Skip to content

Commit

Permalink
Add informerer factory to default args
Browse files Browse the repository at this point in the history
  • Loading branch information
pwittrock committed Mar 15, 2018
1 parent cf63cf3 commit 12ec8cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions cmd/kubebuilder-gen/internal/controllergen/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ func init() {
{{ range $group := .APIS.Groups }}{{ range $version := $group.Versions }}{{ range $res := $version.Resources -}}
arguments.ControllerManager.AddInformerProvider(&{{.Group}}{{.Version}}.{{.Kind}}{}, factory.{{title .Group}}().{{title .Version}}().{{plural .Kind}}())
{{ end }}{{ end }}{{ end -}}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubebuilder/initproject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func RunAll(options run.RunArguments, arguments args.InjectArgs) error {
if Run != nil {
if err := Run(options); err != nil {
return error
return err
}
}
<-options.Stop
Expand Down
10 changes: 9 additions & 1 deletion pkg/inject/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ limitations under the License.
package args

import (
"time"

"github.com/kubernetes-sigs/kubebuilder/pkg/admission"
"github.com/kubernetes-sigs/kubebuilder/pkg/controller"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/informers"
)

// InjectArgs are the common arguments for initializing controllers and admission hooks
Expand All @@ -31,6 +34,9 @@ type InjectArgs struct {
// KubernetesClientSet is a clientset to talk to Kuberntes apis
KubernetesClientSet *kubernetes.Clientset

// KubernetesInformers contains a Kubernetes informers factory
KubernetesInformers informers.SharedInformerFactory

// ControllerManager is the controller manager
ControllerManager *controller.ControllerManager

Expand All @@ -40,9 +46,11 @@ type InjectArgs struct {

// CreateInjectArgs returns new arguments for initializing objects
func CreateInjectArgs(config *rest.Config) InjectArgs {
cs := kubernetes.NewForConfigOrDie(config)
return InjectArgs{
Config: config,
KubernetesClientSet: kubernetes.NewForConfigOrDie(config),
KubernetesClientSet: cs,
KubernetesInformers: informers.NewSharedInformerFactory(cs, 2 * time.Minute),
ControllerManager: &controller.ControllerManager{},
AdmissionHandler: &admission.AdmissionManager{},
}
Expand Down

0 comments on commit 12ec8cf

Please sign in to comment.