Skip to content

Commit d7f658e

Browse files
committed
Mirror OpenShift Route admission errors to OpenStackControlPlane conditions
Add route admission status checking to ensure that OpenStackControlPlane expose conditions (e.g., OpenStackControlPlaneExposeBarbicanReady) properly reflect errors from the underlying OpenShift Route objects. Previously, the expose conditions would be set based only on whether the route could be created, but would not reflect subsequent admission failures by the OpenShift router (e.g., hostname conflicts, invalid configurations). This could leave the condition in a misleading state where it appeared successful while the route was actually not admitted. Changes: - Add checkRouteAdmissionStatus() helper function to inspect route status.ingress[0].conditions for the "Admitted" condition - Update ensureRoute() to check route admission status after creation and update the condition accordingly - Add OpenStackControlPlaneExposeServiceReadyRouteAdmissionErrorMessage constant for clear error reporting - Set expose conditions to True only when routes are successfully admitted - Set expose conditions to False with detailed error messages when route admission fails This ensures that conditions like OpenStackControlPlaneExposeBarbicanReady, OpenStackControlPlaneExposeKeystoneAPIReady, etc. accurately reflect the actual state of the routes, making debugging easier for operators. The implementation handles edge cases gracefully: - Routes without ingress status yet (during initial creation) - Routes without admission conditions yet (still being processed) - Routes with failed admission (error is surfaced in the condition) - Routes successfully admitted (condition set to True) Note: RouteAdmitted (type "Admitted") is currently the only officially defined condition type in the OpenShift Route API (github.com/openshift/api). The implementation loops through all conditions to be future-proof for when additional condition types are added, but today it will only find the "Admitted" condition. Jira: https://issues.redhat.com/browse/OSPRH-8984 AssistedBy: cloude-4-sonnet Signed-off-by: Martin Schuppert <[email protected]>
1 parent 89bc9f2 commit d7f658e

File tree

4 files changed

+637
-0
lines changed

4 files changed

+637
-0
lines changed

apis/core/v1beta1/conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ const (
448448
// OpenStackControlPlaneExposeServiceReadyMessage
449449
OpenStackControlPlaneExposeServiceReadyMessage = "OpenStackControlPlane %s service exposed"
450450

451+
// OpenStackControlPlaneExposeServiceReadyRouteAdmissionErrorMessage
452+
OpenStackControlPlaneExposeServiceReadyRouteAdmissionErrorMessage = "OpenStackControlPlane %s route %s admission failed: %s"
453+
451454
// OpenStackControlPlaneCAReadyInitMessage
452455
OpenStackControlPlaneCAReadyInitMessage = "OpenStackControlPlane CAs not started"
453456

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ require (
114114
golang.org/x/tools v0.37.0 // indirect
115115
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
116116
google.golang.org/protobuf v1.36.7 // indirect
117+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
117118
gopkg.in/inf.v0 v0.9.1 // indirect
118119
k8s.io/apiextensions-apiserver v0.33.2 // indirect
119120
k8s.io/klog/v2 v2.130.1 // indirect

pkg/openstack/common.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,26 @@ func (ed *EndpointDetail) ensureRoute(
516516
return ctrlResult, nil
517517
}
518518

519+
// Check the route admission status and update condition accordingly
520+
err = checkRouteAdmissionStatus(ctx, helper, ed.Name, ed.Namespace)
521+
if err != nil {
522+
instance.Status.Conditions.Set(condition.FalseCondition(
523+
condType,
524+
condition.ErrorReason,
525+
condition.SeverityWarning,
526+
corev1.OpenStackControlPlaneExposeServiceReadyRouteAdmissionErrorMessage,
527+
owner.GetName(),
528+
ed.Name,
529+
err.Error()))
530+
return ctrl.Result{}, err
531+
}
532+
533+
// Route is successfully created and admitted
534+
instance.Status.Conditions.MarkTrue(
535+
condType,
536+
corev1.OpenStackControlPlaneExposeServiceReadyMessage,
537+
owner.GetName())
538+
519539
return ctrl.Result{}, nil
520540
}
521541
instance.Status.Conditions.Remove(condType)
@@ -707,6 +727,45 @@ func (ed *EndpointDetail) CreateRoute(
707727
return ctrl.Result{}, nil
708728
}
709729

730+
// checkRouteAdmissionStatus checks the admission status of a route and returns an error if not admitted
731+
func checkRouteAdmissionStatus(
732+
ctx context.Context,
733+
helper *helper.Helper,
734+
routeName string,
735+
namespace string,
736+
) error {
737+
serviceRoute := &routev1.Route{}
738+
err := helper.GetClient().Get(ctx, types.NamespacedName{Name: routeName, Namespace: namespace}, serviceRoute)
739+
if err != nil {
740+
return err
741+
}
742+
743+
// Check if the route has ingress status
744+
if len(serviceRoute.Status.Ingress) == 0 {
745+
// Route exists but has no ingress status yet - this is normal during initial creation
746+
// Return nil to allow reconciliation to continue
747+
return nil
748+
}
749+
750+
// Check the admission status of the first ingress
751+
for _, condition := range serviceRoute.Status.Ingress[0].Conditions {
752+
// RouteAdmitted (value: "Admitted") is currently the only officially defined condition type in the OpenShift Route API
753+
// https://github.com/openshift/api/blob/c9bef43e850983ce73f69a58b9da0bd02883c26a/route/v1/types.go#L384
754+
// RouteAdmitted means the route is able to service requests for the provided Host
755+
if condition.Type == routev1.RouteAdmitted {
756+
if condition.Status != k8s_corev1.ConditionTrue {
757+
// Route admission failed - return error with the message
758+
return fmt.Errorf("%s", condition.Message)
759+
}
760+
// Route is admitted successfully
761+
return nil
762+
}
763+
}
764+
765+
// No admission condition found yet - route is still being processed
766+
return nil
767+
}
768+
710769
// GetEndptCertSecret -
711770
func (e *Endpoints) GetEndptCertSecret(endpt service.Endpoint) *string {
712771
var endptTLSSecret *string

0 commit comments

Comments
 (0)