Skip to content

Commit 60cbf52

Browse files
committed
Adding status reporting for NonTerminalCondition
1 parent 07c34f1 commit 60cbf52

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

templates/pkg/resource/sdk.go.tpl

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,17 @@ func (rm *resourceManager) updateConditions (
164164
165165
// Terminal condition
166166
var terminalCondition *ackv1alpha1.Condition = nil
167+
var nonTerminalCondition *ackv1alpha1.Condition = nil
167168
for _, condition := range ko.Status.Conditions {
169+
// If terminal condition exists, other errors will
170+
// will not be reported
168171
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
169172
terminalCondition = condition
170173
break
171174
}
175+
if condition.Type == ackv1alpha1.ConditionTypeNonTerminal {
176+
nonTerminalCondition = condition
177+
}
172178
}
173179

174180
if rm.terminalAWSError(err) {
@@ -182,19 +188,43 @@ func (rm *resourceManager) updateConditions (
182188
awsErr, _ := ackerr.AWSError(err)
183189
errorMessage := awsErr.Message()
184190
terminalCondition.Message = &errorMessage
185-
} else if terminalCondition != nil {
186-
terminalCondition.Status = corev1.ConditionFalse
187-
terminalCondition.Message = nil
191+
} else {
192+
// Clear the terminal condition if no longer present
193+
if terminalCondition != nil {
194+
terminalCondition.Status = corev1.ConditionFalse
195+
terminalCondition.Message = nil
196+
}
197+
// Handling NonTerminal Conditions
198+
if err != nil {
199+
if nonTerminalCondition == nil {
200+
// Add a new Condition containing a non-terminal error
201+
nonTerminalCondition = &ackv1alpha1.Condition{
202+
Type: ackv1alpha1.ConditionTypeNonTerminal,
203+
}
204+
ko.Status.Conditions = append(ko.Status.Conditions, nonTerminalCondition)
205+
}
206+
nonTerminalCondition.Status = corev1.ConditionTrue
207+
awsErr, _ := ackerr.AWSError(err)
208+
errorMessage := "Unknown Error"
209+
if awsErr != nil {
210+
errorMessage = awsErr.Message()
211+
}
212+
nonTerminalCondition.Message = &errorMessage
213+
} else if nonTerminalCondition != nil {
214+
nonTerminalCondition.Status = corev1.ConditionFalse
215+
nonTerminalCondition.Message = nil
216+
}
188217
}
189218

219+
190220
{{- if $updateConditionsCustomMethodName := .CRD.UpdateConditionsCustomMethodName }}
191221
// custom update conditions
192222
customUpdate := rm.{{ $updateConditionsCustomMethodName }}(ko, r, err)
193-
if terminalCondition != nil || customUpdate {
223+
if terminalCondition != nil || nonTerminalCondition != nil || customUpdate {
194224
return &resource{ko}, true // updated
195225
}
196226
{{- else }}
197-
if terminalCondition != nil {
227+
if terminalCondition != nil || nonTerminalCondition != nil {
198228
return &resource{ko}, true // updated
199229
}
200230
{{- end }}

0 commit comments

Comments
 (0)