Skip to content

Commit

Permalink
Fix generated RBAC manifests defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri committed Jun 20, 2019
1 parent 464fbed commit 9ac4b8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 6 additions & 3 deletions cmd/controller-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func main() {
Long: `A reference implementation generation tool for Kubernetes APIs.`,
Example: ` # Generate RBAC manifests for a project
controller-gen rbac
# Generate CRD manifests for a project
controller-gen crd
controller-gen crd
# Run all the generators for a given project
controller-gen all
Expand Down Expand Up @@ -155,7 +155,10 @@ Usage:
fmt.Printf("CRD manifests generated under '%s' \n", crdGen.OutputDir)

// RBAC generation
rbacOptions := &rbac.ManifestOptions{}
rbacOptions := &rbac.ManifestOptions{
InputDir: filepath.Join(projectDir, "pkg"),
OutputDir: filepath.Join(projectDir, "config", "rbac"),
}
rbacOptions.SetDefaults()
if err := rbac.Generate(rbacOptions); err != nil {
log.Fatal(err)
Expand Down
20 changes: 15 additions & 5 deletions pkg/rbac/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ type ManifestOptions struct {

// SetDefaults sets up the default options for RBAC Manifest generator.
func (o *ManifestOptions) SetDefaults() {
o.Name = "manager"
o.InputDir = filepath.Join(".", "pkg")
o.OutputDir = filepath.Join(".", "config", "rbac")
o.ServiceAccount = "default"
o.Namespace = "system"
if o.Name == "" {
o.Name = "manager"
}
if o.InputDir == "" {
o.InputDir = filepath.Join(".", "pkg")
}
if o.OutputDir == "" {
o.OutputDir = filepath.Join(".", "config", "rbac")
}
if o.ServiceAccount == "" {
o.ServiceAccount = "default"
}
if o.Namespace == "" {
o.Namespace = "system"
}
}

// RoleName returns the RBAC role name to be used in the manifests.
Expand Down

0 comments on commit 9ac4b8e

Please sign in to comment.