Skip to content

Commit fe3789b

Browse files
committed
fix: require gateway parentRefs and retry without CRDs
1 parent 7d04ce1 commit fe3789b

5 files changed

Lines changed: 19 additions & 26 deletions

File tree

api/v1alpha1/types_shared.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ type GatewayExposeSpec struct {
128128
// WildcardHost is an optional wildcard hostname.
129129
WildcardHost string `json:"wildcardHost,omitempty"`
130130
// ParentRefs are Gateways that the HTTPRoute attaches to.
131-
ParentRefs []GatewayParentRef `json:"parentRefs,omitempty"`
131+
// At least one parentRef is required when gateway exposure is configured.
132+
// +kubebuilder:validation:MinItems=1
133+
ParentRefs []GatewayParentRef `json:"parentRefs"`
132134
}
133135

134136
// GatewayParentRef identifies a Gateway for HTTPRoute attachment.

config/crd/bases/coder.com_codercontrolplanes.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,9 @@ spec:
10391039
description: Host is the primary hostname for the HTTPRoute.
10401040
type: string
10411041
parentRefs:
1042-
description: ParentRefs are Gateways that the HTTPRoute attaches
1043-
to.
1042+
description: |-
1043+
ParentRefs are Gateways that the HTTPRoute attaches to.
1044+
At least one parentRef is required when gateway exposure is configured.
10441045
items:
10451046
description: GatewayParentRef identifies a Gateway for HTTPRoute
10461047
attachment.
@@ -1058,12 +1059,14 @@ spec:
10581059
required:
10591060
- name
10601061
type: object
1062+
minItems: 1
10611063
type: array
10621064
wildcardHost:
10631065
description: WildcardHost is an optional wildcard hostname.
10641066
type: string
10651067
required:
10661068
- host
1069+
- parentRefs
10671070
type: object
10681071
ingress:
10691072
description: Ingress configures a networking.k8s.io/v1 Ingress.

docs/reference/api/codercontrolplane.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ GatewayExposeSpec defines Gateway API (HTTPRoute) exposure configuration.
9595
| --- | --- | --- |
9696
| `host` | string | Host is the primary hostname for the HTTPRoute. |
9797
| `wildcardHost` | string | WildcardHost is an optional wildcard hostname. |
98-
| `parentRefs` | [GatewayParentRef](#gatewayparentref) array | ParentRefs are Gateways that the HTTPRoute attaches to. |
98+
| `parentRefs` | [GatewayParentRef](#gatewayparentref) array | ParentRefs are Gateways that the HTTPRoute attaches to. At least one parentRef is required when gateway exposure is configured. |
9999

100100
### GatewayParentRef
101101

internal/controller/codercontrolplane_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,9 @@ func (r *CoderControlPlaneReconciler) reconcileHTTPRoute(ctx context.Context, co
13101310
if err != nil {
13111311
if meta.IsNoMatchError(err) {
13121312
ctrl.LoggerFrom(ctx).WithName("controller").WithName("codercontrolplane").Info(
1313-
"Gateway API CRDs not available, skipping HTTPRoute reconciliation",
1313+
"Gateway API CRDs not available, retrying HTTPRoute reconciliation",
13141314
)
1315-
return false, nil
1315+
return true, nil
13161316
}
13171317
return false, fmt.Errorf("reconcile control plane httproute: %w", err)
13181318
}

internal/controller/codercontrolplane_controller_test.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,27 +3649,15 @@ func TestReconcile_HTTPRouteExposure_RequiresParentRefs(t *testing.T) {
36493649
},
36503650
},
36513651
}
3652-
if err := k8sClient.Create(ctx, cp); err != nil {
3653-
t.Fatalf("create control plane: %v", err)
3654-
}
3655-
t.Cleanup(func() {
3656-
_ = k8sClient.Delete(ctx, cp)
3657-
})
3658-
3659-
r := &controller.CoderControlPlaneReconciler{Client: k8sClient, Scheme: scheme}
3660-
namespacedName := types.NamespacedName{Name: cp.Name, Namespace: cp.Namespace}
3661-
_, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: namespacedName})
3652+
err := k8sClient.Create(ctx, cp)
36623653
if err == nil {
3663-
t.Fatal("expected reconcile to fail when gateway parentRefs are missing")
3654+
t.Fatal("expected create to fail when gateway parentRefs are missing")
36643655
}
3665-
if !strings.Contains(err.Error(), "gateway parentRefs must not be empty") {
3666-
t.Fatalf("expected missing parentRefs assertion error, got: %v", err)
3656+
if !apierrors.IsInvalid(err) {
3657+
t.Fatalf("expected invalid error for missing gateway parentRefs, got: %v", err)
36673658
}
3668-
3669-
httpRoute := &gatewayv1.HTTPRoute{}
3670-
err = k8sClient.Get(ctx, namespacedName, httpRoute)
3671-
if !apierrors.IsNotFound(err) {
3672-
t.Fatalf("expected httproute to be absent when parentRefs are missing, got: %v", err)
3659+
if !strings.Contains(err.Error(), "parentRefs") {
3660+
t.Fatalf("expected missing parentRefs validation error, got: %v", err)
36733661
}
36743662
}
36753663

@@ -3708,8 +3696,8 @@ func TestReconcile_HTTPRouteExposure_CRDMissingIsGraceful(t *testing.T) {
37083696
if err != nil {
37093697
t.Fatalf("expected reconcile to gracefully ignore missing Gateway CRDs, got error: %v", err)
37103698
}
3711-
if result.RequeueAfter > 0 {
3712-
t.Fatalf("expected missing Gateway CRDs to avoid requeue, got %+v", result)
3699+
if result.RequeueAfter <= 0 {
3700+
t.Fatalf("expected missing Gateway CRDs to request periodic requeue, got %+v", result)
37133701
}
37143702
if clientWithNoMatch.HTTPRouteGetCalls() == 0 {
37153703
t.Fatal("expected gateway exposure reconciliation to attempt HTTPRoute get")

0 commit comments

Comments
 (0)