From e3ecebc9ae467f99803309fe7c15f2e825722e89 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Sun, 26 Jan 2020 12:46:08 +0200 Subject: [PATCH] Add service name field to Canary CRD --- artifacts/flagger/crd.yaml | 3 +++ charts/flagger/templates/crd.yaml | 3 +++ kustomize/base/flagger/crd.yaml | 3 +++ pkg/apis/flagger/v1alpha3/types.go | 19 ++++++++++++++++--- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index c424fce2..8c802972 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -115,6 +115,9 @@ spec: type: object required: ["port"] properties: + name: + description: Kubernetes service name + type: string port: description: Container port number type: number diff --git a/charts/flagger/templates/crd.yaml b/charts/flagger/templates/crd.yaml index f276da00..ef5fed8b 100644 --- a/charts/flagger/templates/crd.yaml +++ b/charts/flagger/templates/crd.yaml @@ -116,6 +116,9 @@ spec: type: object required: ['port'] properties: + name: + description: Kubernetes service name + type: string port: description: Container port number type: number diff --git a/kustomize/base/flagger/crd.yaml b/kustomize/base/flagger/crd.yaml index c424fce2..8c802972 100644 --- a/kustomize/base/flagger/crd.yaml +++ b/kustomize/base/flagger/crd.yaml @@ -115,6 +115,9 @@ spec: type: object required: ["port"] properties: + name: + description: Kubernetes service name + type: string port: description: Container port number type: number diff --git a/pkg/apis/flagger/v1alpha3/types.go b/pkg/apis/flagger/v1alpha3/types.go index 0d9e3c56..74d5fabe 100644 --- a/pkg/apis/flagger/v1alpha3/types.go +++ b/pkg/apis/flagger/v1alpha3/types.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha3 import ( + "fmt" "time" hpav1 "k8s.io/api/autoscaling/v1" @@ -69,7 +70,7 @@ type CanarySpec struct { // virtual service spec Service CanaryService `json:"service"` - // metrics and thresholds + // metrics, thresholds and webhooks spec CanaryAnalysis CanaryAnalysis `json:"canaryAnalysis"` // the maximum time in seconds for a canary deployment to make progress @@ -92,8 +93,9 @@ type CanaryList struct { } // CanaryService is used to create ClusterIP services -// and Istio Virtual Service +// and service mesh or ingress routing objects type CanaryService struct { + Name string `json:"name,omitempty"` Port int32 `json:"port"` PortName string `json:"portName,omitempty"` TargetPort intstr.IntOrString `json:"targetPort,omitempty"` @@ -126,7 +128,7 @@ type CanaryAnalysis struct { Iterations int `json:"iterations,omitempty"` } -// CanaryMetric holds the reference to Istio metrics used for canary analysis +// CanaryMetric holds the reference to metrics used for canary analysis type CanaryMetric struct { Name string `json:"name"` Interval string `json:"interval,omitempty"` @@ -171,6 +173,17 @@ type CanaryWebhookPayload struct { Metadata map[string]string `json:"metadata,omitempty"` } +// GetServiceNames returns the apex, primary and canary Kubernetes service names +func (c *Canary) GetServiceNames() (apexName, primaryName, canaryName string) { + apexName = c.Spec.TargetRef.Name + if c.Spec.Service.Name != "" { + apexName = c.Spec.Service.Name + } + primaryName = fmt.Sprintf("%s-primary", apexName) + canaryName = fmt.Sprintf("%s-canary", apexName) + return +} + // GetProgressDeadlineSeconds returns the progress deadline (default 600s) func (c *Canary) GetProgressDeadlineSeconds() int { if c.Spec.ProgressDeadlineSeconds != nil {