mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Move go-header-file flag to each tool
Also remove the build-tag flag (unused, untested). This changes some output comments (less redundant).
This commit is contained in:
parent
3a77592b2c
commit
6420e64662
2
pkg/generated/openapi/zz_generated.openapi.go
generated
2
pkg/generated/openapi/zz_generated.openapi.go
generated
@ -19,8 +19,6 @@ limitations under the License.
|
||||
|
||||
// Code generated by openapi-gen. DO NOT EDIT.
|
||||
|
||||
// This file was autogenerated by openapi-gen. Do not edit it manually!
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
|
@ -19,8 +19,6 @@ limitations under the License.
|
||||
|
||||
// Code generated by openapi-gen. DO NOT EDIT.
|
||||
|
||||
// This file was autogenerated by openapi-gen. Do not edit it manually!
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
|
@ -29,6 +29,8 @@ type CustomArgs struct {
|
||||
OutputDir string // must be a directory path
|
||||
OutputPkg string // must be a Go import-path
|
||||
|
||||
GoHeaderFile string
|
||||
|
||||
// ExternalApplyConfigurations provides the locations of externally generated
|
||||
// apply configuration types for types referenced by the go structs provided as input.
|
||||
// Locations are provided as a comma separated list of <package>.<typeName>:<applyconfiguration-package>
|
||||
@ -70,6 +72,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet, inputBase string) {
|
||||
"the base directory under which to generate results")
|
||||
fs.StringVar(&ca.OutputPkg, "output-pkg", ca.OutputPkg,
|
||||
"the Go import-path of the generated results")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
fs.Var(NewExternalApplyConfigurationValue(&ca.ExternalApplyConfigurations, nil), "external-applyconfigurations",
|
||||
"list of comma separated external apply configurations locations in <type-package>.<type-name>:<applyconfiguration-package> form."+
|
||||
"For example: k8s.io/api/apps/v1.Deployment:k8s.io/client-go/applyconfigurations/apps/v1")
|
||||
|
@ -56,13 +56,13 @@ func DefaultNameSystem() string {
|
||||
|
||||
// GetTargets makes the client target definition.
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*applygenargs.CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, "", args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*applygenargs.CustomArgs)
|
||||
|
||||
pkgTypes := packageTypesForInputDirs(context, arguments.InputDirs, customArgs.OutputPkg)
|
||||
initialTypes := customArgs.ExternalApplyConfigurations
|
||||
refs := refGraphForReachableTypes(context.Universe, pkgTypes, initialTypes)
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/applyconfiguration-gen/args"
|
||||
"k8s.io/code-generator/cmd/applyconfiguration-gen/generators"
|
||||
"k8s.io/gengo/v2/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -47,6 +48,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ type CustomArgs struct {
|
||||
// The Go import-path of the generated results.
|
||||
OutputPkg string
|
||||
|
||||
// The boilerplate header for Go files.
|
||||
GoHeaderFile string
|
||||
|
||||
// A sorted list of group versions to generate. For each of them the package path is found
|
||||
// in GroupVersionToInputPath.
|
||||
Groups []types.GroupVersions
|
||||
@ -85,6 +88,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet, inputBase string) {
|
||||
"the base directory under which to generate results")
|
||||
fs.StringVar(&ca.OutputPkg, "output-pkg", ca.OutputPkg,
|
||||
"the Go import-path of the generated results")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
fs.Var(NewGVPackagesValue(gvsBuilder, nil), "input", "group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format \"group1/version1,group2/version2...\".")
|
||||
fs.Var(NewGVTypesValue(&ca.IncludedTypesOverrides, []string{}), "included-types-overrides", "list of group/version/type for which client should be generated. By default, client is generated for all types which have genclient in types.go. This overrides that. For each groupVersion in this list, only the types mentioned here will be included. The default check of genclient will be used for other group versions.")
|
||||
fs.Var(NewInputBasePathValue(gvsBuilder, inputBase), "input-base", "base path to look for the api group.")
|
||||
|
@ -341,13 +341,13 @@ func sanitizePackagePaths(context *generator.Context, ca *clientgenargs.CustomAr
|
||||
|
||||
// GetTargets makes the client target definition.
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*clientgenargs.CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, "", args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*clientgenargs.CustomArgs)
|
||||
|
||||
includedTypesOverrides := customArgs.IncludedTypesOverrides
|
||||
|
||||
if err := sanitizePackagePaths(context, customArgs); err != nil {
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
generatorargs "k8s.io/code-generator/cmd/client-gen/args"
|
||||
"k8s.io/code-generator/cmd/client-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/v2/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -53,6 +54,7 @@ func main() {
|
||||
generators.NameSystems(util.PluralExceptionListToMapOrDie(customArgs.PluralExceptions)),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -55,6 +55,10 @@ type CustomArgs struct {
|
||||
// (within the allowed uses of unsafe) and is equivalent to a proposed Golang change to
|
||||
// allow structs that are identical to be assigned to each other.
|
||||
SkipUnsafe bool
|
||||
|
||||
// GoHeaderFile is the path to a boilerplate header file for generated
|
||||
// code.
|
||||
GoHeaderFile string
|
||||
}
|
||||
|
||||
// NewDefaults returns default arguments for the generator.
|
||||
@ -80,6 +84,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
"Application specific comma-separated list of import paths which are loaded and considered for callable conversions, but are not considered peers for conversion.")
|
||||
fs.BoolVar(&ca.SkipUnsafe, "skip-unsafe", ca.SkipUnsafe,
|
||||
"If true, will not generate code using unsafe pointer conversions; resulting code may be slower.")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -198,13 +198,14 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
||||
}
|
||||
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*conversionargs.CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, args.StdBuildTag, args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
targets := []generator.Target{}
|
||||
header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...)
|
||||
|
||||
// Accumulate pre-existing conversion functions.
|
||||
// TODO: This is too ad-hoc. We need a better way.
|
||||
@ -271,8 +272,6 @@ func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []gen
|
||||
}
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*conversionargs.CustomArgs)
|
||||
|
||||
// Make sure explicit peer-packages are added.
|
||||
peers := append(customArgs.BasePeerDirs, customArgs.ExtraPeerDirs...)
|
||||
if expanded, err := context.FindPackages(peers...); err != nil {
|
||||
@ -330,7 +329,7 @@ func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []gen
|
||||
PkgName: filepath.Base(pkg.Path),
|
||||
PkgPath: pkg.Path,
|
||||
PkgDir: pkg.SourcePath, // output pkg is the same as the input
|
||||
HeaderComment: header,
|
||||
HeaderComment: boilerplate,
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return t.Name.Package == typesPkg.Path
|
||||
},
|
||||
|
@ -102,6 +102,7 @@ import (
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
||||
"k8s.io/code-generator/cmd/conversion-gen/generators"
|
||||
"k8s.io/gengo/v2/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -132,6 +133,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
"the name of the file to be generated")
|
||||
fs.StringSliceVar(&ca.BoundingDirs, "bounding-dirs", ca.BoundingDirs,
|
||||
"Comma-separated list of import paths which bound the types for which deep-copies will be generated.")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -49,10 +49,10 @@ import (
|
||||
"flag"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
generatorargs "k8s.io/code-generator/cmd/deepcopy-gen/args"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/gengo/v2/examples/deepcopy-gen/generators"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/deepcopy-gen/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -74,6 +74,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
"the name of the file to be generated")
|
||||
fs.StringSliceVar(&ca.ExtraPeerDirs, "extra-peer-dirs", ca.ExtraPeerDirs,
|
||||
"Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -45,10 +45,10 @@ import (
|
||||
"flag"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
generatorargs "k8s.io/code-generator/cmd/defaulter-gen/args"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/gengo/v2/examples/defaulter-gen/generators"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/defaulter-gen/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -70,6 +70,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import (
|
||||
)
|
||||
|
||||
type Generator struct {
|
||||
Common args.GeneratorArgs
|
||||
GoHeaderFile string
|
||||
APIMachineryPackages string
|
||||
Packages string
|
||||
OutputDir string
|
||||
@ -69,7 +69,7 @@ func New() *Generator {
|
||||
}
|
||||
|
||||
func (g *Generator) BindFlags(flag *flag.FlagSet) {
|
||||
flag.StringVarP(&g.Common.GoHeaderFilePath, "go-header-file", "h", g.Common.GoHeaderFilePath, "File containing boilerplate header text. The string YEAR will be replaced with the current 4-digit year.")
|
||||
flag.StringVarP(&g.GoHeaderFile, "go-header-file", "h", "", "File containing boilerplate header text. The string YEAR will be replaced with the current 4-digit year.")
|
||||
flag.StringVarP(&g.Packages, "packages", "p", g.Packages, "comma-separated list of directories to get input types from. Directories prefixed with '-' are not generated, directories prefixed with '+' only create types with explicit IDL instructions.")
|
||||
flag.StringVar(&g.APIMachineryPackages, "apimachinery-packages", g.APIMachineryPackages, "comma-separated list of directories to get apimachinery input types from which are needed by any API. Directories prefixed with '-' are not generated, directories prefixed with '+' only create types with explicit IDL instructions.")
|
||||
flag.StringVar(&g.OutputDir, "output-dir", g.OutputDir, "The base directory under which to generate results.")
|
||||
@ -153,7 +153,7 @@ func Run(g *Generator) {
|
||||
// Roughly models gengo/v2/args.GeneratorArgs.Execute calling the
|
||||
// tool-provided Packages() callback.
|
||||
|
||||
boilerplate, err := g.Common.LoadGoBoilerplate()
|
||||
boilerplate, err := args.GoBoilerplate(g.GoHeaderFile, "", "")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed loading boilerplate (consider using the go-header-file flag): %v", err)
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func newProtobufPackage(packagePath, packageDir, packageName string, generateAll
|
||||
PkgName: packageName,
|
||||
PkgPath: packagePath,
|
||||
PkgDir: packageDir,
|
||||
HeaderComment: []byte("\n// This file was autogenerated by go-to-protobuf. Do not edit it manually!\n\n"),
|
||||
HeaderComment: []byte("// This file was autogenerated by go-to-protobuf. Do not edit it manually!\n\n"),
|
||||
PkgDocComment: []byte(fmt.Sprintf("// Package %s is an autogenerated protobuf IDL.\n", packageName)),
|
||||
},
|
||||
GenerateAll: generateAll,
|
||||
|
@ -37,6 +37,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
"",
|
||||
); err != nil {
|
||||
klog.Errorf("Error: %v", err)
|
||||
os.Exit(1)
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
type CustomArgs struct {
|
||||
OutputDir string // must be a directory path
|
||||
OutputPkg string // must be a Go import-path
|
||||
GoHeaderFile string
|
||||
VersionedClientSetPackage string // must be a Go import-path
|
||||
InternalClientSetPackage string // must be a Go import-path
|
||||
ListersPackage string // must be a Go import-path
|
||||
@ -55,6 +56,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
"the base directory under which to generate results")
|
||||
fs.StringVar(&ca.OutputPkg, "output-pkg", ca.OutputPkg,
|
||||
"the Go import-path of the generated results")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
fs.StringVar(&ca.InternalClientSetPackage, "internal-clientset-package", ca.InternalClientSetPackage, "the Go import-path of the internal clientset to use")
|
||||
fs.StringVar(&ca.VersionedClientSetPackage, "versioned-clientset-package", ca.VersionedClientSetPackage, "the Go import-path of the versioned clientset to use")
|
||||
fs.StringVar(&ca.ListersPackage, "listers-package", ca.ListersPackage, "the Go import-path of the listers to use")
|
||||
|
@ -94,13 +94,13 @@ func subdirForInternalInterfaces(base string) string {
|
||||
|
||||
// GetTargets makes the client target definition.
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*informergenargs.CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, "", args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*informergenargs.CustomArgs)
|
||||
|
||||
internalVersionOutputDir := customArgs.OutputDir
|
||||
internalVersionOutputPkg := customArgs.OutputPkg
|
||||
externalVersionOutputDir := customArgs.OutputDir
|
||||
|
@ -20,11 +20,11 @@ import (
|
||||
"flag"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
generatorargs "k8s.io/code-generator/cmd/informer-gen/args"
|
||||
"k8s.io/code-generator/cmd/informer-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/informer-gen/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -46,6 +46,7 @@ func main() {
|
||||
generators.NameSystems(util.PluralExceptionListToMapOrDie(customArgs.PluralExceptions)),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -25,8 +25,9 @@ import (
|
||||
|
||||
// CustomArgs is used by the gengo framework to pass args specific to this generator.
|
||||
type CustomArgs struct {
|
||||
OutputDir string // must be a directory path
|
||||
OutputPkg string // must be a Go import-path
|
||||
OutputDir string // must be a directory path
|
||||
OutputPkg string // must be a Go import-path
|
||||
GoHeaderFile string
|
||||
|
||||
// PluralExceptions specify list of exceptions used when pluralizing certain types.
|
||||
// For example 'Endpoints:Endpoints', otherwise the pluralizer will generate 'Endpointes'.
|
||||
@ -52,6 +53,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
"the base Go import-path under which to generate results")
|
||||
fs.StringSliceVar(&ca.PluralExceptions, "plural-exceptions", ca.PluralExceptions,
|
||||
"list of comma separated plural exception definitions in Type:PluralizedType format")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -60,13 +60,13 @@ func DefaultNameSystem() string {
|
||||
|
||||
// GetTargets makes the client target definition.
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*listergenargs.CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, "", args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*listergenargs.CustomArgs)
|
||||
|
||||
var targetList []generator.Target
|
||||
for _, inputDir := range arguments.InputDirs {
|
||||
p := context.Universe.Package(inputDir)
|
||||
|
@ -20,11 +20,11 @@ import (
|
||||
"flag"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
generatorargs "k8s.io/code-generator/cmd/lister-gen/args"
|
||||
"k8s.io/code-generator/cmd/lister-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/lister-gen/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -46,6 +46,7 @@ func main() {
|
||||
generators.NameSystems(util.PluralExceptionListToMapOrDie(customArgs.PluralExceptions)),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -24,12 +24,11 @@ import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/klog/v2"
|
||||
generatorargs "k8s.io/kube-openapi/cmd/openapi-gen/args"
|
||||
"k8s.io/kube-openapi/pkg/generators"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -51,6 +50,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
log.Fatalf("OpenAPI code generation error: %v", err)
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ func NewDefaults() (*args.GeneratorArgs, *CustomArgs) {
|
||||
func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&ca.OutputFile, "output-file", "generated.prerelease_lifecycle.go",
|
||||
"the name of the file to be generated")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -40,6 +40,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
generatorargs "k8s.io/code-generator/cmd/prerelease-lifecycle-gen/args"
|
||||
statusgenerators "k8s.io/code-generator/cmd/prerelease-lifecycle-gen/prerelease-lifecycle-generators"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@ -62,6 +63,7 @@ func main() {
|
||||
statusgenerators.NameSystems(),
|
||||
statusgenerators.DefaultNameSystem(),
|
||||
statusgenerators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ import (
|
||||
|
||||
// CustomArgs is used tby the go2idl framework to pass args specific to this generator.
|
||||
type CustomArgs struct {
|
||||
OutputFile string
|
||||
OutputFile string
|
||||
GoHeaderFile string
|
||||
}
|
||||
|
||||
// This is the comment tag that carries parameters for API status generation. Because the cadence is fixed, we can predict
|
||||
@ -182,13 +183,14 @@ func DefaultNameSystem() string {
|
||||
|
||||
// GetTargets makes the target definition.
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, args.StdBuildTag, args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
targets := []generator.Target{}
|
||||
header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...)
|
||||
|
||||
for _, i := range context.Inputs {
|
||||
klog.V(5).Infof("Considering pkg %q", i)
|
||||
@ -230,15 +232,13 @@ func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []gen
|
||||
}
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*CustomArgs)
|
||||
|
||||
if pkgNeedsGeneration {
|
||||
targets = append(targets,
|
||||
&generator.SimpleTarget{
|
||||
PkgName: strings.Split(filepath.Base(pkg.Path), ".")[0],
|
||||
PkgPath: pkg.Path,
|
||||
PkgDir: pkg.SourcePath, // output pkg is the same as the input
|
||||
HeaderComment: header,
|
||||
HeaderComment: boilerplate,
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return t.Name.Package == pkg.Path
|
||||
},
|
||||
|
@ -24,7 +24,8 @@ import (
|
||||
)
|
||||
|
||||
type CustomArgs struct {
|
||||
OutputFile string
|
||||
OutputFile string
|
||||
GoHeaderFile string
|
||||
}
|
||||
|
||||
// NewDefaults returns default arguments for the generator.
|
||||
@ -38,6 +39,8 @@ func NewDefaults() *args.GeneratorArgs {
|
||||
func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&ca.OutputFile, "output-file", "generated.register.go",
|
||||
"the name of the file to be generated")
|
||||
fs.StringVar(&ca.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -45,13 +45,13 @@ func DefaultNameSystem() string {
|
||||
|
||||
// GetTargets makes targets to generate.
|
||||
func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []generator.Target {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
customArgs := arguments.CustomArgs.(*registerargs.CustomArgs)
|
||||
|
||||
boilerplate, err := args.GoBoilerplate(customArgs.GoHeaderFile, args.StdBuildTag, args.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs := arguments.CustomArgs.(*registerargs.CustomArgs)
|
||||
|
||||
targets := []generator.Target{}
|
||||
for _, input := range context.Inputs {
|
||||
pkg := context.Universe.Package(input)
|
||||
|
@ -20,10 +20,10 @@ import (
|
||||
"flag"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/register-gen/args"
|
||||
"k8s.io/code-generator/cmd/register-gen/generators"
|
||||
"k8s.io/gengo/v2/args"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -42,6 +42,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.GetTargets,
|
||||
args.StdBuildTag,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ limitations under the License.
|
||||
|
||||
// Code generated by openapi-gen. DO NOT EDIT.
|
||||
|
||||
// This file was autogenerated by openapi-gen. Do not edit it manually!
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
|
@ -19,8 +19,6 @@ limitations under the License.
|
||||
|
||||
// Code generated by openapi-gen. DO NOT EDIT.
|
||||
|
||||
// This file was autogenerated by openapi-gen. Do not edit it manually!
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
|
@ -19,8 +19,6 @@ limitations under the License.
|
||||
|
||||
// Code generated by openapi-gen. DO NOT EDIT.
|
||||
|
||||
// This file was autogenerated by openapi-gen. Do not edit it manually!
|
||||
|
||||
package openapi
|
||||
|
||||
import (
|
||||
|
Loading…
Reference in New Issue
Block a user