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

Adds possibility to disable CRDs on the binary #70

Merged
merged 2 commits into from
Mar 1, 2022
Merged
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
4 changes: 3 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func main() {
pflag.Int("ssh-key-length", 2048, "Default length of SSH Keys")
pflag.String("secret-encoding", "base64", "Encoding for secrets")
pflag.Bool("use-metrics-service", false, "Whether or not to use metrics service")
pflag.Bool("disable-crd-support", false, "Whether to disable CRD support and registering")

pflag.Parse()

// Import flags into viper and bind them to env vars
Expand Down Expand Up @@ -182,7 +184,7 @@ func main() {
}

// Setup all Controllers
if err = controller.AddToManager(mgr); err != nil {
if err = controller.AddToManager(mgr, !viper.GetBool("disable-crd-support")); err != nil {
log.Error(err, "")
os.Exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }}
image: {{ include "kubernetes-secret-generator.images.image" (dict "root" . "Values" .Values.image)}}
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: {{ toYaml .Values.args | nindent 12 }}
args:
{{- $args := .Values.args }}
{{- if not .Values.installCRDs }}
{{- $args = append $args "--disable-crd-support" }}
{{- end }}
{{- toYaml $args | nindent 12 }}
ports:
- containerPort: 8080
name: healthcheck
Expand Down
1 change: 1 addition & 0 deletions deploy/helm-chart/kubernetes-secret-generator/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
installCRDs: true
global:
imageRegistry:
imagePullSecrets:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/add_basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (

func init() {
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, basicauth.Add)
AddToManagerFuncs = append(AddToManagerFuncs, managerFunc{true, basicauth.Add})
}
2 changes: 1 addition & 1 deletion pkg/controller/add_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (

func init() {
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, secret.Add)
AddToManagerFuncs = append(AddToManagerFuncs, managerFunc{false, secret.Add})
}
2 changes: 1 addition & 1 deletion pkg/controller/add_sshkeypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (

func init() {
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, sshkeypair.Add)
AddToManagerFuncs = append(AddToManagerFuncs, managerFunc{true, sshkeypair.Add})
}
2 changes: 1 addition & 1 deletion pkg/controller/add_stringsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (

func init() {
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, stringsecret.Add)
AddToManagerFuncs = append(AddToManagerFuncs, managerFunc{true, stringsecret.Add})
}
17 changes: 12 additions & 5 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

type managerFunc struct {
isCRD bool
managerFunc func(manager.Manager) error
}

// AddToManagerFuncs is a list of functions to add all Controllers to the Manager
var AddToManagerFuncs []func(manager.Manager) error
var AddToManagerFuncs []managerFunc

// AddToManager adds all Controllers to the Manager
func AddToManager(m manager.Manager) error {
for _, f := range AddToManagerFuncs {
if err := f(m); err != nil {
return err
func AddToManager(m manager.Manager, enableCRDs bool) error {
for _, mf := range AddToManagerFuncs {
if enableCRDs || !mf.isCRD {
if err := mf.managerFunc(m); err != nil {
return err
}
}
}
return nil
Expand Down