Skip to content

Commit

Permalink
Merge pull request #458 from DirectXMan12/bug/metrics-compatible-defa…
Browse files Browse the repository at this point in the history
…ult-name

✨ Allow setting controller name, fix default
  • Loading branch information
k8s-ci-robot committed May 30, 2019
2 parents 5320b25 + 2a14111 commit b56d269
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Builder struct {
watchRequest []watchRequest
config *rest.Config
ctrl controller.Controller
name string
}

// SimpleController returns a new Builder.
Expand Down Expand Up @@ -131,6 +132,16 @@ func (blder *Builder) WithEventFilter(p predicate.Predicate) *Builder {
return blder
}

// Named sets the name of the controller to the given name. The name shows up
// in metrics, among other things, and thus should be a prometheus compatible name
// (underscores and alphanumeric characters only).
//
// By default, controllers are named using the lowercase version of their kind.
func (blder *Builder) Named(name string) *Builder {
blder.name = name
return blder
}

// Complete builds the Application ControllerManagedBy.
func (blder *Builder) Complete(r reconcile.Reconciler) error {
_, err := blder.Build(r)
Expand Down Expand Up @@ -227,12 +238,14 @@ func (blder *Builder) doManager() error {
}

func (blder *Builder) getControllerName() (string, error) {
if blder.name != "" {
return blder.name, nil
}
gvk, err := getGvk(blder.apiType, blder.mgr.GetScheme())
if err != nil {
return "", err
}
name := fmt.Sprintf("%s-application", strings.ToLower(gvk.Kind))
return name, nil
return strings.ToLower(gvk.Kind), nil
}

func (blder *Builder) doController(r reconcile.Reconciler) error {
Expand Down

0 comments on commit b56d269

Please sign in to comment.