Skip to content

Commit b8799a6

Browse files
authored
fix terminal addons (#166)
fixes aws-controllers-k8s/community#2569 Description of changes: Fixes addon error handling by removing `CREATE_FAILED` and `UPDATE_FAILED` from terminal statuses and adding retry recovery. The controller now detects when addons are in failed states and forces `UpdateAddon` calls regardless of spec changes. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 6b10c1d commit b8799a6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pkg/resource/addon/hooks.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ var (
4848
ackrequeue.DefaultRequeueAfterDuration,
4949
)
5050
)
51+
var (
52+
// FailedStatuses defines the list of statuses that are a failed state for an addon
53+
FailedStatuses = []string{
54+
StatusCreateFailed,
55+
StatusUpdateFailed,
56+
}
57+
)
5158

5259
var (
5360
// TerminalStatuses defines the list of statuses that are terminal for an addon
5461
TerminalStatuses = []string{
55-
StatusCreateFailed,
56-
StatusUpdateFailed,
5762
StatusDeleteFailed,
5863
// Still not sure if we should consider DEGRADED as terminal
5964
// StatusDegraded,
@@ -212,11 +217,25 @@ func equalPodIdentityAssociations(desired, latest []*v1alpha1.AddonPodIdentityAs
212217
return true
213218
}
214219

220+
// addonInFailedState returns true if the supplied addon is in a failed state
221+
// that requires retry (CREATE_FAILED or UPDATE_FAILED)
222+
func addonHasFailedStatus(r *resource) bool {
223+
if r.ko.Status.Status == nil {
224+
return false
225+
}
226+
cs := *r.ko.Status.Status
227+
return cs == StatusCreateFailed || cs == StatusUpdateFailed
228+
}
229+
215230
// customPreCompare is a custom pre-compare function that compares the PodIdentityAssociations field
216231
func customPreCompare(delta *ackcompare.Delta, desired, latest *resource) {
217232
if !equalPodIdentityAssociations(desired.ko.Spec.PodIdentityAssociations, latest.ko.Spec.PodIdentityAssociations) {
218233
delta.Add("Spec.PodIdentityAssociations", desired.ko.Spec.PodIdentityAssociations, latest.ko.Spec.PodIdentityAssociations)
219234
}
235+
// Force update if addon is in failed state to attempt recovery
236+
if addonHasFailedStatus(latest) {
237+
delta.Add("Spec.ForceRecovery", desired.ko.Status.Status, latest.ko.Status.Status)
238+
}
220239
}
221240

222241
// formatPodIdentityAssociation returns a string representation of the pod identity association

0 commit comments

Comments
 (0)