Skip to content

Commit acc2fdf

Browse files
committed
Make IgnoreUpdate secrets optional
Fixes issue where nonexistent secret with ignoreUpdate set would cause the plan to endlessly requeue due to errors. If it is ignored for purposes of plan hash, it should be optional. Signed-off-by: Brad Davidson <[email protected]>
1 parent 9de9132 commit acc2fdf

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

pkg/upgrade/handle_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (ctl *Controller) handlePlans(ctx context.Context) error {
4040
// validate plan, and generate events for transitions
4141
validated := upgradeapiv1.PlanSpecValidated
4242
validated.CreateUnknownIfNotExists(obj)
43-
if err := upgradeplan.Validate(obj); err != nil {
43+
if err := upgradeplan.Validate(obj, secretsCache); err != nil {
4444
if !validated.IsFalse(obj) {
4545
recorder.Eventf(obj, corev1.EventTypeWarning, "ValidateFailed", "Failed to validate plan: %v", err)
4646
}

pkg/upgrade/job/job.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ func New(plan *upgradeapiv1.Plan, node *corev1.Node, controllerName string) *bat
288288
VolumeSource: corev1.VolumeSource{
289289
Secret: &corev1.SecretVolumeSource{
290290
SecretName: secret.Name,
291+
Optional: pointer.Bool(secret.IgnoreUpdates),
291292
},
292293
},
293294
})

pkg/upgrade/plan/plan.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ func DigestStatus(plan *upgradeapiv1.Plan, secretCache corectlv1.SecretCache) (u
7979
}
8080

8181
for _, s := range plan.Spec.Secrets {
82-
secret, err := secretCache.Get(plan.Namespace, s.Name)
83-
if err != nil {
84-
return plan.Status, err
85-
}
8682
if !s.IgnoreUpdates {
83+
secret, err := secretCache.Get(plan.Namespace, s.Name)
84+
if err != nil {
85+
return plan.Status, err
86+
}
87+
8788
secretHash, err := hash.SecretHash(secret)
8889
if err != nil {
8990
return plan.Status, err
9091
}
92+
9193
h.Write([]byte(secretHash))
9294
}
9395
}
@@ -239,7 +241,7 @@ func sha256sum(s ...string) string {
239241
}
240242

241243
// Validate performs validation of the plan spec, raising errors for any conflicting or invalid settings.
242-
func Validate(plan *upgradeapiv1.Plan) error {
244+
func Validate(plan *upgradeapiv1.Plan, secretCache corectlv1.SecretCache) error {
243245
if drainSpec := plan.Spec.Drain; drainSpec != nil {
244246
if drainSpec.DeleteEmptydirData != nil && drainSpec.DeleteLocalData != nil {
245247
return ErrDrainDeleteConflict
@@ -262,5 +264,16 @@ func Validate(plan *upgradeapiv1.Plan) error {
262264
if delay := plan.Spec.PostCompleteDelay; delay != nil && delay.Duration < 0 {
263265
return ErrInvalidDelay
264266
}
265-
return nil
267+
268+
sErrs := []error{}
269+
for _, secret := range plan.Spec.Secrets {
270+
if secret.IgnoreUpdates {
271+
continue
272+
}
273+
if _, err := secretCache.Get(plan.Namespace, secret.Name); err != nil {
274+
sErrs = append(sErrs, err)
275+
}
276+
}
277+
278+
return merr.NewErrors(sErrs...)
266279
}

0 commit comments

Comments
 (0)