Skip to content

Commit

Permalink
fix(*): do not annotate gateway services with ingress upstream (#3816)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz authored Feb 14, 2022
1 parent 02b0395 commit acae7af
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (r *GatewayInstanceReconciler) createOrUpdateService(
ObjectMeta: kube_meta.ObjectMeta{
Namespace: gatewayInstance.Namespace,
GenerateName: fmt.Sprintf("%s-", gatewayInstance.Name),
Annotations: map[string]string{
metadata.KumaGatewayAnnotation: metadata.AnnotationBuiltin,
},
},
}
if obj != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/plugins/runtime/k8s/controllers/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (r *ServiceReconciler) Reconcile(ctx context.Context, req kube_ctrl.Request
return kube_ctrl.Result{}, errors.Wrapf(err, "unable to fetch Service %s", req.NamespacedName.Name)
}

if svc.GetAnnotations()[metadata.KumaGatewayAnnotation] == metadata.AnnotationBuiltin {
return kube_ctrl.Result{}, nil
}

namespace := &kube_core.Namespace{}
if err := r.Get(ctx, kube_types.NamespacedName{Name: svc.GetNamespace()}, namespace); err != nil {
if kube_apierrs.IsNotFound(err) {
Expand Down
30 changes: 30 additions & 0 deletions pkg/plugins/runtime/k8s/controllers/service_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ var _ = Describe("ServiceReconciler", func() {
},
Spec: kube_core.ServiceSpec{},
},
&kube_core.Service{
ObjectMeta: kube_meta.ObjectMeta{
Namespace: "builtin-gateway",
Name: "service",
Annotations: map[string]string{
metadata.KumaGatewayAnnotation: metadata.AnnotationBuiltin,
},
},
Spec: kube_core.ServiceSpec{},
},
&kube_core.Service{
ObjectMeta: kube_meta.ObjectMeta{
Namespace: "non-system-ns-with-sidecar-injection",
Expand Down Expand Up @@ -116,6 +126,26 @@ var _ = Describe("ServiceReconciler", func() {
Expect(svc.GetAnnotations()).ToNot(HaveKey(metadata.IngressServiceUpstream))
})

It("should ignore service of builtin gateway", func() {
// given
req := kube_ctrl.Request{
NamespacedName: kube_types.NamespacedName{Namespace: "builtin-gateway", Name: "service"},
}

// when
result, err := reconciler.Reconcile(context.Background(), req)

// then
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeZero())

// and service is not annotated
svc := &kube_core.Service{}
err = kubeClient.Get(context.Background(), req.NamespacedName, svc)
Expect(err).ToNot(HaveOccurred())
Expect(svc.GetAnnotations()).ToNot(HaveKey(metadata.IngressServiceUpstream))
})

It("should update service in an annotated namespace", func() {
// given
req := kube_ctrl.Request{
Expand Down

0 comments on commit acae7af

Please sign in to comment.