mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #32769 from mfojtik/customize-api-path-clientgen
Automatic merge from submit-queue clientgen: allow to pass custom apiPath when generating client sets This PR allow to pass the `--clientset-api-path` parameter to clientgen that allows to customize the default API path set in clients. This allows projects like OpenShift to re-use the client with different API path (`/oapi` in our case).
This commit is contained in:
commit
c4f509e65d
@ -39,6 +39,8 @@ type Args struct {
|
|||||||
// ClientsetOutputPath is the path the clientset will be generated at. It's
|
// ClientsetOutputPath is the path the clientset will be generated at. It's
|
||||||
// populated from command-line arguments.
|
// populated from command-line arguments.
|
||||||
ClientsetOutputPath string
|
ClientsetOutputPath string
|
||||||
|
// ClientsetAPIPath is the default API path for generated clients.
|
||||||
|
ClientsetAPIPath string
|
||||||
// ClientsetOnly determines if we should generate the clients for groups and
|
// ClientsetOnly determines if we should generate the clients for groups and
|
||||||
// types along with the clientset. It's populated from command-line
|
// types along with the clientset. It's populated from command-line
|
||||||
// arguments.
|
// 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")
|
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)
|
outputPackagePath := filepath.Join(packageBasePath, gv.Group, gv.Version)
|
||||||
return &generator.DefaultPackage{
|
return &generator.DefaultPackage{
|
||||||
PackageName: gv.Version,
|
PackageName: gv.Version,
|
||||||
@ -102,6 +102,7 @@ func packageForGroup(gv unversioned.GroupVersion, typeList []*types.Type, packag
|
|||||||
inputPacakge: inputPath,
|
inputPacakge: inputPath,
|
||||||
group: gv.Group,
|
group: gv.Group,
|
||||||
version: gv.Version,
|
version: gv.Version,
|
||||||
|
apiPath: apiPath,
|
||||||
types: typeList,
|
types: typeList,
|
||||||
imports: generator.NewImportTracker(),
|
imports: generator.NewImportTracker(),
|
||||||
})
|
})
|
||||||
@ -217,7 +218,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
for _, gv := range customArgs.GroupVersions {
|
for _, gv := range customArgs.GroupVersions {
|
||||||
types := gvToTypes[gv]
|
types := gvToTypes[gv]
|
||||||
inputPath := customArgs.GroupVersionToInputPath[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 {
|
if customArgs.FakeClient {
|
||||||
packageList = append(packageList, fake.PackageForGroup(normalization.GroupVersion(gv), orderer.OrderTypes(types), typedClientBasePath, arguments.OutputBase, inputPath, boilerplate, generatedBy))
|
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
|
outputPackage string
|
||||||
group string
|
group string
|
||||||
version string
|
version string
|
||||||
|
apiPath string
|
||||||
// types in this group
|
// types in this group
|
||||||
types []*types.Type
|
types []*types.Type
|
||||||
imports namer.ImportTracker
|
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 pkgAPI = "k8s.io/kubernetes/pkg/api"
|
||||||
const pkgSerializer = "k8s.io/kubernetes/pkg/runtime/serializer"
|
const pkgSerializer = "k8s.io/kubernetes/pkg/runtime/serializer"
|
||||||
apiPath := func(group string) string {
|
apiPath := func(group string) string {
|
||||||
|
if len(g.apiPath) > 0 {
|
||||||
|
return `"` + g.apiPath + `"`
|
||||||
|
}
|
||||||
if group == "core" {
|
if group == "core" {
|
||||||
return `"/api"`
|
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.")
|
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\"")
|
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.")
|
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/\"")
|
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")
|
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")
|
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 {
|
if err != nil {
|
||||||
glog.Fatalf("Unexpected error: %v", err)
|
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.InputDirs = append(inputPath, dependencies...)
|
||||||
|
|
||||||
arguments.CustomArgs = clientgenargs.Args{
|
arguments.CustomArgs = clientgenargs.Args{
|
||||||
GroupVersions: groupVersions,
|
GroupVersions: groupVersions,
|
||||||
GroupVersionToInputPath: gvToPath,
|
GroupVersionToInputPath: gvToPath,
|
||||||
ClientsetName: *clientsetName,
|
ClientsetName: *clientsetName,
|
||||||
|
ClientsetAPIPath: *clientsetAPIPath,
|
||||||
ClientsetOutputPath: *clientsetPath,
|
ClientsetOutputPath: *clientsetPath,
|
||||||
ClientsetOnly: *clientsetOnly,
|
ClientsetOnly: *clientsetOnly,
|
||||||
FakeClient: *fakeClient,
|
FakeClient: *fakeClient,
|
||||||
@ -191,7 +193,7 @@ func main() {
|
|||||||
IncludedTypesOverrides: includedTypesOverrides,
|
IncludedTypesOverrides: includedTypesOverrides,
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("==arguments: %v\n", arguments)
|
glog.V(3).Infof("==arguments: %v\n", arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := arguments.Execute(
|
if err := arguments.Execute(
|
||||||
|
@ -65,6 +65,7 @@ cleanup-iptables
|
|||||||
client-ca-file
|
client-ca-file
|
||||||
client-certificate
|
client-certificate
|
||||||
client-key
|
client-key
|
||||||
|
clientset-api-path
|
||||||
clientset-name
|
clientset-name
|
||||||
clientset-only
|
clientset-only
|
||||||
clientset-path
|
clientset-path
|
||||||
|
Loading…
Reference in New Issue
Block a user