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

Add external checks to canary analysis #18

Merged
merged 14 commits into from
Jan 4, 2019
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2018 Weaveworks. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ You can change the canary analysis _max weight_ and the _step weight_ percentage
For a deployment named _podinfo_, a canary promotion can be defined using Flagger's custom resource:

```yaml
apiVersion: flagger.app/v1alpha1
apiVersion: flagger.app/v1alpha2
kind: Canary
metadata:
name: podinfo
Expand All @@ -87,7 +87,7 @@ spec:
# the maximum time in seconds for the canary deployment
# to make progress before it is rollback (default 600s)
progressDeadlineSeconds: 60
# hpa reference (optional)
# HPA reference (optional)
autoscalerRef:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
Expand All @@ -100,16 +100,17 @@ spec:
- public-gateway.istio-system.svc.cluster.local
# Istio virtual service host names (optional)
hosts:
- app.istio.weavedx.com
- app.iowa.weavedx.com
canaryAnalysis:
# max number of failed metric checks before rollback
threshold: 5
threshold: 10
# max traffic percentage routed to canary
# percentage (0-100)
maxWeight: 50
# canary increment step
# percentage (0-100)
stepWeight: 10
stepWeight: 5
# Istio Prometheus checks
metrics:
- name: istio_requests_total
# minimum req success rate (non 5xx responses)
Expand All @@ -121,6 +122,14 @@ spec:
# milliseconds
threshold: 500
interval: 30s
# external checks (optional)
webhooks:
- name: integration-tests
url: http://podinfo.test:9898/echo
timeout: 1m
metadata:
test: "all"
token: "16688eb5e9f289f1991c"
```

The canary analysis is using the following promql queries:
Expand Down Expand Up @@ -166,6 +175,22 @@ histogram_quantile(0.99,
)
```

The canary analysis can be extended with webhooks.
Flagger would call a URL (HTTP POST) and determine from the response status code (HTTP 2xx) if the canary is failing or not.

Webhook payload:

```json
{
"name": "podinfo",
"namespace": "test",
"metadata": {
"test": "all",
"token": "16688eb5e9f289f1991c"
}
}
```

### Automated canary analysis, promotions and rollbacks

Create a test namespace with Istio sidecar injection enabled:
Expand Down
11 changes: 10 additions & 1 deletion artifacts/canaries/canary.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: flagger.app/v1alpha1
apiVersion: flagger.app/v1alpha2
kind: Canary
metadata:
name: podinfo
Expand Down Expand Up @@ -35,6 +35,7 @@ spec:
# canary increment step
# percentage (0-100)
stepWeight: 5
# Istio Prometheus checks
metrics:
- name: istio_requests_total
# minimum req success rate (non 5xx responses)
Expand All @@ -46,3 +47,11 @@ spec:
# milliseconds
threshold: 500
interval: 30s
# external checks (optional)
webhooks:
- name: integration-tests
url: http://podinfo.test:9898/echo
timeout: 1m
metadata:
test: "all"
token: "16688eb5e9f289f1991c"
29 changes: 27 additions & 2 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ metadata:
name: canaries.flagger.app
spec:
group: flagger.app
version: v1alpha1
version: v1alpha2
versions:
- name: v1alpha1
- name: v1alpha2
served: true
storage: true
- name: v1alpha1
served: true
storage: false
names:
plural: canaries
singular: canary
Expand All @@ -26,6 +29,8 @@ spec:
progressDeadlineSeconds:
type: number
targetRef:
type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
type: string
Expand All @@ -34,6 +39,8 @@ spec:
name:
type: string
autoscalerRef:
type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
type: string
Expand All @@ -42,6 +49,8 @@ spec:
name:
type: string
service:
type: object
required: ['port']
properties:
port:
type: number
Expand All @@ -58,6 +67,7 @@ spec:
properties:
items:
type: object
required: ['name', 'interval', 'threshold']
properties:
name:
type: string
Expand All @@ -66,3 +76,18 @@ spec:
pattern: "^[0-9]+(m)"
threshold:
type: number
webhooks:
type: array
properties:
items:
type: object
required: ['name', 'url', 'timeout']
properties:
name:
type: string
url:
type: string
format: url
timeout:
type: string
pattern: "^[0-9]+(s)"
2 changes: 1 addition & 1 deletion artifacts/flagger/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
serviceAccountName: flagger
containers:
- name: flagger
image: quay.io/stefanprodan/flagger:0.1.2
image: quay.io/stefanprodan/flagger:0.2.0-alpha.1
imagePullPolicy: Always
ports:
- name: http
Expand Down
2 changes: 1 addition & 1 deletion charts/flagger/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
name: flagger
version: 0.1.2
appVersion: 0.1.2
appVersion: 0.2.0-alpha.1
kubeVersion: ">=1.9.0-0"
engine: gotpl
description: Flagger is a Kubernetes operator that automates the promotion of canary deployments using Istio routing for traffic shifting and Prometheus metrics for canary analysis.
Expand Down
38 changes: 31 additions & 7 deletions charts/flagger/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: canaries.flagger.app
annotations:
"helm.sh/resource-policy": keep
spec:
group: flagger.app
version: v1alpha1
version: v1alpha2
versions:
- name: v1alpha1
- name: v1alpha2
served: true
storage: true
- name: v1alpha1
served: true
storage: false
names:
plural: canaries
singular: canary
Expand All @@ -22,13 +23,15 @@ spec:
properties:
spec:
required:
- targetRef
- service
- canaryAnalysis
- targetRef
- service
- canaryAnalysis
properties:
progressDeadlineSeconds:
type: number
targetRef:
type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
type: string
Expand All @@ -37,6 +40,8 @@ spec:
name:
type: string
autoscalerRef:
type: object
required: ['apiVersion', 'kind', 'name']
properties:
apiVersion:
type: string
Expand All @@ -45,6 +50,8 @@ spec:
name:
type: string
service:
type: object
required: ['port']
properties:
port:
type: number
Expand All @@ -61,6 +68,7 @@ spec:
properties:
items:
type: object
required: ['name', 'interval', 'threshold']
properties:
name:
type: string
Expand All @@ -69,4 +77,20 @@ spec:
pattern: "^[0-9]+(m)"
threshold:
type: number
webhooks:
type: array
properties:
items:
type: object
required: ['name', 'url', 'timeout']
properties:
name:
type: string
url:
type: string
format: url
timeout:
type: string
pattern: "^[0-9]+(s)"

{{- end }}
2 changes: 1 addition & 1 deletion charts/flagger/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

image:
repository: quay.io/stefanprodan/flagger
tag: 0.1.2
tag: 0.2.0-alpha.1
pullPolicy: IfNotPresent

controlLoopInterval: "10s"
Expand Down
2 changes: 1 addition & 1 deletion cmd/flagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {
}

flaggerInformerFactory := informers.NewSharedInformerFactory(flaggerClient, time.Second*30)
canaryInformer := flaggerInformerFactory.Flagger().V1alpha1().Canaries()
canaryInformer := flaggerInformerFactory.Flagger().V1alpha2().Canaries()

logger.Infof("Starting flagger version %s revision %s", version.VERSION, version.REVISION)

Expand Down
Loading