Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛Fix generated RBAC manifests defaults #230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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