Skip to content

Commit e822b41

Browse files
Configure max retries (#1633)
<!-- Before you open the request please review the following guidelines and tips to help it be more easily integrated: - Describe the scope of your change - i.e. what the change does. - Describe any known limitations with your change. - Please run any tests or examples that can exercise your modified code. Thank you for contributing! We will try to test and integrate the change as soon as we can, but be aware we have many GitHub repositories to manage and can't immediately respond to every request. There is no need to bump or check in on a pull request (it will clutter the discussion of the request). Also don't be worried if the request is closed or not integrated sometimes the priorities of Bitnami might not match the priorities of the pull request. Don't fret, the open source community thrives on forks and GitHub makes it easy to keep your changes in a forked repo. --> **Description of the change** Allow to configure max retries **Applicable issues** <!-- Enter any applicable Issues here (You can reference an issue using #) --> - fixes #1599 --------- Signed-off-by: Alvaro Neira Ayuso <[email protected]> Signed-off-by: Alvaro Neira Ayuso <[email protected]> Co-authored-by: Alfredo Garcia <[email protected]>
1 parent 2c6d400 commit e822b41

File tree

7 files changed

+92
-74
lines changed

7 files changed

+92
-74
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ original Secret from the SealedSecret.
6060
- [How to use kubeseal if the controller is not running within the `kube-system` namespace?](#how-to-use-kubeseal-if-the-controller-is-not-running-within-the-kube-system-namespace)
6161
- [How to verify the images?](#how-to-verify-the-images)
6262
- [How to use one controller for a subset of namespaces](#How-to-use-one-controller-for-a-subset-of-namespaces)
63+
- [Can I configure the controller unseal retries](#can-i-configure-the-controller-unseal-retries)
6364

6465
- [Community](#community)
6566
- [Related projects](#related-projects)
@@ -826,6 +827,10 @@ cosign verify --key .github/workflows/cosign.pub docker.io/bitnami/sealed-secret
826827

827828
If you want to use one controller for more than one namespace, but not all namespaces, you can provide additional namespaces using the command line flag `--additional-namespaces=<namespace1>,<namespace2>,<...>`. Make sure you provide appropriate roles and rolebindings in the target namespaces, so the controller can manage the secrets in there.
828829

830+
### Can I configure the Controller unseal retries?
831+
832+
The answer is yes, you can configure the number of retries in your controller using the flag `--max-unseal-retries`. This flag allows you to configure the number of maximum retries to unseal your Sealed Secrets.
833+
829834
## Community
830835

831836
- [#sealed-secrets on Kubernetes Slack](https://kubernetes.slack.com/messages/sealed-secrets)

cmd/controller/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func bindControllerFlags(f *controller.Flags, fs *flag.FlagSet) {
5858

5959
fs.DurationVar(&f.KeyRenewPeriod, "rotate-period", defaultKeyRenewPeriod, "")
6060
_ = fs.MarkDeprecated("rotate-period", "please use key-renew-period instead")
61+
62+
fs.IntVar(&f.MaxRetries, "max-unseal-retries", 5, "Max unseal retries.")
6163
}
6264

6365
func bindFlags(f *controller.Flags, fs *flag.FlagSet, gofs *goflag.FlagSet) {

helm/sealed-secrets/README.md

+71-70
Large diffs are not rendered by default.

helm/sealed-secrets/templates/deployment.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ spec:
145145
- --listen-metrics-addr
146146
- {{ printf ":%s" (.Values.containerPorts.metrics | toString) }}
147147
{{- end }}
148+
{{- if .Values.maxRetries }}
149+
- --max-unseal-retries
150+
- {{ .Values.maxRetries | quote }}
151+
{{- end }}
148152
{{- end }}
149153
image: {{ printf "%s/%s:%s" .Values.image.registry .Values.image.repository .Values.image.tag }}
150154
imagePullPolicy: {{ .Values.image.pullPolicy }}

helm/sealed-secrets/values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ logLevel: ""
112112
## @param logFormat Specifies log format (text,json)
113113
##
114114
logFormat: ""
115+
## @param maxRetries Number of maximum retries
116+
##
117+
maxRetries: ""
115118
## @param command Override default container command
116119
##
117120
command: []

pkg/controller/controller.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import (
3838
)
3939

4040
const (
41-
maxRetries = 5
42-
4341
// SuccessUnsealed is used as part of the Event 'reason' when
4442
// a SealedSecret is unsealed successfully.
4543
SuccessUnsealed = "Unsealed"
@@ -60,6 +58,8 @@ const (
6058
var (
6159
// ErrCast happens when a K8s any type cannot be casted to the expected type.
6260
ErrCast = errors.New("cast error")
61+
62+
maxRetries = 5
6363
)
6464

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

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

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

105+
maxRetries = maxRetriesConfig
106+
105107
return &Controller{
106108
ssInformer: ssInformer,
107109
sInformer: sInformer,

pkg/controller/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Flags struct {
5555
LogFormat string
5656
PrivateKeyAnnotations string
5757
PrivateKeyLabels string
58+
MaxRetries int
5859
}
5960

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

0 commit comments

Comments
 (0)