Commit bb0dd0be authored by Shinya Maeda's avatar Shinya Maeda
Browse files

feat: Canary Ingress

This commit introduces the Canary Ingress in the Auto Deploy
architecture in order for advanced traffic routing.

BREAKING CHANGE: Due to the resource rearchitecturing,
charts older than v2.0 are not compatible.
parent 22f10278
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ test-get-replicas:
    GIT_STRATEGY: none
    CI_ENVIRONMENT_SLUG: production
  script:
    - replicas=$(auto-deploy get_replicas "stable" "100")
    - replicas=$(auto-deploy get_replicas "stable")
    - |
      if [[ $replicas != 1 ]]; then
        echo "$replicas should equal 1"
@@ -147,24 +147,24 @@ test-get-replicas-multiple:
    CI_ENVIRONMENT_SLUG: production
    REPLICAS: "2"
  script:
    - replicas=$(auto-deploy get_replicas "stable" "100")
    - replicas=$(auto-deploy get_replicas "stable")
    - |
      if [[ $replicas != 2 ]]; then
        echo "$replicas should equal 2"
        exit 1
      fi

test-get-replicas-fraction:
test-get-replicas-canary:
  <<: *test-job
  variables:
    GIT_STRATEGY: none
    CI_ENVIRONMENT_SLUG: production
    REPLICAS: "2"
  script:
    - replicas=$(auto-deploy get_replicas "stable" "25")
    - replicas=$(auto-deploy get_replicas "canary")
    - |
      if [[ $replicas != 1 ]]; then
        echo "$replicas should 1, (25% of 2 is 0.5, so set a floor of 1)"
      if [[ $replicas != 2 ]]; then
        echo "$replicas should equal 2 for canary"
        exit 1
      fi

@@ -175,7 +175,7 @@ test-get-replicas-zero:
    CI_ENVIRONMENT_SLUG: production
    REPLICAS: "0"
  script:
    - replicas=$(auto-deploy get_replicas "stable" "100")
    - replicas=$(auto-deploy get_replicas "stable")
    - |
      if [[ $replicas != 0 ]]; then
        echo "$replicas should equal 0, as requested"
+1 −1
Original line number Diff line number Diff line
apiVersion: v1
description: GitLab's Auto-deploy Helm Chart
name: auto-deploy-app
version: 2.0.0-beta.1
version: 2.0.0-beta.2
icon: https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png
+9 −2
Original line number Diff line number Diff line
{{- if and (.Values.service.enabled) (eq .Values.application.track "stable") (or (.Values.ingress.enabled) (not (hasKey .Values.ingress "enabled"))) -}}
{{- if and (.Values.service.enabled) (or (eq .Values.application.track "stable") (eq .Values.application.track "canary")) (or (.Values.ingress.enabled) (not (hasKey .Values.ingress "enabled"))) -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
@@ -12,6 +12,13 @@ metadata:
{{- if .Values.ingress.annotations }}
{{ toYaml .Values.ingress.annotations | indent 4 }}
{{- end }}
{{- if eq .Values.application.track "canary" }}
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-by-header: "canary"
{{- if .Values.ingress.canary.weight }}
    nginx.ingress.kubernetes.io/canary-weight: {{ .Values.ingress.canary.weight | quote }}
{{- end }}
{{- end }}
{{- with .Values.ingress.modSecurity }}
{{- if .enabled }}
    nginx.ingress.kubernetes.io/modsecurity-transaction-id: "$server_name-$request_id"
@@ -51,7 +58,7 @@ spec:
      paths:
      - path: /
        backend:
          serviceName: {{ template "fullname" . }}
          serviceName: {{ template "trackableappname" . }}
          servicePort: {{ .Values.service.externalPort }}
{{- if .Values.service.commonName }}
  - host: {{ template "hostname" .Values.service.commonName }}
+4 −2
Original line number Diff line number Diff line
{{- if and (.Values.service.enabled) (eq .Values.application.track "stable") -}}
{{- if and (.Values.service.enabled) (or (eq .Values.application.track "stable") (eq .Values.application.track "canary")) -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "fullname" . }}
  name: {{ template "trackableappname" . }}
  annotations:
{{- if .Values.service.annotations }}
{{ toYaml .Values.service.annotations | indent 4 }}
@@ -13,6 +13,7 @@ metadata:
{{- end }}
  labels:
    app: {{ template "appname" . }}
    track: "{{ .Values.application.track }}"
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
@@ -26,4 +27,5 @@ spec:
  selector:
    app: {{ template "appname" . }}
    tier: "{{ .Values.application.tier }}"
    track: "{{ .Values.application.track }}"
{{- end -}}
+7 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import (
)

const (
	chartName     = "auto-deploy-app-2.0.0-beta.1"
	chartName     = "auto-deploy-app-2.0.0-beta.2"
	helmChartPath = ".."
)

@@ -810,7 +810,7 @@ func TestServiceTemplate_Disable(t *testing.T) {
	}{
		{
			name:         "defaults",
			expectedName: releaseName + "-auto-deploy",
			expectedName: releaseName,
		},
		{
			name:                "with service enabled and track non-stable",
@@ -835,9 +835,12 @@ func TestServiceTemplate_Disable(t *testing.T) {
				SetValues: tc.values,
			}
			output, err := helm.RenderTemplateE(t, opts, helmChartPath, releaseName, templates)

			if tc.expectedErrorRegexp != nil {
				if err == nil {
					t.Error("Expected error but didn't happen")
				} else {
					require.Regexp(t, tc.expectedErrorRegexp, err.Error())
				}
				return
			}
			if err != nil {
Loading