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

provisioner: Ensure GatewayClass condition generations are updated #4932

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions internal/provisioner/controller/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,22 @@ func (r *gatewayClassReconciler) setAcceptedCondition(
reason gatewayapi_v1beta1.GatewayClassConditionReason,
message string,
) error {
currentAcceptedCondition := metav1.Condition{
Type: string(gatewayapi_v1beta1.GatewayClassConditionStatusAccepted),
Status: status,
ObservedGeneration: gatewayClass.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(reason),
Message: message,
}
var newConds []metav1.Condition
for _, cond := range gatewayClass.Status.Conditions {
if cond.Type == string(gatewayapi_v1beta1.GatewayClassConditionStatusAccepted) {
if cond.Status == status {
return nil
// If status hasn't changed, don't change the condition, just
// update the generation.
currentAcceptedCondition = cond
currentAcceptedCondition.ObservedGeneration = gatewayClass.Generation
}

continue
Expand All @@ -262,14 +273,7 @@ func (r *gatewayClassReconciler) setAcceptedCondition(
r.log.WithValues("gatewayclass-name", gatewayClass.Name).Info(fmt.Sprintf("setting gateway class's Accepted condition to %s", status))

// nolint:gocritic
gatewayClass.Status.Conditions = append(newConds, metav1.Condition{
Type: string(gatewayapi_v1beta1.GatewayClassConditionStatusAccepted),
Status: status,
ObservedGeneration: gatewayClass.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(reason),
Message: message,
})
gatewayClass.Status.Conditions = append(newConds, currentAcceptedCondition)

if err := r.client.Status().Update(ctx, gatewayClass); err != nil {
return fmt.Errorf("failed to set gatewayclass %s accepted condition: %w", gatewayClass.Name, err)
Expand Down
26 changes: 26 additions & 0 deletions internal/provisioner/controller/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,31 @@ func TestGatewayClassReconcile(t *testing.T) {
Reason: string(gatewayv1beta1.GatewayClassReasonInvalidParameters),
},
},
"gatewayclass with status from previous generation is updated": {
gatewayClass: &gatewayv1beta1.GatewayClass{
ObjectMeta: metav1.ObjectMeta{
Name: "gatewayclass-1",
Generation: 2,
},
Spec: gatewayv1beta1.GatewayClassSpec{
ControllerName: "projectcontour.io/gateway-controller",
},
Status: gatewayv1beta1.GatewayClassStatus{
Conditions: []metav1.Condition{{
Type: string(gatewayv1beta1.GatewayClassConditionStatusAccepted),
Status: metav1.ConditionTrue,
Reason: string(gatewayv1beta1.GatewayClassReasonAccepted),
ObservedGeneration: 1,
}},
},
},
wantCondition: &metav1.Condition{
Type: string(gatewayv1beta1.GatewayClassConditionStatusAccepted),
Status: metav1.ConditionTrue,
Reason: string(gatewayv1beta1.GatewayClassReasonAccepted),
ObservedGeneration: 2,
},
},
}

for name, tc := range tests {
Expand Down Expand Up @@ -424,6 +449,7 @@ func TestGatewayClassReconcile(t *testing.T) {
assert.Equal(t, tc.wantCondition.Type, res.Status.Conditions[0].Type)
assert.Equal(t, tc.wantCondition.Status, res.Status.Conditions[0].Status)
assert.Equal(t, tc.wantCondition.Reason, res.Status.Conditions[0].Reason)
assert.Equal(t, tc.wantCondition.ObservedGeneration, res.Status.Conditions[0].ObservedGeneration)
}

if tc.assertions != nil {
Expand Down