From f5b97fbb7425121bd44064c39805920f74b973d3 Mon Sep 17 00:00:00 2001 From: Trond Nordheim Date: Thu, 21 Mar 2019 12:37:02 +0100 Subject: [PATCH] Add support for naming generated service ports --- pkg/apis/flagger/v1alpha3/types.go | 4 +++- pkg/router/kubernetes.go | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/apis/flagger/v1alpha3/types.go b/pkg/apis/flagger/v1alpha3/types.go index d0650524..92bc5516 100755 --- a/pkg/apis/flagger/v1alpha3/types.go +++ b/pkg/apis/flagger/v1alpha3/types.go @@ -17,10 +17,11 @@ limitations under the License. package v1alpha3 import ( + "time" + istiov1alpha3 "github.com/weaveworks/flagger/pkg/apis/istio/v1alpha3" hpav1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "time" ) const ( @@ -111,6 +112,7 @@ type CanaryStatus struct { // and Istio Virtual Service type CanaryService struct { Port int32 `json:"port"` + PortName string `json:"portName,omitempty"` Match []istiov1alpha3.HTTPMatchRequest `json:"match,omitempty"` Rewrite *istiov1alpha3.HTTPRewrite `json:"rewrite,omitempty"` Timeout string `json:"timeout,omitempty"` diff --git a/pkg/router/kubernetes.go b/pkg/router/kubernetes.go index f42819d6..f0158513 100644 --- a/pkg/router/kubernetes.go +++ b/pkg/router/kubernetes.go @@ -2,6 +2,7 @@ package router import ( "fmt" + flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" clientset "github.com/weaveworks/flagger/pkg/client/clientset/versioned" "go.uber.org/zap" @@ -24,6 +25,11 @@ type KubernetesRouter struct { func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { targetName := cd.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-primary", targetName) + portName := cd.Spec.Service.PortName + if portName == "" { + portName = "http" + } + canaryService, err := c.kubeClient.CoreV1().Services(cd.Namespace).Get(targetName, metav1.GetOptions{}) if errors.IsNotFound(err) { canaryService = &corev1.Service{ @@ -43,7 +49,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { Selector: map[string]string{"app": primaryName}, Ports: []corev1.ServicePort{ { - Name: "http", + Name: portName, Protocol: corev1.ProtocolTCP, Port: cd.Spec.Service.Port, TargetPort: intstr.IntOrString{ @@ -82,7 +88,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { Selector: map[string]string{"app": targetName}, Ports: []corev1.ServicePort{ { - Name: "http", + Name: portName, Protocol: corev1.ProtocolTCP, Port: cd.Spec.Service.Port, TargetPort: intstr.IntOrString{ @@ -120,7 +126,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { Selector: map[string]string{"app": primaryName}, Ports: []corev1.ServicePort{ { - Name: "http", + Name: portName, Protocol: corev1.ProtocolTCP, Port: cd.Spec.Service.Port, TargetPort: intstr.IntOrString{