Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release/2.12.x] fix(controller): Do not update existing Programmed condition to Unknown #6403

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
{{- end }}

{{- if .ProgrammedConditionUpdatesEnabled }}
log.V(util.DebugLevel).Info("updating programmed condition status", "namespace", req.Namespace, "name", req.Name)
configurationStatus := r.DataplaneClient.KubernetesObjectConfigurationStatus(obj)
log.V(util.DebugLevel).Info("updating programmed condition status", "namespace", req.Namespace, "name", req.Name, "configuration_status",configurationStatus)
conditions, updateNeeded := ctrlutils.EnsureProgrammedCondition(configurationStatus, obj.Generation, obj.Status.Conditions)
obj.Status.Conditions = conditions
{{- end }}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/controllers/utils/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func EnsureProgrammedCondition(configurationStatus object.ConfigurationStatus, o
if !ok {
conditions = append(conditions, desiredCondition)
} else {
// Do not update existing "Programmed" condition to Unknown to prevent races on updating status when new instance starts.
if configurationStatus == object.ConfigurationStatusUnknown {
return conditions, false
}
conditions[idx] = desiredCondition
}

Expand Down
22 changes: 11 additions & 11 deletions internal/controllers/utils/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ func TestEnsureProgrammedCondition(t *testing.T) {
Reason: string(kongv1.ReasonInvalid),
Message: utils.ProgrammedConditionFalseInvalidMessage,
}
expectedProgrammedConditionUnknown = metav1.Condition{
Type: string(kongv1.ConditionProgrammed),
Status: metav1.ConditionFalse,
ObservedGeneration: testObjectGeneration,
Reason: string(kongv1.ReasonPending),
Message: utils.ProgrammedConditionFalsePendingMessage,
}
)

testCases := []struct {
Expand Down Expand Up @@ -83,17 +76,24 @@ func TestEnsureProgrammedCondition(t *testing.T) {
},
{
name: "condition present with correct observed generation but different reason",
configurationStatus: object.ConfigurationStatusUnknown,
configurationStatus: object.ConfigurationStatusFailed,
conditions: []metav1.Condition{
func() metav1.Condition {
cond := expectedProgrammedConditionUnknown
cond.Reason = string(kongv1.ReasonInvalid)
cond := expectedProgrammedConditionFalse
cond.Reason = string("SomeOtherReason")
return cond
}(),
},
expectedUpdatedConditions: []metav1.Condition{expectedProgrammedConditionUnknown},
expectedUpdatedConditions: []metav1.Condition{expectedProgrammedConditionFalse},
expectedUpdateNeeded: true,
},
{
name: "Unknown status should not modify existing Programmed condition",
configurationStatus: object.ConfigurationStatusUnknown,
conditions: []metav1.Condition{expectedProgrammedConditionTrue},
expectedUpdatedConditions: []metav1.Condition{expectedProgrammedConditionTrue},
expectedUpdateNeeded: false,
},
{
name: "empty conditions",
configurationStatus: object.ConfigurationStatusSucceeded,
Expand Down
Loading