Skip to content

Commit

Permalink
Add creating event recorder for controller in creating resource
Browse files Browse the repository at this point in the history
- Modified resourceControllerTemplate by adding
  1) "k8s.io/client-go/tools/record"
  2) event recorder field in Conroller struct
  3) initializing event recorder in ProvideController
  • Loading branch information
fanzhangio committed Apr 13, 2018
1 parent f72f5c9 commit a60f500
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/kubebuilder/create/resource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/kubernetes-sigs/kubebuilder/pkg/controller"
"github.com/kubernetes-sigs/kubebuilder/pkg/controller/types"
"k8s.io/client-go/tools/record"
{{.Group}}{{.Version}}client "{{.Repo}}/pkg/client/clientset/versioned/typed/{{.Group}}/{{.Version}}"
{{.Group}}{{.Version}}lister "{{.Repo}}/pkg/client/listers/{{.Group}}/{{.Version}}"
Expand All @@ -64,6 +65,9 @@ type {{.Kind}}Controller struct {
// INSERT ADDITIONAL FIELDS HERE
{{lower .Kind}}Lister {{.Group}}{{.Version}}lister.{{.Kind}}Lister
{{lower .Kind}}client {{.Group}}{{.Version}}client.{{title .Group}}{{title .Version}}Interface
// recorder is an event recorder for recording Event resources to the
// Kubernetes API.
{{lower .Kind}}recorder record.EventRecorder
}
// ProvideController provides a controller that will be run at startup. Kubebuilder will use codegeneration
Expand All @@ -73,6 +77,7 @@ func ProvideController(arguments args.InjectArgs) (*controller.GenericController
bc := &{{.Kind}}Controller{
{{lower .Kind}}Lister: arguments.ControllerManager.GetInformerProvider(&{{.Group}}{{.Version}}.{{.Kind}}{}).({{.Group}}{{.Version}}informer.{{.Kind}}Informer).Lister(),
{{lower .Kind}}client: arguments.Clientset.{{title .Group}}{{title .Version}}(),
{{lower .Kind}}recorder: arguments.CreateRecorder("{{.Kind}}Controller"),
}
// Create a new controller that will call {{.Kind}}Controller.Reconcile on changes to {{.Kind}}s
Expand Down

0 comments on commit a60f500

Please sign in to comment.