Skip to content

Commit

Permalink
Add extendeddaemonset-check helper (#53)
Browse files Browse the repository at this point in the history
* Add extendeddaemonset-check helper
* add new cmd binary: `check-eds`
* add new `app-example` chart
* update ci to deliver the `datadog/extendeddaemonset-check` container image
  • Loading branch information
clamoriniere committed Oct 26, 2020
1 parent b98cd7a commit 1b59ab0
Show file tree
Hide file tree
Showing 21 changed files with 639 additions and 24 deletions.
50 changes: 33 additions & 17 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ image: golang:1.13
variables:
GO111MODULE: "on"
PROJECTNAME: "extendeddaemonset"
PROJECTNAME_CHECK: "extendeddaemonset-check"
GOPATH: "$CI_PROJECT_DIR/.cache"
TARGET_TAG: v$CI_PIPELINE_ID-$CI_COMMIT_SHORT_SHA
DOCKER_REGISTRY: "486234852809.dkr.ecr.us-east-1.amazonaws.com/ci"
Expand Down Expand Up @@ -40,33 +41,33 @@ generate_code:
- make generate manifests
- git diff --exit-code

build_image:
build_images:
stage: image
tags: [ "runner:docker", "size:large" ]
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker-notary:0.6.1
before_script: []
script:
- IMG=$DOCKER_REGISTRY/$PROJECTNAME:$TARGET_TAG make docker-build-ci docker-push
- IMG=$DOCKER_REGISTRY/$PROJECTNAME:$TARGET_TAG make docker-build-ci docker-push-ci
- IMG_CHECK=$DOCKER_REGISTRY/$PROJECTNAME_CHECK:$TARGET_TAG make docker-build-check-ci docker-push-check-ci

push_release_tag:
only:
- tags
stage: release
tags: [ "runner:docker", "size:large" ]
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker-notary:0.6.1
before_script: []
script:
- IMAGE_NAME=$DOCKER_REGISTRY/$PROJECTNAME:$TARGET_TAG
- RELEASE_IMAGE_NAME=$DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG
- docker pull $IMAGE_NAME
- docker tag $IMAGE_NAME $RELEASE_IMAGE_NAME
- docker push $RELEASE_IMAGE_NAME
push_release_tag_controller:
extends: .push_release_tag
variables:
IMAGE_NAME: $DOCKER_REGISTRY/$PROJECTNAME:$TARGET_TAG
RELEASE_IMAGE_NAME: $DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG

.docker_env_tag_check:
extends: .push_release_tag
variables:
IMAGE_NAME: $DOCKER_REGISTRY/$PROJECTNAME_CHECK:$TARGET_TAG
RELEASE_IMAGE_NAME: $DOCKER_REGISTRY/$PROJECTNAME_CHECK:$CI_COMMIT_TAG

.docker_hub_variables: &docker_hub_variables
DOCKER_REGISTRY_LOGIN_SSM_KEY: docker_hub_login
DOCKER_REGISTRY_PWD_SSM_KEY: docker_hub_pwd
DOCKER_REGISTRY_URL: docker.io
DOCKERHUB_REPO: extendeddaemonset
DOCKERHUB_REPO_CHECK: extendeddaemonset-check
DOCKERHUB_ORG: datadog

push_tag_to_docker_hub:
Expand All @@ -82,7 +83,8 @@ push_tag_to_docker_hub:
script:
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin $DOCKER_REGISTRY_URL
- IMG=$DOCKERHUB_ORG/$DOCKERHUB_REPO:${CI_COMMIT_TAG:1} make docker-build-ci docker-push
- IMG=$DOCKERHUB_ORG/$DOCKERHUB_REPO:${CI_COMMIT_TAG:1} make docker-build-ci docker-push-ci
- IMG_CHECK=$DOCKERHUB_ORG/$DOCKERHUB_REPO_CHECK:${CI_COMMIT_TAG:1} make docker-build-check-ci docker-push-check-ci

push_latest_to_docker_hub:
only:
Expand All @@ -97,4 +99,18 @@ push_latest_to_docker_hub:
script:
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin $DOCKER_REGISTRY_URL
- IMG=$DOCKERHUB_ORG/$DOCKERHUB_REPO:latest make docker-build-ci docker-push
- IMG=$DOCKERHUB_ORG/$DOCKERHUB_REPO:latest make docker-build-ci docker-push-ci
- IMG_CHECK=$DOCKERHUB_ORG/$DOCKERHUB_REPO_CHECK:latest make docker-build-check-ci docker-push-check-ci


.push_release_tag:
only:
- tags
stage: release
tags: [ "runner:docker", "size:large" ]
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker-notary:0.6.1
before_script: []
script:
- docker pull $IMAGE_NAME
- docker tag $IMAGE_NAME $RELEASE_IMAGE_NAME
- docker push $RELEASE_IMAGE_NAME
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Image URL to use all building/pushing image targets
IMG ?= datadog/extendeddaemonset:latest
IMG_CHECK ?= datadog/extendeddaemonset-check:latest

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -81,15 +82,23 @@ generate: controller-gen generate-openapi
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# Build the docker image
docker-build: generate docker-build-ci
docker-build: generate docker-build-ci docker-build-check-ci

docker-build-ci:
docker build . -t ${IMG} --build-arg LDFLAGS="${LDFLAGS}"

# Push the docker image
docker-push:
docker-build-check-ci:
docker build . -t ${IMG_CHECK} -f check-eds.Dockerfile --build-arg LDFLAGS="${LDFLAGS}"

# Push the docker images
docker-push: docker-push-ci docker-push-check-ci

docker-push-ci:
docker push ${IMG}

docker-push-check-ci:
docker push ${IMG_CHECK}

# find or download controller-gen
# download controller-gen if necessary
controller-gen: install-tools
Expand Down Expand Up @@ -172,6 +181,9 @@ vendor:
kubectl-eds: fmt vet lint
go build -ldflags '${LDFLAGS}' -o bin/kubectl-eds ./cmd/kubectl-eds/main.go

check-eds: fmt vet lint
go build -ldflags '${LDFLAGS}' -o bin/check-eds ./cmd/check-eds/main.go

bin/kubebuilder:
./hack/install-kubebuilder.sh 2.3.1

Expand Down
23 changes: 23 additions & 0 deletions chart/app-example/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions chart/app-example/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: app-example
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0
44 changes: 44 additions & 0 deletions chart/app-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# APP Example

## Introduction

This chart allows you to deploy a "dummy" application that uses the ExtendedDaemonset.

Thanks to this chart you can test several ExtendedDaemonset features, such as:

* The Canary deployment strategy
* The `extendeddaemonset-check` util pod with the `helm test` command.
* The possibility to override a `Pod` resources for a specific `Node` thanks to an
`ExtendedDaemonsetSettings` resource.

## Deployment

Before deploying this chart, you should have deployed the `ExtendedDaemonset` Controller with the following command: `helm install eds-controller ./chart/extendeddaemonset`.

Now you can deploy the `app-example` with default values this: `helm install foo ./chart/app-example`.

### Canary deployment

### Check if a canary deployment finished

Helm3 introduces the `helm test` command, which can be used to validate a "complex" deployment, was looking only
at the state if the pod is not enough. It is also useful when the chart contains CRDs because Helm is not aware
of how to understand the status of a CRD.

This chart contains a test "Pod" (manifests present in `app-example/templates/tests`) that can check if a
Extendedaemonset update is finished.

To simulate an update, the following command will update the docker image tag for the "foo" application:
`helm upgrade foo ./chart/app-example --set image.tag=stable`.

The `ExtendedDaemonset` status should have been moved to `canary`

```console
$ kubectl get eds
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE IGNORED UNRESPONSIVE NODES STATUS REASON ACTIVE RS CANARY RS AGE
foo-app-example 3 3 3 3 3 Canary foo-app-example-db2sk foo-app-example-76kz8 1h
```

With the default configuration, the Canary deployment is set to 3min. During this period only one pod has been updated.

The command `helm test foo` starts a Pod with a specific container that checks the `ExtendedDaemonset` status. The command returns when the canary deployment and the rolling-up are finished.
Empty file.
62 changes: 62 additions & 0 deletions chart/app-example/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "app-example.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "app-example.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "app-example.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "app-example.labels" -}}
helm.sh/chart: {{ include "app-example.chart" . }}
{{ include "app-example.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "app-example.selectorLabels" -}}
app.kubernetes.io/name: {{ include "app-example.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "app-example.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "app-example.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
30 changes: 30 additions & 0 deletions chart/app-example/templates/extendeddaemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: datadoghq.com/v1alpha1
kind: ExtendedDaemonSet
metadata:
name: {{ include "app-example.fullname" . }}
labels:
{{- include "app-example.labels" . | nindent 4 }}
spec:
strategy:
{{- toYaml .Values.strategy | nindent 4 }}
template:
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "app-example.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 6 }}
{{- end }}
12 changes: 12 additions & 0 deletions chart/app-example/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "app-example.serviceAccountName" . }}
labels:
{{- include "app-example.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
34 changes: 34 additions & 0 deletions chart/app-example/templates/tests/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: "{{ include "app-example.fullname" . }}-test"
labels:
{{- include "app-example.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
rules:
- apiGroups:
- datadoghq.com
resources:
- 'extendeddaemonsets'
- 'extendeddaemonsets/status'
verbs:
- 'get'
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: "{{ include "app-example.fullname" . }}-test"
labels:
{{- include "app-example.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
subjects:
- kind: ServiceAccount
name: "{{ include "app-example.serviceAccountName" . }}-test"
roleRef:
kind: Role
name: "{{ include "app-example.fullname" . }}-test"
apiGroup: rbac.authorization.k8s.io
{{- end -}}
12 changes: 12 additions & 0 deletions chart/app-example/templates/tests/service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "app-example.serviceAccountName" . }}-test
labels:
{{- include "app-example.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 1b59ab0

Please sign in to comment.