Skip to content

Commit

Permalink
Configure max retries
Browse files Browse the repository at this point in the history
  • Loading branch information
alvneiayu committed Nov 7, 2024
1 parent 2c6d400 commit 0cba988
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 74 deletions.
2 changes: 2 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func bindControllerFlags(f *controller.Flags, fs *flag.FlagSet) {

fs.DurationVar(&f.KeyRenewPeriod, "rotate-period", defaultKeyRenewPeriod, "")
_ = fs.MarkDeprecated("rotate-period", "please use key-renew-period instead")

fs.IntVar(&f.MaxRetries, "max-retries", 5, "Max retries.")
}

func bindFlags(f *controller.Flags, fs *flag.FlagSet, gofs *goflag.FlagSet) {
Expand Down
141 changes: 71 additions & 70 deletions helm/sealed-secrets/README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions helm/sealed-secrets/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ spec:
- --listen-metrics-addr
- {{ printf ":%s" (.Values.containerPorts.metrics | toString) }}
{{- end }}
{{- if .Values.maxRetries }}
- --max-retries
- {{ .Values.maxRetries | quote }}
{{- end }}
{{- end }}
image: {{ printf "%s/%s:%s" .Values.image.registry .Values.image.repository .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand Down
3 changes: 3 additions & 0 deletions helm/sealed-secrets/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ logLevel: ""
## @param logFormat Specifies log format (text,json)
##
logFormat: ""
## @param maxRetries Number of maximum retries
##
maxRetries: ""
## @param command Override default container command
##
command: []
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import (
)

const (
maxRetries = 5

// SuccessUnsealed is used as part of the Event 'reason' when
// a SealedSecret is unsealed successfully.
SuccessUnsealed = "Unsealed"
Expand All @@ -60,6 +58,8 @@ const (
var (
// ErrCast happens when a K8s any type cannot be casted to the expected type.
ErrCast = errors.New("cast error")

maxRetries = 5
)

// Controller implements the main sealed-secrets-controller loop.
Expand All @@ -77,7 +77,7 @@ type Controller struct {
}

// NewController returns the main sealed-secrets controller loop.
func NewController(clientset kubernetes.Interface, ssclientset ssclientset.Interface, ssinformer ssinformer.SharedInformerFactory, sinformer informers.SharedInformerFactory, keyRegistry *KeyRegistry) (*Controller, error) {
func NewController(clientset kubernetes.Interface, ssclientset ssclientset.Interface, ssinformer ssinformer.SharedInformerFactory, sinformer informers.SharedInformerFactory, keyRegistry *KeyRegistry, maxRetriesConfig int) (*Controller, error) {
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())

utilruntime.Must(ssscheme.AddToScheme(scheme.Scheme))
Expand All @@ -102,6 +102,8 @@ func NewController(clientset kubernetes.Interface, ssclientset ssclientset.Inter
}
}

maxRetries = maxRetriesConfig

return &Controller{
ssInformer: ssInformer,
sInformer: sInformer,
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Flags struct {
LogFormat string
PrivateKeyAnnotations string
PrivateKeyLabels string
MaxRetries int
}

func initKeyPrefix(keyPrefix string) (string, error) {
Expand Down Expand Up @@ -267,7 +268,7 @@ func Main(f *Flags, version string) error {
func prepareController(clientset kubernetes.Interface, namespace string, tweakopts func(*metav1.ListOptions), f *Flags, ssclientset versioned.Interface, keyRegistry *KeyRegistry) (*Controller, error) {
sinformer := initSecretInformerFactory(clientset, namespace, tweakopts, f.SkipRecreate)
ssinformer := ssinformers.NewFilteredSharedInformerFactory(ssclientset, 0, namespace, tweakopts)
controller, err := NewController(clientset, ssclientset, ssinformer, sinformer, keyRegistry)
controller, err := NewController(clientset, ssclientset, ssinformer, sinformer, keyRegistry, f.MaxRetries)
return controller, err
}

Expand Down

0 comments on commit 0cba988

Please sign in to comment.