Skip to content

Commit

Permalink
fix: only check if condition contained in httproute
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Jan 9, 2023
1 parent e3c862d commit 6b73827
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/controllers/gateway/httproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,10 @@ func (r *HTTPRouteReconciler) ensureGatewayReferenceStatusAdded(ctx context.Cont
// if the reference already exists and doesn't require any changes
// then just leave it alone.
if existingGatewayParentStatus, exists := parentStatuses[key]; exists {
// fake the time of the existing status as this wont be equal
for i := range existingGatewayParentStatus.Conditions {
existingGatewayParentStatus.Conditions[i].LastTransitionTime = gatewayParentStatus.Conditions[0].LastTransitionTime
}

// other than the condition timestamps, check if the statuses are equal
if reflect.DeepEqual(existingGatewayParentStatus, gatewayParentStatus) {
// check if the parentRef and controllerName are equal, and expected condition presents in conditions
if reflect.DeepEqual(existingGatewayParentStatus.ParentRef, gatewayParentStatus.ParentRef) &&
existingGatewayParentStatus.ControllerName == gatewayParentStatus.ControllerName &&
containsCondition(existingGatewayParentStatus.Conditions, gatewayParentStatus.Conditions[0]) {
continue
}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/controllers/gateway/route_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,17 @@ func isHTTPReferenceGranted(grantSpec gatewayv1alpha2.ReferenceGrantSpec, backen
}
return false
}

// containsCondition returns true if a condition with same type, status, reason and message
// of expectedCondition in conditions
func containsCondition(conditions []metav1.Condition, expectedCondition metav1.Condition) bool {
for _, condition := range conditions {
if condition.Type == expectedCondition.Type &&
condition.Status == expectedCondition.Status &&
condition.Reason == expectedCondition.Reason &&
condition.Message == expectedCondition.Message {
return true
}
}
return false
}

0 comments on commit 6b73827

Please sign in to comment.