Skip to content

Commit

Permalink
Merge pull request #264 from KevinJoiner/generic-controllers
Browse files Browse the repository at this point in the history
Generic controllers
  • Loading branch information
rmweir authored Mar 7, 2023
2 parents 16ddd2e + fc1fea5 commit 3ca01d2
Show file tree
Hide file tree
Showing 52 changed files with 3,407 additions and 5,324 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/ghodss/yaml v1.0.0
github.com/golang/mock v1.6.0
github.com/moby/locker v1.0.1
github.com/pkg/errors v0.9.1
github.com/rancher/lasso v0.0.0-20221227210133-6ea88ca2fbcc
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -805,6 +806,7 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
Expand Down
36 changes: 0 additions & 36 deletions pkg/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,17 @@ func main() {
v1.PersistentVolumeClaim{},
v1.Pod{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
discoveryv1.GroupName: {
Types: []interface{}{
discoveryv1.EndpointSlice{},
},
OutputControllerPackageName: "discovery",
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
extensionsv1beta1.GroupName: {
Types: []interface{}{
extensionsv1beta1.Ingress{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
rbacv1.GroupName: {
Types: []interface{}{
Expand All @@ -65,77 +56,50 @@ func main() {
rbacv1.ClusterRoleBinding{},
},
OutputControllerPackageName: "rbac",
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
appsv1.GroupName: {
Types: []interface{}{
appsv1.Deployment{},
appsv1.DaemonSet{},
appsv1.StatefulSet{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
storagev1.GroupName: {
OutputControllerPackageName: "storage",
Types: []interface{}{
storagev1.StorageClass{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
apiextv1.GroupName: {
Types: []interface{}{
apiextv1.CustomResourceDefinition{},
},
ClientSetPackage: "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset",
InformersPackage: "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions",
ListersPackage: "k8s.io/apiextensions-apiserver/pkg/client/listers",
},
apiv1.GroupName: {
Types: []interface{}{
apiv1.APIService{},
},
ClientSetPackage: "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset",
InformersPackage: "k8s.io/kube-aggregator/pkg/client/informers/externalversions",
ListersPackage: "k8s.io/kube-aggregator/pkg/client/listers",
},
batchv1.GroupName: {
Types: []interface{}{
batchv1.Job{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
networkingv1.GroupName: {
Types: []interface{}{
networkingv1.NetworkPolicy{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
admissionregistrationv1.GroupName: {
Types: []interface{}{
admissionregistrationv1.ValidatingWebhookConfiguration{},
admissionregistrationv1.MutatingWebhookConfiguration{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
coordinationv1.GroupName: {
Types: []interface{}{
coordinationv1.Lease{},
},
InformersPackage: "k8s.io/client-go/informers",
ClientSetPackage: "k8s.io/client-go/kubernetes",
ListersPackage: "k8s.io/client-go/listers",
},
},
})
Expand Down
4 changes: 0 additions & 4 deletions pkg/controller-gen/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,4 @@ type Group struct {
GenerateInformers bool
// The package name of the API types
PackageName string
// Use existing clientset, informer, listers
ClientSetPackage string
ListersPackage string
InformersPackage string
}
12 changes: 8 additions & 4 deletions pkg/controller-gen/generators/group_version_interface_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ func (f *groupInterfaceGo) Init(c *generator.Context, w io.Writer) error {
"versionUpper": namer.IC(f.gv.Version),
"groupUpper": upperLowercase(f.gv.Group),
}

sw.Do("func (c *version) {{.type}}() {{.type}}Controller {\n", m)
sw.Do("return New{{.type}}Controller(schema.GroupVersionKind{Group:\"{{.group}}\",Version:\"{{.version}}\",Kind:\"{{.type}}\"} , \"{{.pluralLower}}\", {{.namespaced}}, c.controllerFactory)\n", m)
sw.Do("}\n", m)
body := `
func (v *version) {{.type}}() {{.type}}Controller {
return &{{.type}}GenericController {
generic.New{{ if not .namespaced}}NonNamespaced{{end}}Controller[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List](schema.GroupVersionKind{Group: "{{.group}}", Version: "{{.version}}", Kind: "{{.type}}"}, "{{.pluralLower}}", {{ if .namespaced}}true, {{end}}v.controllerFactory),
}
}
`
sw.Do(body, m)
}

return sw.Error()
Expand Down
Loading

0 comments on commit 3ca01d2

Please sign in to comment.