Skip to content

Commit b977d86

Browse files
authored
Merge pull request #40 from jkuruba/statuschanges
Adding status reporting for RecoverableCondition
2 parents 3aa6d5c + 73f41e6 commit b977d86

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

templates/pkg/resource/sdk.go.tpl

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ func (rm *resourceManager) updateConditions (
164164
165165
// Terminal condition
166166
var terminalCondition *ackv1alpha1.Condition = nil
167+
var recoverableCondition *ackv1alpha1.Condition = nil
167168
for _, condition := range ko.Status.Conditions {
168169
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
169170
terminalCondition = condition
170-
break
171+
}
172+
if condition.Type == ackv1alpha1.ConditionTypeRecoverable {
173+
recoverableCondition = condition
171174
}
172175
}
173176

@@ -182,19 +185,43 @@ func (rm *resourceManager) updateConditions (
182185
awsErr, _ := ackerr.AWSError(err)
183186
errorMessage := awsErr.Message()
184187
terminalCondition.Message = &errorMessage
185-
} else if terminalCondition != nil {
186-
terminalCondition.Status = corev1.ConditionFalse
187-
terminalCondition.Message = nil
188+
} else {
189+
// Clear the terminal condition if no longer present
190+
if terminalCondition != nil {
191+
terminalCondition.Status = corev1.ConditionFalse
192+
terminalCondition.Message = nil
193+
}
194+
// Handling Recoverable Conditions
195+
if err != nil {
196+
if recoverableCondition == nil {
197+
// Add a new Condition containing a non-terminal error
198+
recoverableCondition = &ackv1alpha1.Condition{
199+
Type: ackv1alpha1.ConditionTypeRecoverable,
200+
}
201+
ko.Status.Conditions = append(ko.Status.Conditions, recoverableCondition)
202+
}
203+
recoverableCondition.Status = corev1.ConditionTrue
204+
awsErr, _ := ackerr.AWSError(err)
205+
errorMessage := err.Error()
206+
if awsErr != nil {
207+
errorMessage = awsErr.Message()
208+
}
209+
recoverableCondition.Message = &errorMessage
210+
} else if recoverableCondition != nil {
211+
recoverableCondition.Status = corev1.ConditionFalse
212+
recoverableCondition.Message = nil
213+
}
188214
}
189215

216+
190217
{{- if $updateConditionsCustomMethodName := .CRD.UpdateConditionsCustomMethodName }}
191218
// custom update conditions
192219
customUpdate := rm.{{ $updateConditionsCustomMethodName }}(ko, r, err)
193-
if terminalCondition != nil || customUpdate {
220+
if terminalCondition != nil || recoverableCondition != nil || customUpdate {
194221
return &resource{ko}, true // updated
195222
}
196223
{{- else }}
197-
if terminalCondition != nil {
224+
if terminalCondition != nil || recoverableCondition != nil {
198225
return &resource{ko}, true // updated
199226
}
200227
{{- end }}

0 commit comments

Comments
 (0)