Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import (
"github.com/openshift/hypershift/support/metrics"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/releaseinfo"
"github.com/openshift/hypershift/support/statuspatching"
"github.com/openshift/hypershift/support/upsert"
"github.com/openshift/hypershift/support/util"
"github.com/openshift/hypershift/support/validations"
Expand All @@ -110,7 +111,6 @@ import (
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -2320,20 +2320,20 @@ func (r *HostedControlPlaneReconciler) removeHCPIngressFromRoutes(ctx context.Co
// when the HCP router admits routes. We filter by this specific name to ensure
// we only remove ingress entries from the HCP router, not from other routers
// (e.g., the default ingress controller router).
originalRoute := route.DeepCopy()
filteredIngress := make([]routev1.RouteIngress, 0, len(route.Status.Ingress))
for _, ingress := range route.Status.Ingress {
if ingress.RouterName != "router" {
filteredIngress = append(filteredIngress, ingress)
}
}
if len(filteredIngress) != len(route.Status.Ingress) {
route.Status.Ingress = filteredIngress
if !equality.Semantic.DeepEqual(originalRoute.Status, route.Status) {
if err := r.Status().Patch(ctx, route, client.MergeFrom(originalRoute)); err != nil {
return fmt.Errorf("failed to clear route %s ingress: %w", route.Name, err)
// The filtering is recomputed inside the PatchStatus closure against whatever is
// freshly fetched on each retry, rather than a value captured beforehand, so a
// concurrent ingress write from the actual router controller isn't clobbered.
if err := statuspatching.PatchStatus(ctx, r.Client, route, func() error {
filteredIngress := make([]routev1.RouteIngress, 0, len(route.Status.Ingress))
for _, ingress := range route.Status.Ingress {
if ingress.RouterName != "router" {
filteredIngress = append(filteredIngress, ingress)
}
}
route.Status.Ingress = filteredIngress
return nil
}); err != nil {
return fmt.Errorf("failed to clear route %s ingress: %w", route.Name, err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2801,13 +2801,11 @@ func (r *reconciler) destroyCloudResources(ctx context.Context, hcp *hyperv1.Hos
Message: message,
}

originalHCP := hcp.DeepCopy()
meta.SetStatusCondition(&hcp.Status.Conditions, *resourcesDestroyedCond)

if !equality.Semantic.DeepEqual(hcp, originalHCP) {
if err := r.cpClient.Status().Patch(ctx, hcp, client.MergeFromWithOptions(originalHCP, client.MergeFromWithOptimisticLock{})); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to patch resources destroyed condition: %w", err)
}
// resourcesDestroyedCond is derived from a live guest-cluster check above, not a stale
// snapshot, so replaying it on PatchStatusCondition's retry is safe even if CPO's
// fallback timeout condition landed on the object in between.
if err := statuspatching.PatchStatusCondition(ctx, r.cpClient, hcp, &hcp.Status.Conditions, *resourcesDestroyedCond); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to patch resources destroyed condition: %w", err)
}

if remaining.Len() > 0 {
Expand Down
Loading