From f7e8e8226fe416a0697384a4cca7726167d7af74 Mon Sep 17 00:00:00 2001 From: oleksandr k Date: Thu, 12 Mar 2020 18:33:09 +0000 Subject: [PATCH] helm and playbook Change-Id: Ia640c46d97ced49674ae475b86a833f34f3503ee downgrade helm version and do playbook Change-Id: Id451effe1286742e5e17e1a85c3627f6429905ac paste post and get Change-Id: I7ad6f974a4dc9eb7a9c002efb13f776dab852c46 --- .zuul.yaml | 18 +++++++++ chart/.helmignore | 22 +++++++++++ chart/Chart.yaml | 5 +++ chart/templates/_helpers.tpl | 60 ++++++++++++++++++++++++++++++ chart/templates/deployment.yaml | 65 +++++++++++++++++++++++++++++++++ chart/templates/ingress.yaml | 37 +++++++++++++++++++ chart/templates/secrets.yaml | 21 +++++++++++ chart/templates/service.yaml | 24 ++++++++++++ chart/values.yaml | 62 +++++++++++++++++++++++++++++++ location.txt | 1 + playbooks/functional/run.yaml | 33 +++++++++++++++++ 11 files changed, 348 insertions(+) create mode 100644 .zuul.yaml create mode 100644 chart/.helmignore create mode 100644 chart/Chart.yaml create mode 100644 chart/templates/_helpers.tpl create mode 100644 chart/templates/deployment.yaml create mode 100644 chart/templates/ingress.yaml create mode 100644 chart/templates/secrets.yaml create mode 100644 chart/templates/service.yaml create mode 100644 chart/values.yaml create mode 100644 location.txt create mode 100644 playbooks/functional/run.yaml diff --git a/.zuul.yaml b/.zuul.yaml new file mode 100644 index 0000000..986dd25 --- /dev/null +++ b/.zuul.yaml @@ -0,0 +1,18 @@ +- job: + name: lodgeit-helm-functional + parent: apply-helm-charts + run: playbooks/functional/run.yaml + vars: + minikube_dns_resolvers: ['1.1.1.1', '8.8.8.8'] + helm_charts: + nodepool: ./charts/nodepool + +- project: + check: + jobs: + - chart-testing-lint + - lodgeit-helm-functional + gate: + jobs: + - chart-testing-lint + - lodgeit-helm-functional diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/chart/.helmignore @@ -0,0 +1,22 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..14fc2f4 --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +name: lodgeit +description: Helm charts for deploying Lodgeit +version: 0.0.0 +appVersion: 0.0.1 diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 0000000..b0331a1 --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,60 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "lodgeit.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 "lodgeit.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 -}} + +{{/* +Generate chart secret name +*/}} +{{- define "lodgeit.secretName" -}} +{{ default (include "lodgeit.fullname" .) .Values.existingSecret }} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "lodgeit.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "lodgeit.labels" -}} +helm.sh/chart: {{ include "lodgeit.chart" . }} +{{ include "lodgeit.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "lodgeit.selectorLabels" -}} +app.kubernetes.io/name: {{ include "lodgeit.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 0000000..215db6e --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,65 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "lodgeit.fullname" . }} + labels: + {{- include "lodgeit.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "lodgeit.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "lodgeit.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.version }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: LODGEIT_DBURI + valueFrom: + secretKeyRef: + name: {{ template "lodgeit.secretName" . }} + key: db-uri + - name: LODGEIT_SECRET_KEY + valueFrom: + secretKeyRef: + name: {{ template "lodgeit.secretName" . }} + key: secret-key + ports: + - name: http + containerPort: 9000 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/chart/templates/ingress.yaml b/chart/templates/ingress.yaml new file mode 100644 index 0000000..529b38b --- /dev/null +++ b/chart/templates/ingress.yaml @@ -0,0 +1,37 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "lodgeit.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "lodgeit.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/chart/templates/secrets.yaml b/chart/templates/secrets.yaml new file mode 100644 index 0000000..255552f --- /dev/null +++ b/chart/templates/secrets.yaml @@ -0,0 +1,21 @@ +{{- if not .Values.existingSecret }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "lodgeit.fullname" . }} + labels: + {{- include "lodgeit.labels" . | nindent 4 }} +type: Opaque +data: + {{ if .Values.dbUri }} + db-uri: {{ .Values.dbUri | b64enc | quote }} + {{ else }} + db-uri: {{ randAlphaNum 10 | b64enc | quote }} + {{ end }} + + {{ if .Values.secretKey }} + secret-key: {{ .Values.secretKey | b64enc | quote }} + {{ else }} + secret-key: {{ randAlphaNum 10 | b64enc | quote }} + {{ end }} +{{- end }} diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000..0f9d7f4 --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,24 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "lodgeit.fullname" . }} + labels: + {{- include "lodgeit.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http +{{ if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }} + nodePort: {{.Values.service.nodePort}} +{{ end }} + +{{- if .Values.service.externalIPs }} + externalIPs: +{{ toYaml .Values.service.externalIPs | indent 4 }} +{{- end }} + + selector: + {{- include "lodgeit.selectorLabels" . | nindent 4 }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..9c0c949 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,62 @@ +replicaCount: 1 + +image: + repository: opendevorg/lodgeit + version: latest + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +dbUri: "sqlite:////tmp/lodgeit.db" +secretKey: "password" +#existingSecret: + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: +# type: ClusterIP + port: 80 + type: NodePort + nodePort: 30009 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/location.txt b/location.txt new file mode 100644 index 0000000..e979707 --- /dev/null +++ b/location.txt @@ -0,0 +1 @@ +< Location: http://paste.openstack.org/show/790650/ diff --git a/playbooks/functional/run.yaml b/playbooks/functional/run.yaml new file mode 100644 index 0000000..89c45b9 --- /dev/null +++ b/playbooks/functional/run.yaml @@ -0,0 +1,33 @@ +- hosts: all + roles: + - role: helm-template + vars: + helm_release_name: lodgeit + helm_chart: ./chart + tasks: + + - name: Get the Node Port + command: > + kubectl get -o jsonpath="{.spec.ports[0].nodePort}" services lodgeit + register: nodePort + + - name: Get the Node IP + command: > + kubectl get nodes -o jsonpath="{.items[0].status.addresses[0].address}" + register: nodeIP + + - name: Post the paste + shell: "curl -vv --silent -d 'code=test&language=text&webpage=' http://{{ nodeIP.stdout }}:{{ nodePort.stdout }} 2>&1 |grep Location" + register: pasteLocationInfo + + - name: Get the pasteUrl + shell: "echo '{{ pasteLocationInfo.stdout }}' | cut -d' ' -f3" + register: pasteUrl + + + - name: Get the paste + command: > + curl -I {{ pasteUrl.stdout }} + register: getPaste + +