Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename spec.canaryAnalysis to spec.analysis #463

Merged
merged 7 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
name: Run go mod download
command: go mod download
- run:
name: Run go fmt
command: make test-fmt
name: Check code formatting
command: go install golang.org/x/tools/cmd/goimports && make test-fmt
- run:
name: Build Flagger
command: |
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ TAG?=latest
VERSION?=$(shell grep 'VERSION' pkg/version/version.go | awk '{ print $$4 }' | tr -d '"')
VERSION_MINOR:=$(shell grep 'VERSION' pkg/version/version.go | awk '{ print $$4 }' | tr -d '"' | rev | cut -d'.' -f2- | rev)
PATCH:=$(shell grep 'VERSION' pkg/version/version.go | awk '{ print $$4 }' | tr -d '"' | awk -F. '{print $$NF}')
SOURCE_DIRS = cmd pkg/apis pkg/controller pkg/server pkg/canary pkg/metrics pkg/router pkg/notifier
LT_VERSION?=$(shell grep 'VERSION' cmd/loadtester/main.go | awk '{ print $$4 }' | tr -d '"' | head -n1)
TS=$(shell date +%Y-%m-%d_%H-%M-%S)

Expand Down Expand Up @@ -43,10 +42,12 @@ push:
docker push weaveworks/flagger:$(VERSION)

fmt:
gofmt -l -s -w $(SOURCE_DIRS)
gofmt -l -s -w ./
goimports -l -w ./

test-fmt:
gofmt -l -s $(SOURCE_DIRS) | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi
gofmt -l -s ./ | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi
goimports -l ./ | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi

test-codegen:
./hack/verify-codegen.sh
Expand Down
17 changes: 10 additions & 7 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ spec:
priority: 1
- name: Interval
type: string
JSONPath: .spec.canaryAnalysis.interval
JSONPath: .spec.analysis.interval
priority: 1
- name: Mirror
type: boolean
JSONPath: .spec.canaryAnalysis.mirror
JSONPath: .spec.analysis.mirror
priority: 1
- name: StepWeight
type: string
JSONPath: .spec.canaryAnalysis.stepWeight
JSONPath: .spec.analysis.stepWeight
priority: 1
- name: MaxWeight
type: string
JSONPath: .spec.canaryAnalysis.maxWeight
JSONPath: .spec.analysis.maxWeight
priority: 1
- name: LastTransitionTime
type: string
Expand All @@ -66,7 +66,7 @@ spec:
required:
- targetRef
- service
- canaryAnalysis
- analysis
properties:
provider:
description: Traffic managent provider
Expand Down Expand Up @@ -502,9 +502,12 @@ spec:
skipAnalysis:
description: Skip analysis and promote canary
type: boolean
canaryAnalysis:
analysis:
description: Canary analysis for this canary
type: object
oneOf:
- required: ["interval", "threshold", "iterations"]
- required: ["interval", "threshold", "stepWeight"]
properties:
interval:
description: Schedule interval for this canary
Expand All @@ -523,7 +526,7 @@ spec:
description: Incremental traffic percentage step
type: number
mirror:
description: Mirror traffic to canary before shifting
description: Mirror traffic to canary
type: boolean
match:
description: A/B testing match conditions
Expand Down
17 changes: 10 additions & 7 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ spec:
priority: 1
- name: Interval
type: string
JSONPath: .spec.canaryAnalysis.interval
JSONPath: .spec.analysis.interval
priority: 1
- name: Mirror
type: boolean
JSONPath: .spec.canaryAnalysis.mirror
JSONPath: .spec.analysis.mirror
priority: 1
- name: StepWeight
type: string
JSONPath: .spec.canaryAnalysis.stepWeight
JSONPath: .spec.analysis.stepWeight
priority: 1
- name: MaxWeight
type: string
JSONPath: .spec.canaryAnalysis.maxWeight
JSONPath: .spec.analysis.maxWeight
priority: 1
- name: LastTransitionTime
type: string
Expand All @@ -66,7 +66,7 @@ spec:
required:
- targetRef
- service
- canaryAnalysis
- analysis
properties:
provider:
description: Traffic managent provider
Expand Down Expand Up @@ -502,9 +502,12 @@ spec:
skipAnalysis:
description: Skip analysis and promote canary
type: boolean
canaryAnalysis:
analysis:
description: Canary analysis for this canary
type: object
oneOf:
- required: ["interval", "threshold", "iterations"]
- required: ["interval", "threshold", "stepWeight"]
properties:
interval:
description: Schedule interval for this canary
Expand All @@ -523,7 +526,7 @@ spec:
description: Incremental traffic percentage step
type: number
mirror:
description: Mirror traffic to canary before shifting
description: Mirror traffic to canary
type: boolean
match:
description: A/B testing match conditions
Expand Down
5 changes: 3 additions & 2 deletions cmd/loadtester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"flag"
"log"
"time"

"github.com/weaveworks/flagger/pkg/loadtester"
"github.com/weaveworks/flagger/pkg/logger"
"github.com/weaveworks/flagger/pkg/signals"
"go.uber.org/zap"
"log"
"time"
)

