From 9ed182b88a532cf3157208de54553bfa32805a08 Mon Sep 17 00:00:00 2001 From: rimas Date: Mon, 26 Feb 2018 13:32:51 +0000 Subject: [PATCH] refactor chart to latest best practices --- chart/keel/Chart.yaml | 8 ++-- chart/keel/README.md | 20 +++------- chart/keel/templates/NOTES.txt | 14 +++---- chart/keel/templates/_helpers.tpl | 20 +++++++++- chart/keel/templates/clusterrole.yaml | 2 +- chart/keel/templates/clusterrolebinding.yaml | 6 +-- chart/keel/templates/deployment.yaml | 39 +++++++++++++------ chart/keel/templates/secrets-google.yaml | 12 +++--- .../keel/templates/secrets-webhookrelay.yaml | 10 ++--- chart/keel/templates/service-account.yaml | 10 ++--- chart/keel/templates/service.yaml | 8 ++-- chart/keel/values.yaml | 24 ++++++------ 12 files changed, 99 insertions(+), 74 deletions(-) diff --git a/chart/keel/Chart.yaml b/chart/keel/Chart.yaml index 82a8762d..c025de95 100644 --- a/chart/keel/Chart.yaml +++ b/chart/keel/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 name: keel description: Open source, tool for automating Kubernetes deployment updates. Keel is stateless, robust and lightweight. -version: 0.1.2 -appversion: 0.5.2 +version: 0.1.4 +appversion: 0.6.1 keywords: - kubernetes deployment - helm release @@ -11,8 +11,8 @@ home: https://keel.sh sources: - https://github.com/keel-hq/keel maintainers: -- name: Rimas Mocevicius +- name: rimusz email: rmocius@gmail.com -- name: Karolis Rusenas +- name: rusenask email: karolis.rusenas@gmail.com engine: gotpl diff --git a/chart/keel/README.md b/chart/keel/README.md index 0d753abe..a7e666d7 100644 --- a/chart/keel/README.md +++ b/chart/keel/README.md @@ -24,20 +24,12 @@ Keel provides several key features: **Note**: For now Keel gets installed into `kube-system` _namespace_ by default as where Helm's `Tiller` is installed. -## Installing the Chart with Kubernetes provider support +## Installing -Docker image _polling_ and _Kubernetes_ provider are set by default, then Kubernetes _deployments_ can be upgraded when new Docker image is available: +Docker image _polling_, _Kubernetes provider_ and _Helm provider_ support are set by default, then Kubernetes _deployments_ can be upgraded when new Docker image is available: ```console -helm upgrade --install keel keel" -``` - -## Installing the Chart with Helm provider support - -Docker image _polling_ is set by default, but we need to enable _Helm provider_ support, then Helm _releases_ can be upgraded when new Docker image is available: - -```console -helm upgrade --install keel keel --set helmProvider.enabled="true" +helm upgrade --install keel keel/ ``` ### Setting up Helm release to be automatically updated by Keel @@ -78,7 +70,7 @@ idea how to set automatic updates. To uninstall/delete the `keel` deployment: ```console -$ helm delete keel +$ helm delete --purge keel ``` The command removes all the Kubernetes components associated with the chart and deletes the release. @@ -90,7 +82,7 @@ The following table lists has the main configurable parameters (polling, trigger | Parameter | Description | Default | | --------------------------------- | -------------------------------------- | --------------------------------------------------------- | | `polling.enabled` | Docker registries polling | `true` | -| `helmProvider.enabled` | Enable/disable Helm provider | `false` | +| `helmProvider.enabled` | Enable/disable Helm provider | `true` | | `gcr.enabled` | Enable/disable GCR Registry | `false` | | `gcr.projectID` | GCP Project ID GCR belongs to | | | `gcr.pubsub.enabled` | Enable/disable GCP Pub/Sub trigger | `false` | @@ -120,6 +112,6 @@ Specify each parameter using the `--set key=value[,key=value]` argument to `helm Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, ```console -$ helm install --name keel -f values.yaml keel +$ helm install --name keel -f values.yaml keel/ ``` > **Tip**: You can use the default [values.yaml](values.yaml) diff --git a/chart/keel/templates/NOTES.txt b/chart/keel/templates/NOTES.txt index a67cb0b3..5eec1c2c 100644 --- a/chart/keel/templates/NOTES.txt +++ b/chart/keel/templates/NOTES.txt @@ -1,8 +1,8 @@ -1. The {{ template "name" .}} is getting provisioned in your cluster. After a few minutes, you can run the following to verify. +1. The {{ template "keel.name" . }} is getting provisioned in your cluster. After a few minutes, you can run the following to verify. -To verify that {{ template "name" . }} has started, run: +To verify that {{ template "keel.name" . }} has started, run: - kubectl --namespace=kube-system get pods -l "app={{ template "name" . }}" + kubectl --namespace=kube-system get pods -l "app={{ template "keel.name" . }}" {{- if .Values.service.enabled }} @@ -11,20 +11,20 @@ To verify that {{ template "name" . }} has started, run: {{- if contains "LoadBalancer" .Values.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. - Watch the status with: 'kubectl get svc --namespace kube-system -w {{ template "name" . }}' + Watch the status with: 'kubectl get svc --namespace kube-system -w {{ template "keel.name" . }}' - export SERVICE_IP=$(kubectl get svc --namespace kube-system {{ template "name" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + export SERVICE_IP=$(kubectl get svc --namespace kube-system {{ template "keel.name" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') echo http://$SERVICE_IP:{{ .Values.service.externalPort }} {{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace kube-system -l "app={{ template "name" . }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace kube-system -l "app={{ template "keel.name" . }}" -o jsonpath="{.items[0].metadata.name}") echo http://127.0.0.1:{{ .Values.service.externalPort }} kubectl port-forward --namespace kube-system $POD_NAME {{ .Values.service.externalPort }}:{{ .Values.service.externalPort }} {{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace kube-system -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "name" . }}) + export NODE_PORT=$(kubectl get --namespace kube-system -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "keel.name" . }}) export NODE_IP=$(kubectl get nodes --namespace kube-system -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT/ diff --git a/chart/keel/templates/_helpers.tpl b/chart/keel/templates/_helpers.tpl index f0d83d2e..06f9476d 100644 --- a/chart/keel/templates/_helpers.tpl +++ b/chart/keel/templates/_helpers.tpl @@ -2,15 +2,31 @@ {{/* Expand the name of the chart. */}} -{{- define "name" -}} +{{- define "keel.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 "fullname" -}} +{{- define "keel.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 "keel.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/chart/keel/templates/clusterrole.yaml b/chart/keel/templates/clusterrole.yaml index 6c94c30a..d9b54fd2 100644 --- a/chart/keel/templates/clusterrole.yaml +++ b/chart/keel/templates/clusterrole.yaml @@ -2,7 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: {{ template "name" . }} + name: {{ template "keel.name" . }} rules: - apiGroups: - "" diff --git a/chart/keel/templates/clusterrolebinding.yaml b/chart/keel/templates/clusterrolebinding.yaml index 1c3f60d0..523cb7e1 100644 --- a/chart/keel/templates/clusterrolebinding.yaml +++ b/chart/keel/templates/clusterrolebinding.yaml @@ -2,13 +2,13 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: {{ template "name" . }} + name: {{ template "keel.name" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: {{ template "name" . }} + name: {{ template "keel.name" . }} subjects: - kind: ServiceAccount - name: {{ template "name" . }} + name: {{ template "keel.name" . }} namespace: kube-system {{ end }} diff --git a/chart/keel/templates/deployment.yaml b/chart/keel/templates/deployment.yaml index 0109ff50..1a1585ed 100644 --- a/chart/keel/templates/deployment.yaml +++ b/chart/keel/templates/deployment.yaml @@ -1,30 +1,37 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1beta2 kind: Deployment metadata: - name: {{ template "name" . }} + name: {{ template "keel.fullname" . }} namespace: kube-system labels: - app: {{ template "name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app: {{ template "keel.name" . }} + chart: {{ template "keel.chart" . }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} spec: replicas: 1 + selector: + matchLabels: + app: {{ template "keel.name" . }} + release: {{ .Release.Name }} template: metadata: labels: - app: {{ template "name" . }} + app: {{ template "keel.name" . }} + release: {{ .Release.Name }} spec: - serviceAccountName: {{ template "name" . }} + serviceAccountName: {{ template "keel.name" . }} containers: - name: keel image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} command: ["/bin/keel"] +{{- if .Values.googleApplicationCredentials }} volumeMounts: - name: google mountPath: "/google" readOnly: true +{{- end }} env: {{- if .Values.googleApplicationCredentials }} - name: GOOGLE_APPLICATION_CREDENTIALS @@ -103,23 +110,33 @@ spec: - name: KEY valueFrom: secretKeyRef: - name: {{ template "name" . }}-webhookrelay + name: {{ template "keel.name" . }}-webhookrelay key: key - name: SECRET valueFrom: secretKeyRef: - name: {{ template "name" . }}-webhookrelay + name: {{ template "keel.name" . }}-webhookrelay key: secret - name: BUCKET value: "{{ .Values.webhookRelay.bucket }}" resources: {{ toYaml .Values.resources | indent 12 }} {{- end }} + {{- with .Values.nodeSelector }} nodeSelector: -{{ toYaml .Values.nodeSelector | indent 8 }} +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} {{- if .Values.googleApplicationCredentials }} volumes: - name: google secret: - secretName: {{ template "name" . }}-google -{{- end }} \ No newline at end of file + secretName: {{ template "keel.name" . }}-google +{{- end }} diff --git a/chart/keel/templates/secrets-google.yaml b/chart/keel/templates/secrets-google.yaml index 0b651028..95e279e6 100644 --- a/chart/keel/templates/secrets-google.yaml +++ b/chart/keel/templates/secrets-google.yaml @@ -2,14 +2,14 @@ apiVersion: v1 kind: Secret metadata: - name: {{ template "name" . }}-google + name: {{ template "keel.name" . }}-google namespace: kube-system labels: - app: {{ template "name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: {{ template "keel.name" . }} + chart: {{ template "keel.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} type: Opaque data: google-application-credentials.json: {{ .Values.googleApplicationCredentials | b64enc | quote }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/chart/keel/templates/secrets-webhookrelay.yaml b/chart/keel/templates/secrets-webhookrelay.yaml index b1d6096a..bda6fb66 100644 --- a/chart/keel/templates/secrets-webhookrelay.yaml +++ b/chart/keel/templates/secrets-webhookrelay.yaml @@ -2,13 +2,13 @@ apiVersion: v1 kind: Secret metadata: - name: {{ template "name" . }}-webhookrelay + name: {{ template "keel.name" . }}-webhookrelay namespace: kube-system labels: - app: {{ template "name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: {{ template "keel.name" . }} + chart: {{ template "keel.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} type: Opaque data: key: {{ .Values.webhookRelay.key | b64enc }} diff --git a/chart/keel/templates/service-account.yaml b/chart/keel/templates/service-account.yaml index db37393f..106eb70f 100644 --- a/chart/keel/templates/service-account.yaml +++ b/chart/keel/templates/service-account.yaml @@ -1,10 +1,10 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ template "name" . }} + name: {{ template "keel.name" . }} namespace: kube-system labels: - app: {{ template "name" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: {{ template "keel.name" . }} + chart: {{ template "keel.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} diff --git a/chart/keel/templates/service.yaml b/chart/keel/templates/service.yaml index 46bfd9bd..abb00917 100644 --- a/chart/keel/templates/service.yaml +++ b/chart/keel/templates/service.yaml @@ -2,11 +2,11 @@ apiVersion: v1 kind: Service metadata: - name: {{ template "name" . }} + name: {{ template "keel.name" . }} namespace: kube-system labels: - app: {{ template "name" . }} - chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app: {{ template "keel.name" . }} + chart: {{ template "keel.chart" . }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} spec: @@ -17,6 +17,6 @@ spec: protocol: TCP name: keel selector: - app: {{ template "name" . }} + app: {{ template "keel.name" . }} sessionAffinity: None {{- end }} diff --git a/chart/keel/values.yaml b/chart/keel/values.yaml index b6eee178..66b89cbd 100644 --- a/chart/keel/values.yaml +++ b/chart/keel/values.yaml @@ -4,7 +4,7 @@ image: repository: keelhq/keel - tag: 0.5.2 + tag: 0.6.1 pullPolicy: IfNotPresent # Polling is enabled by default, @@ -14,7 +14,7 @@ polling: # Helm provider support helmProvider: - enabled: false + enabled: true # Google Container Registry # GCP Project ID @@ -107,14 +107,14 @@ nodeSelector: {} # json of service account # googleApplicationCredentials: |- # { -# "type": +# "type": # "project_id" -# "private_key_id": -# "private_key": -# "client_email": -# "client_id": -# "auth_uri": -# "token_uri": -# "auth_provider_x509_cert_url": -# "client_x509_cert_url": -# } \ No newline at end of file +# "private_key_id": +# "private_key": +# "client_email": +# "client_id": +# "auth_uri": +# "token_uri": +# "auth_provider_x509_cert_url": +# "client_x509_cert_url": +# }