From 6cd8ddddc50395d1975413e6e80f35b24b7311ae Mon Sep 17 00:00:00 2001 From: Phil Nichol <35630607+philnichol@users.noreply.github.com> Date: Thu, 5 May 2022 17:43:29 +0100 Subject: [PATCH] feat: Added the optional appProtocol field to Canary.Service Signed-off-by: Phil Nichol <35630607+philnichol@users.noreply.github.com> --- artifacts/flagger/crd.yaml | 3 +++ pkg/apis/flagger/v1beta1/canary.go | 5 +++++ pkg/router/kubernetes_default.go | 4 ++++ pkg/router/kubernetes_default_test.go | 2 ++ pkg/router/router_test.go | 1 + 5 files changed, 15 insertions(+) diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index 19b24319e..9f93d4ea1 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -158,6 +158,9 @@ spec: portName: description: Container port name type: string + appProtocol: + description: Application protocol of the port + type: string targetPort: description: Container target port name x-kubernetes-int-or-string: true diff --git a/pkg/apis/flagger/v1beta1/canary.go b/pkg/apis/flagger/v1beta1/canary.go index 627d288be..bf22f1b2f 100644 --- a/pkg/apis/flagger/v1beta1/canary.go +++ b/pkg/apis/flagger/v1beta1/canary.go @@ -128,6 +128,11 @@ type CanaryService struct { // +optional TargetPort intstr.IntOrString `json:"targetPort,omitempty"` + // AppProtocol of the service + // https://kubernetes.io/docs/concepts/services-networking/service/#application-protocol + // +optional + AppProtocol string `json:"appProtocol,omitempty"` + // PortDiscovery adds all container ports to the generated Kubernetes service PortDiscovery bool `json:"portDiscovery"` diff --git a/pkg/router/kubernetes_default.go b/pkg/router/kubernetes_default.go index 118d5ab07..61ffd7fd5 100644 --- a/pkg/router/kubernetes_default.go +++ b/pkg/router/kubernetes_default.go @@ -114,6 +114,10 @@ func (c *KubernetesDefaultRouter) reconcileService(canary *flaggerv1.Canary, nam }, } + if v := canary.Spec.Service.AppProtocol; v != "" { + svcSpec.Ports[0].AppProtocol = &v + } + // set additional ports for n, p := range c.ports { cp := corev1.ServicePort{ diff --git a/pkg/router/kubernetes_default_test.go b/pkg/router/kubernetes_default_test.go index a18883413..9d4648f6b 100644 --- a/pkg/router/kubernetes_default_test.go +++ b/pkg/router/kubernetes_default_test.go @@ -39,6 +39,7 @@ func TestServiceRouter_Create(t *testing.T) { flaggerClient: mocks.flaggerClient, logger: mocks.logger, } + appProtocol := "http" err := router.Initialize(mocks.canary) require.NoError(t, err) @@ -49,6 +50,7 @@ func TestServiceRouter_Create(t *testing.T) { canarySvc, err := mocks.kubeClient.CoreV1().Services("default").Get(context.TODO(), "podinfo-canary", metav1.GetOptions{}) require.NoError(t, err) + assert.Equal(t, &appProtocol, canarySvc.Spec.Ports[0].AppProtocol) assert.Equal(t, "http", canarySvc.Spec.Ports[0].Name) assert.Equal(t, int32(9898), canarySvc.Spec.Ports[0].Port) diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index e077e0089..999cec29b 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -100,6 +100,7 @@ func newTestCanary() *flaggerv1.Canary { Service: flaggerv1.CanaryService{ Port: 9898, PortDiscovery: true, + AppProtocol: "http", Headers: &istiov1alpha3.Headers{ Request: &istiov1alpha3.HeaderOperations{ Add: map[string]string{