Beispiel #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	var funcOut io.Writer
	if *functionDest == "-" {
		funcOut = os.Stdout
	} else {
		file, err := os.Create(*functionDest)
		if err != nil {
			glog.Fatalf("Couldn't open %v: %v", *functionDest, err)
		}
		defer file.Close()
		funcOut = file
	}

	generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw())
	// TODO(wojtek-t): Change the overwrites to a flag.
	generator.OverwritePackage(*version, "")
	for _, knownType := range api.Scheme.KnownTypes(*version) {
		if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
			glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
		}
	}
	if err := generator.WriteConversionFunctions(funcOut); err != nil {
		glog.Fatalf("Error while writing conversion functions: %v", err)
	}
	if err := generator.RegisterConversionFunctions(funcOut); err != nil {
		glog.Fatalf("Error while writing conversion functions: %v", err)
	}
}
func generateConversions(t *testing.T, version string) bytes.Buffer {
	g := runtime.NewConversionGenerator(api.Scheme.Raw())
	g.OverwritePackage(version, "")
	for _, knownType := range api.Scheme.KnownTypes(version) {
		if err := g.GenerateConversionsForType(version, knownType); err != nil {
			glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
		}
	}

	var functions bytes.Buffer
	functionsWriter := bufio.NewWriter(&functions)
	if err := g.WriteConversionFunctions(functionsWriter); err != nil {
		t.Fatalf("couldn't generate conversion functions: %v", err)
	}
	if err := functionsWriter.Flush(); err != nil {
		t.Fatalf("error while flushing writer")
	}
	if err := g.RegisterConversionFunctions(functionsWriter); err != nil {
		t.Fatalf("couldn't generate conversion function names: %v", err)
	}
	if err := functionsWriter.Flush(); err != nil {
		t.Fatalf("error while flushing writer")
	}

	return functions
}
func generateConversions(t *testing.T, version string) bytes.Buffer {
	g := runtime.NewConversionGenerator(api.Scheme.Raw(), path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", version))
	apiShort := g.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api")
	g.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource")
	// TODO(wojtek-t): Change the overwrites to a flag.
	g.OverwritePackage(version, "")
	for _, knownType := range api.Scheme.KnownTypes(version) {
		if err := g.GenerateConversionsForType(version, knownType); err != nil {
			t.Fatalf("error while generating conversion functions for %v: %v", knownType, err)
		}
	}
	g.RepackImports(util.NewStringSet())
	var functions bytes.Buffer
	functionsWriter := bufio.NewWriter(&functions)
	if err := g.WriteImports(functionsWriter); err != nil {
		t.Fatalf("error while writing imports: %v", err)
	}
	if err := g.WriteConversionFunctions(functionsWriter); err != nil {
		t.Fatalf("couldn't generate conversion functions: %v", err)
	}
	if err := g.RegisterConversionFunctions(functionsWriter, fmt.Sprintf("%s.Scheme", apiShort)); err != nil {
		t.Fatalf("couldn't generate conversion function names: %v", err)
	}
	if err := functionsWriter.Flush(); err != nil {
		t.Fatalf("error while flushing writer")
	}

	return functions
}
Beispiel #4
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	var funcOut io.Writer
	if *functionDest == "-" {
		funcOut = os.Stdout
	} else {
		file, err := os.Create(*functionDest)
		if err != nil {
			glog.Fatalf("Couldn't open %v: %v", *functionDest, err)
		}
		defer file.Close()
		funcOut = file
	}

	generator := pkg_runtime.NewConversionGenerator(api.Scheme.Raw(), "github.com/openshift/origin/pkg/api")
	apiShort := generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api")
	generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource")
	generator.AssumePrivateConversions()
	// TODO(wojtek-t): Change the overwrites to a flag.
	generator.OverwritePackage(*version, "")
	for _, knownType := range api.Scheme.KnownTypes(*version) {
		if !strings.Contains(knownType.PkgPath(), "openshift/origin") {
			continue
		}
		if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
			glog.Errorf("error while generating conversion functions for %v: %v", knownType, err)
		}
	}
	generator.RepackImports(util.NewStringSet("github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"))
	if err := generator.WriteImports(funcOut); err != nil {
		glog.Fatalf("error while writing imports: %v", err)
	}
	if err := generator.WriteConversionFunctions(funcOut); err != nil {
		glog.Fatalf("Error while writing conversion functions: %v", err)
	}
	if err := generator.RegisterConversionFunctions(funcOut, fmt.Sprintf("%s.Scheme", apiShort)); err != nil {
		glog.Fatalf("Error while writing conversion functions: %v", err)
	}
}