Skip to content

Commit

Permalink
fix: change existing resolvedRef condition to avoid duplicates (#3386)
Browse files Browse the repository at this point in the history
* fix: change existing condition for resolvedRef condition to avoid duplicates

* add CHANGELOG
  • Loading branch information
randmonkey committed Jan 16, 2023
1 parent 2d565d2 commit 98fc6b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ Adding a new version? You'll need three changes:
- Fixed the duplicate update of status of `HTTPRoute` caused by incorrect check
of whether status is changed.
[#3346](https://github.com/Kong/kubernetes-ingress-controller/pull/3346)
- Change existing `resolvedRefs` condition in status `HTTPRoute` if there is
already one to avoid multiple appearance of conditions with same type
[#3386](https://github.com/Kong/kubernetes-ingress-controller/pull/3386)

### Deprecated

Expand Down
26 changes: 15 additions & 11 deletions internal/controllers/gateway/httproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,24 +521,28 @@ func (r *HTTPRouteReconciler) setRouteConditionResolvedRefsCondition(

// iterate over all the parentStatuses conditions, and if no RouteConditionResolvedRefs is found,
// or if the condition is found but has to be changed, update the status and mark it to be updated
resolvedRefsCondition := metav1.Condition{
Type: string(gatewayv1beta1.RouteConditionResolvedRefs),
Status: resolvedRefsStatus,
ObservedGeneration: httpRoute.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(reason),
}
for _, parentStatus := range parentStatuses {
var conditionFound bool
for _, cond := range parentStatus.Conditions {
if cond.Type == string(gatewayv1beta1.RouteConditionResolvedRefs) &&
cond.Status == resolvedRefsStatus &&
cond.Reason == string(reason) {
for i, cond := range parentStatus.Conditions {
if cond.Type == string(gatewayv1beta1.RouteConditionResolvedRefs) {
if !(cond.Status == resolvedRefsStatus &&
cond.Reason == string(reason)) {
parentStatus.Conditions[i] = resolvedRefsCondition
changed = true
}
conditionFound = true
break
}
}
if !conditionFound {
parentStatus.Conditions = append(parentStatus.Conditions, metav1.Condition{
Type: string(gatewayv1beta1.RouteConditionResolvedRefs),
Status: resolvedRefsStatus,
ObservedGeneration: httpRoute.Generation,
LastTransitionTime: metav1.Now(),
Reason: string(reason),
})
parentStatus.Conditions = append(parentStatus.Conditions, resolvedRefsCondition)
changed = true
}
}
Expand Down

0 comments on commit 98fc6b4

Please sign in to comment.