var VERSION = "0.12.1"
Expand Down
17 changes: 10 additions & 7 deletions kustomize/base/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ spec:
priority: 1
- name: Interval
type: string
JSONPath: .spec.canaryAnalysis.interval
JSONPath: .spec.analysis.interval
priority: 1
- name: Mirror
type: boolean
JSONPath: .spec.canaryAnalysis.mirror
JSONPath: .spec.analysis.mirror
priority: 1
- name: StepWeight
type: string
JSONPath: .spec.canaryAnalysis.stepWeight
JSONPath: .spec.analysis.stepWeight
priority: 1
- name: MaxWeight
type: string
JSONPath: .spec.canaryAnalysis.maxWeight
JSONPath: .spec.analysis.maxWeight
priority: 1
- name: LastTransitionTime
type: string
Expand All @@ -66,7 +66,7 @@ spec:
required:
- targetRef
- service
- canaryAnalysis
- analysis
properties:
provider:
description: Traffic managent provider
Expand Down Expand Up @@ -502,9 +502,12 @@ spec:
skipAnalysis:
description: Skip analysis and promote canary
type: boolean
canaryAnalysis:
analysis:
description: Canary analysis for this canary
type: object
oneOf:
- required: ["interval", "threshold", "iterations"]
- required: ["interval", "threshold", "stepWeight"]
properties:
interval:
description: Schedule interval for this canary
Expand All @@ -523,7 +526,7 @@ spec:
description: Incremental traffic percentage step
type: number
mirror:
description: Mirror traffic to canary before shifting
description: Mirror traffic to canary
type: boolean
match:
description: A/B testing match conditions
Expand Down
37 changes: 33 additions & 4 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ type CanarySpec struct {
// Service defines how ClusterIP services, service mesh or ingress routing objects are generated
Service CanaryService `json:"service"`

// CanaryAnalysis defines how the analysis should be performed
CanaryAnalysis CanaryAnalysis `json:"canaryAnalysis"`
// Analysis defines the validation process of a release
Analysis *CanaryAnalysis `json:"analysis,omitempty"`

// Deprecated: replaced by Analysis
CanaryAnalysis *CanaryAnalysis `json:"canaryAnalysis,omitempty"`

// ProgressDeadlineSeconds represents the maximum time in seconds for a
// canary deployment to make progress before it is considered to be failed
Expand Down Expand Up @@ -352,13 +355,22 @@ func (c *Canary) GetProgressDeadlineSeconds() int {
return ProgressDeadlineSeconds
}

// GetAnalysis returns the analysis v1beta1 or v1alpha3
// to be removed along with spec.canaryAnalysis in v1
func (c *Canary) GetAnalysis() *CanaryAnalysis {
if c.Spec.Analysis != nil {
return c.Spec.Analysis
}
return c.Spec.CanaryAnalysis
}

// GetAnalysisInterval returns the canary analysis interval (default 60s)
func (c *Canary) GetAnalysisInterval() time.Duration {
if c.Spec.CanaryAnalysis.Interval == "" {
if c.GetAnalysis().Interval == "" {
return AnalysisInterval
}

interval, err := time.ParseDuration(c.Spec.CanaryAnalysis.Interval)
interval, err := time.ParseDuration(c.GetAnalysis().Interval)
if err != nil {
return AnalysisInterval
}
Expand All @@ -370,7 +382,24 @@ func (c *Canary) GetAnalysisInterval() time.Duration {
return interval
}

// GetAnalysisThreshold returns the canary threshold (default 1)
func (c *Canary) GetAnalysisThreshold() int {
if c.GetAnalysis().Threshold > 0 {
return c.GetAnalysis().Threshold
}
return 1
}

// GetMetricInterval returns the metric interval default value (1m)
func (c *Canary) GetMetricInterval() string {
return MetricInterval
}

// SkipAnalysis returns true if the analysis is nil
// or if spec.SkipAnalysis is true
func (c *Canary) SkipAnalysis() bool {
if c.Spec.Analysis == nil && c.Spec.CanaryAnalysis == nil {
return true
}
return c.Spec.SkipAnalysis
}
11 changes: 10 additions & 1 deletion pkg/apis/flagger/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/canary/daemonset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *DaemonSetController) Initialize(cd *flaggerv1.Canary, skipLivenessCheck
}

if cd.Status.Phase == "" || cd.Status.Phase == flaggerv1.CanaryPhaseInitializing {
if !skipLivenessChecks && !cd.Spec.SkipAnalysis {
if !skipLivenessChecks && !cd.SkipAnalysis() {
_, readyErr := c.IsPrimaryReady(cd)
if readyErr != nil {
return readyErr
Expand Down
2 changes: 1 addition & 1 deletion pkg/canary/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *DeploymentController) Initialize(cd *flaggerv1.Canary, skipLivenessChec
}

if cd.Status.Phase == "" || cd.Status.Phase == flaggerv1.CanaryPhaseInitializing {
if !skipLivenessChecks && !cd.Spec.SkipAnalysis {
if !skipLivenessChecks && !cd.SkipAnalysis() {
_, readyErr := c.IsPrimaryReady(cd)
if readyErr != nil {
return readyErr
Expand Down
2 changes: 1 addition & 1 deletion pkg/canary/deployment_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func newDeploymentControllerTestCanary() *flaggerv1.Canary {
Kind: "HorizontalPodAutoscaler",
}, Service: flaggerv1.CanaryService{
Port: 9898,
}, CanaryAnalysis: flaggerv1.CanaryAnalysis{
}, CanaryAnalysis: &flaggerv1.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,
MaxWeight: 50,
Expand Down
Loading