func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

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

	versionsForConversion := strings.Split(*versions, ",")
	for _, version := range versionsForConversion {
		generator := conversion.NewGenerator(api.Scheme.Raw())
		// TODO(wojtek-t): Change the overwrites to a flag.
		generator.OverwritePackage(version, "")
		generator.OverwritePackage("api", "newer")
		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(out); err != nil {
			glog.Fatalf("Error while writing conversion functions: %v", err)
		}
	}
}
Example #2
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
	}
	var nameOut io.Writer
	if *namesDest == "-" {
		nameOut = os.Stdout
	} else {
		file, err := os.Create(*namesDest)
		if err != nil {
			glog.Fatalf("Couldn't open %v: %v", *functionDest, err)
		}
		defer file.Close()
		nameOut = file
	}

	generator := conversion.NewGenerator(kapi.Scheme.Raw())
	// TODO(wojtek-t): Change the overwrites to a flag.
	generator.OverwritePackage(*version, "")
	generator.OverwritePackage("api", "newer")
	for _, knownType := range kapi.Scheme.KnownTypes(*version) {
		if strings.Contains(knownType.PkgPath(), "GoogleCloudPlatform/kubernetes") {
			continue
		}
		if err := generator.GenerateConversionsForType(*version, knownType); err != nil {
			util.HandleError(fmt.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.WriteConversionFunctionNames(nameOut); err != nil {
		glog.Fatalf("Error while writing conversion functions: %v", err)
	}
}