mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
clientgen: allow to pass custom apiPath when generating client sets
This commit is contained in:
parent
3c3f74922d
commit
aea9b486a0
@ -39,6 +39,8 @@ type Args struct {
|
||||
// ClientsetOutputPath is the path the clientset will be generated at. It's
|
||||
// populated from command-line arguments.
|
||||
ClientsetOutputPath string
|
||||
// ClientsetAPIPath is the default API path for generated clients.
|
||||
ClientsetAPIPath string
|
||||
// ClientsetOnly determines if we should generate the clients for groups and
|
||||
// types along with the clientset. It's populated from command-line
|
||||
// arguments.
|
||||
|
@ -62,7 +62,7 @@ func generatedBy(customArgs clientgenargs.Args) string {
|
||||
return fmt.Sprintf("\n// This package is generated by client-gen with the default arguments.\n\n")
|
||||
}
|
||||
|
||||
func packageForGroup(gv unversioned.GroupVersion, typeList []*types.Type, packageBasePath string, srcTreePath string, inputPath string, boilerplate []byte, generatedBy string) generator.Package {
|
||||
func packageForGroup(gv unversioned.GroupVersion, typeList []*types.Type, packageBasePath string, apiPath string, srcTreePath string, inputPath string, boilerplate []byte, generatedBy string) generator.Package {
|
||||
outputPackagePath := filepath.Join(packageBasePath, gv.Group, gv.Version)
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: gv.Version,
|
||||
@ -102,6 +102,7 @@ func packageForGroup(gv unversioned.GroupVersion, typeList []*types.Type, packag
|
||||
inputPacakge: inputPath,
|
||||
group: gv.Group,
|
||||
version: gv.Version,
|
||||
apiPath: apiPath,
|
||||
types: typeList,
|
||||
imports: generator.NewImportTracker(),
|
||||
})
|
||||
@ -217,7 +218,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
||||
for _, gv := range customArgs.GroupVersions {
|
||||
types := gvToTypes[gv]
|
||||
inputPath := customArgs.GroupVersionToInputPath[gv]
|
||||
packageList = append(packageList, packageForGroup(normalization.GroupVersion(gv), orderer.OrderTypes(types), typedClientBasePath, arguments.OutputBase, inputPath, boilerplate, generatedBy))
|
||||
packageList = append(packageList, packageForGroup(normalization.GroupVersion(gv), orderer.OrderTypes(types), typedClientBasePath, customArgs.ClientsetAPIPath, arguments.OutputBase, inputPath, boilerplate, generatedBy))
|
||||
if customArgs.FakeClient {
|
||||
packageList = append(packageList, fake.PackageForGroup(normalization.GroupVersion(gv), orderer.OrderTypes(types), typedClientBasePath, arguments.OutputBase, inputPath, boilerplate, generatedBy))
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ type genGroup struct {
|
||||
outputPackage string
|
||||
group string
|
||||
version string
|
||||
apiPath string
|
||||
// types in this group
|
||||
types []*types.Type
|
||||
imports namer.ImportTracker
|
||||
@ -62,6 +63,9 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
|
||||
const pkgAPI = "k8s.io/kubernetes/pkg/api"
|
||||
const pkgSerializer = "k8s.io/kubernetes/pkg/runtime/serializer"
|
||||
apiPath := func(group string) string {
|
||||
if len(g.apiPath) > 0 {
|
||||
return `"` + g.apiPath + `"`
|
||||
}
|
||||
if group == "core" {
|
||||
return `"/api"`
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ var (
|
||||
includedTypesOverrides = flag.StringSlice("included-types-overrides", []string{}, "list of group/version/type for which client should be generated. By default, client is generated for all types which have genclient=true 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=true will be used for other group versions.")
|
||||
basePath = flag.String("input-base", "k8s.io/kubernetes/pkg/apis", "base path to look for the api group. Default to \"k8s.io/kubernetes/pkg/apis\"")
|
||||
clientsetName = flag.StringP("clientset-name", "n", "internalclientset", "the name of the generated clientset package.")
|
||||
clientsetAPIPath = flag.StringP("clientset-api-path", "", "", "the value of default API path.")
|
||||
clientsetPath = flag.String("clientset-path", "k8s.io/kubernetes/pkg/client/clientset_generated/", "the generated clientset will be output to <clientset-path>/<clientset-name>. Default to \"k8s.io/kubernetes/pkg/client/clientset_generated/\"")
|
||||
clientsetOnly = flag.Bool("clientset-only", false, "when set, client-gen only generates the clientset shell, without generating the individual typed clients")
|
||||
fakeClient = flag.Bool("fake-clientset", true, "when set, client-gen will generate the fake clientset that can be used in tests")
|
||||
@ -177,13 +178,14 @@ func main() {
|
||||
if err != nil {
|
||||
glog.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
glog.Infof("going to generate clientset from these input paths: %v", inputPath)
|
||||
glog.V(3).Infof("going to generate clientset from these input paths: %v", inputPath)
|
||||
arguments.InputDirs = append(inputPath, dependencies...)
|
||||
|
||||
arguments.CustomArgs = clientgenargs.Args{
|
||||
GroupVersions: groupVersions,
|
||||
GroupVersionToInputPath: gvToPath,
|
||||
ClientsetName: *clientsetName,
|
||||
ClientsetAPIPath: *clientsetAPIPath,
|
||||
ClientsetOutputPath: *clientsetPath,
|
||||
ClientsetOnly: *clientsetOnly,
|
||||
FakeClient: *fakeClient,
|
||||
@ -191,7 +193,7 @@ func main() {
|
||||
IncludedTypesOverrides: includedTypesOverrides,
|
||||
}
|
||||
|
||||
glog.Infof("==arguments: %v\n", arguments)
|
||||
glog.V(3).Infof("==arguments: %v\n", arguments)
|
||||
}
|
||||
|
||||
if err := arguments.Execute(
|
||||
|
@ -64,6 +64,7 @@ cleanup-iptables
|
||||
client-ca-file
|
||||
client-certificate
|
||||
client-key
|
||||
clientset-api-path
|
||||
clientset-name
|
||||
clientset-only
|
||||
clientset-path
|
||||
|
Loading…
Reference in New Issue
Block a user