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

generate minimal config during installation #619

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
28 changes: 25 additions & 3 deletions cmd/gen_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime_ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

ic_api "github.com/pomerium/ingress-controller/apis/ingress/v1"
"github.com/pomerium/ingress-controller/util"
)

type genSecretsCmd struct {
secrets string
debug bool
secrets string
debug bool
generateGlobalConfig string

cobra.Command
}
Expand All @@ -36,6 +39,7 @@ func GenSecretsCommand() (*cobra.Command, error) {
func (s *genSecretsCmd) setupFlags() error {
flags := s.PersistentFlags()
flags.BoolVar(&s.debug, debug, false, "enable debug logging")
flags.StringVar(&s.generateGlobalConfig, "generate-global-config", "", "generate a default global config")
if err := flags.MarkHidden("debug"); err != nil {
return err
}
Expand Down Expand Up @@ -87,5 +91,23 @@ func (s *genSecretsCmd) exec(*cobra.Command, []string) error {
return fmt.Errorf("generate secrets: %w", err)
}

return c.Create(ctx, secret)
if err := c.Create(ctx, secret); err != nil {
return fmt.Errorf("create secret: %w", err)
}

if s.generateGlobalConfig != "" {
globalConfig := ic_api.Pomerium{
ObjectMeta: metav1.ObjectMeta{
Name: s.generateGlobalConfig,
},
Spec: ic_api.PomeriumSpec{
Secrets: name.String(),
},
}
if err := c.Create(ctx, &globalConfig); err != nil {
return fmt.Errorf("create global config: %w", err)
}
}

return nil
}
1 change: 1 addition & 0 deletions config/gen_secrets/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spec:
args:
- gen-secrets
- --secrets=$(POD_NAMESPACE)/bootstrap
- --generate-global-config=global
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
6 changes: 6 additions & 0 deletions config/gen_secrets/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ rules:
- secrets
verbs:
- create
- apiGroups:
- ingress.pomerium.io
resources:
- pomerium
verbs:
- create
7 changes: 7 additions & 0 deletions deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ rules:
- secrets
verbs:
- create
- apiGroups:
- ingress.pomerium.io
resources:
- pomerium
verbs:
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down Expand Up @@ -638,6 +644,7 @@ spec:
- args:
- gen-secrets
- --secrets=$(POD_NAMESPACE)/bootstrap
- --generate-global-config=global
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down