Skip to content

Commit b64338c

Browse files
authored
Reject service network actions when gateway class is under non-default namespace (#130)
* reject non-default service network creation * reject non-default service network creation
1 parent 00420a4 commit b64338c

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

controllers/gateway_controller.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949

5050
const (
5151
gatewayFinalizer = "gateway.k8s.aws/resources"
52+
defaultNameSpace = "default"
5253
)
5354

5455
// GatewayReconciler reconciles a Gateway object
@@ -108,6 +109,10 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
108109
return lattice_runtime.HandleReconcileError(r.reconcile(ctx, req))
109110
}
110111

112+
func (r *GatewayReconciler) isDefaultNameSpace(n string) bool {
113+
return n == defaultNameSpace
114+
}
115+
111116
func (r *GatewayReconciler) reconcile(ctx context.Context, req ctrl.Request) error {
112117
gwLog := log.FromContext(ctx)
113118

@@ -118,9 +123,16 @@ func (r *GatewayReconciler) reconcile(ctx context.Context, req ctrl.Request) err
118123
return client.IgnoreNotFound(err)
119124
}
120125

126+
if !r.isDefaultNameSpace(gw.Namespace) {
127+
errmsg := "VPC lattice do not support no-default namespace gateway111"
128+
glog.V(2).Infof(errmsg)
129+
r.updateBadStatus(ctx, errmsg, gw)
130+
return nil
131+
}
132+
121133
gwClass := &gateway_api.GatewayClass{}
122134
gwClassName := types.NamespacedName{
123-
Namespace: "default",
135+
Namespace: defaultNameSpace,
124136
Name: string(gw.Spec.GatewayClassName),
125137
}
126138

@@ -144,7 +156,7 @@ func (r *GatewayReconciler) reconcile(ctx context.Context, req ctrl.Request) err
144156
continue
145157
}
146158
gwName := types.NamespacedName{
147-
Namespace: "default",
159+
Namespace: defaultNameSpace,
148160
Name: string(httpRoute.Spec.ParentRefs[0].Name),
149161
}
150162

@@ -267,6 +279,27 @@ func (r *GatewayReconciler) updateGatewayStatus(ctx context.Context, serviceNetw
267279
return nil
268280
}
269281

282+
func (r *GatewayReconciler) updateBadStatus(ctx context.Context, message string, gw *gateway_api.Gateway) error {
283+
284+
gwOld := gw.DeepCopy()
285+
286+
glog.V(6).Infof("updateGatewayStatus: updating last transition time \n")
287+
if gw.Status.Conditions[0].LastTransitionTime == eventhandlers.ZeroTransitionTime {
288+
gw.Status.Conditions[0].LastTransitionTime = metav1.NewTime(time.Now())
289+
}
290+
291+
gw.Status.Conditions[0].Status = "False"
292+
gw.Status.Conditions[0].Message = message
293+
gw.Status.Conditions[0].Reason = "NoReconcile"
294+
gw.Status.Conditions[0].Type = "NotAccepted"
295+
296+
if err := r.Client.Status().Patch(ctx, gw, client.MergeFrom(gwOld)); err != nil {
297+
return errors.Wrapf(err, "failed to update gateway status")
298+
}
299+
300+
return nil
301+
}
302+
270303
// SetupWithManager sets up the controller with the Manager.
271304
func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
272305
gwClassEventHandler := eventhandlers.NewEnqueueRequestsForGatewayClassEvent(r.Client)

0 commit comments

Comments
 (0)