Skip to content

Commit

Permalink
Merge pull request #53202 from sttts/sttts-unify-generator-mains
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 53434, 53202). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generator: unify generator main funcs and prepare for launching from one binary

- remove "generated by client-gen with custom arguments" message as this does not
  make sense in the times of k8s.io/code-generator
- unify generator main funcs and explicitly call pflag.AddFlags and pflag.Parse. This
  will allow to instantiate the generators also from other places.

Requires kubernetes/gengo#80.

Closes kubernetes/kubernetes#53522.

Kubernetes-commit: 6ac018af01bd27054452cf04adaa05cf61f1e82a
  • Loading branch information
k8s-publish-robot committed Oct 7, 2017
2 parents e762e3c + d184fbd commit f662bbb
Show file tree
Hide file tree
Showing 36 changed files with 568 additions and 298 deletions.
20 changes: 10 additions & 10 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions _examples/apiserver/clientset/internalversion/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated clientset.
package internalversion
2 changes: 0 additions & 2 deletions _examples/apiserver/clientset/internalversion/fake/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated fake clientset.
package fake
2 changes: 0 additions & 2 deletions _examples/apiserver/clientset/internalversion/scheme/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package contains the scheme of the automatically generated clientset.
package scheme
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated typed clients.
package internalversion
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// Package fake has the automatically generated clients.
package fake
2 changes: 0 additions & 2 deletions _examples/apiserver/clientset/versioned/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated clientset.
package versioned
2 changes: 0 additions & 2 deletions _examples/apiserver/clientset/versioned/fake/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated fake clientset.
package fake
2 changes: 0 additions & 2 deletions _examples/apiserver/clientset/versioned/scheme/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package contains the scheme of the automatically generated clientset.
package scheme
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated typed clients.
package v1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// Package fake has the automatically generated clients.
package fake
2 changes: 0 additions & 2 deletions _examples/crd/clientset/versioned/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated clientset.
package versioned
2 changes: 0 additions & 2 deletions _examples/crd/clientset/versioned/fake/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated fake clientset.
package fake
2 changes: 0 additions & 2 deletions _examples/crd/clientset/versioned/scheme/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package contains the scheme of the automatically generated clientset.
package scheme
2 changes: 0 additions & 2 deletions _examples/crd/clientset/versioned/typed/example/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated typed clients.
package v1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This package is generated by client-gen with custom arguments.

// Package fake has the automatically generated clients.
package fake
1 change: 0 additions & 1 deletion cmd/client-gen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ go_library(
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/code-generator/cmd/client-gen/args:go_default_library",
"//vendor/k8s.io/code-generator/cmd/client-gen/generators:go_default_library",
"//vendor/k8s.io/code-generator/cmd/client-gen/types:go_default_library",
"//vendor/k8s.io/gengo/args:go_default_library",
],
)
Expand Down
22 changes: 20 additions & 2 deletions cmd/client-gen/args/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)

go_library(
name = "go_default_library",
srcs = ["args.go"],
deps = ["//vendor/k8s.io/code-generator/cmd/client-gen/types:go_default_library"],
srcs = [
"args.go",
"gvpackages.go",
"gvtype.go",
],
deps = [
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/code-generator/cmd/client-gen/types:go_default_library",
],
)

filegroup(
Expand All @@ -23,3 +31,13 @@ filegroup(
srcs = [":package-srcs"],
tags = ["automanaged"],
)

go_test(
name = "go_default_test",
srcs = ["gvpackages_test.go"],
library = ":go_default_library",
deps = [
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/code-generator/cmd/client-gen/types:go_default_library",
],
)
50 changes: 42 additions & 8 deletions cmd/client-gen/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ limitations under the License.

package args

import "k8s.io/code-generator/cmd/client-gen/types"
import (
"github.com/spf13/pflag"

"k8s.io/code-generator/cmd/client-gen/types"
)

// ClientGenArgs is a wrapper for arguments to client-gen.
type Args struct {
type CustomArgs struct {
// A sorted list of group versions to generate. For each of them the package path is found
// in GroupVersionToInputPath.
Groups []types.GroupVersions

// GroupVersionToInputPath is a map between GroupVersion and the path to
// the respective types.go. We still need GroupVersions in the struct because
// we need an order.
// GroupVersionToInputPath is a map between GroupVersion and the path to the respective
// types.go, relative to InputBasePath. We still need GroupVersions in the
// struct because we need an order.
GroupVersionToInputPath map[types.GroupVersion]string
// The base for the path of GroupVersionToInputPath.
InputBasePath string

// Overrides for which types should be included in the client.
IncludedTypesOverrides map[types.GroupVersion][]string
Expand All @@ -44,6 +51,33 @@ type Args struct {
ClientsetOnly bool
// FakeClient determines if client-gen generates the fake clients.
FakeClient bool
// CmdArgs is the command line arguments supplied when the client-gen is called.
CmdArgs string
}

var defaultInput = []string{
"api/",
"admissionregistration/",
"authentication/",
"authorization/",
"autoscaling/",
"batch/",
"certificates/",
"extensions/",
"rbac/",
"storage/",
"apps/",
"policy/",
"scheduling/",
"settings/",
"networking/",
}

func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
pflag.Var(NewGVPackagesValue(&ca.GroupVersionToInputPath, &ca.Groups, defaultInput), "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...\".")
pflag.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.")
pflag.StringVar(&ca.InputBasePath, "input-base", "k8s.io/kubernetes/pkg/apis", "base path to look for the api group.")
pflag.StringVarP(&ca.ClientsetName, "clientset-name", "n", "internalclientset", "the name of the generated clientset package.")
pflag.StringVarP(&ca.ClientsetAPIPath, "clientset-api-path", "", "", "the value of default API path.")
pflag.StringVar(&ca.ClientsetOutputPath, "clientset-path", "k8s.io/kubernetes/pkg/client/clientset_generated/", "the generated clientset will be output to <clientset-path>/<clientset-name>.")
pflag.BoolVar(&ca.ClientsetOnly, "clientset-only", false, "when set, client-gen only generates the clientset shell, without generating the individual typed clients")
pflag.BoolVar(&ca.FakeClient, "fake-clientset", true, "when set, client-gen will generate the fake clientset that can be used in tests")
}
Loading

0 comments on commit f662bbb

Please sign in to comment.