Skip to content

Commit

Permalink
feat: Added the optional appProtocol field to Canary.Service
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Nichol <35630607+philnichol@users.noreply.github.com>
  • Loading branch information
philnichol committed May 15, 2022
1 parent a1e519b commit 6cd8ddd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
4 changes: 4 additions & 0 deletions pkg/router/kubernetes_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions pkg/router/kubernetes_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6cd8ddd

Please sign in to comment.