From ec00228bcd48f5dcb518db3df1de12f4af5cfd6c Mon Sep 17 00:00:00 2001 From: Larry Rensing Date: Tue, 24 Jan 2017 23:49:08 +0000 Subject: [PATCH 1/4] replaced existing systemd script with kubernetes job, also added configurable credentials for maas --- .../bin/_import-boot-resources.sh.tpl | 33 +++++++++ maas/templates/bin/_job-readiness.sh.tpl | 6 ++ .../bin/_maas-region-controller.postinst.tpl | 8 ++- maas/templates/bin/_start.sh.tpl | 8 +++ maas/templates/configmap-bin.yaml | 4 ++ maas/templates/configmap-etc.yaml | 2 + maas/templates/db-service.yaml | 13 ++++ maas/templates/deploy-region.yaml | 19 +++-- maas/templates/etc/_postgresql-config.tpl | 44 ++++++++++++ maas/templates/job-import.yaml | 72 +++++++++++++++++++ .../{service.yaml => maas-service.yaml} | 2 +- maas/values.yaml | 30 +++++++- 12 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 maas/templates/bin/_import-boot-resources.sh.tpl create mode 100644 maas/templates/bin/_job-readiness.sh.tpl create mode 100644 maas/templates/db-service.yaml create mode 100644 maas/templates/etc/_postgresql-config.tpl create mode 100644 maas/templates/job-import.yaml rename maas/templates/{service.yaml => maas-service.yaml} (91%) diff --git a/maas/templates/bin/_import-boot-resources.sh.tpl b/maas/templates/bin/_import-boot-resources.sh.tpl new file mode 100644 index 0000000000..95c6b657b7 --- /dev/null +++ b/maas/templates/bin/_import-boot-resources.sh.tpl @@ -0,0 +1,33 @@ +#!/bin/sh + +set -ex + +function check_for_download { + + if maas {{ .Values.credentials.admin_username }} boot-resources read | grep -q '\[\]'; + then + echo 'Did not find boot resources. Will try again' + sleep 60 + exit 1 + else + echo 'Boot resources found' + exit 0 + fi + +} + +maas-region local_config_set \ + --database-host "{{ .Values.db_service_name }}.{{ .Release.Namespace}}" \ + --database-name "{{ .Values.database.db_name }}" \ + --database-user "{{ .Values.database.db_user }}" \ + --database-pass "{{ .Values.database.db_password }}" \ + --maas-url "http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}:80/MAAS" + +KEY=$(maas-region apikey --username={{ .Values.credentials.admin_username }}) +maas login {{ .Values.credentials.admin_username }} http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS/ $KEY + +# make call to import images +maas {{ .Values.credentials.admin_username }} boot-resources import +# see if we can find > 0 images +sleep 10 +check_for_download diff --git a/maas/templates/bin/_job-readiness.sh.tpl b/maas/templates/bin/_job-readiness.sh.tpl new file mode 100644 index 0000000000..9eb9659fe4 --- /dev/null +++ b/maas/templates/bin/_job-readiness.sh.tpl @@ -0,0 +1,6 @@ +#!/bin/bash + + Date: Thu, 26 Jan 2017 21:47:51 +0000 Subject: [PATCH 2/4] job init container uses template, removed special image --- .../snippets/_k8s_init_dep_check.tpl | 8 +++++ .../bin/_import-boot-resources.sh.tpl | 31 ++++++++++-------- maas/templates/job-import.yaml | 32 +++---------------- maas/values.yaml | 15 ++++++--- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/common/templates/snippets/_k8s_init_dep_check.tpl b/common/templates/snippets/_k8s_init_dep_check.tpl index d55e0bc654..0188ac1c7f 100644 --- a/common/templates/snippets/_k8s_init_dep_check.tpl +++ b/common/templates/snippets/_k8s_init_dep_check.tpl @@ -8,12 +8,16 @@ "env": [ { "name": "POD_NAME", + {{- if $deps.pod -}} + "value": "{{- $deps.pod . 1 -}}" + {{- else -}} "valueFrom": { "fieldRef": { "APIVersion": "v1", "fieldPath": "metadata.name" } } + {{- end -}} }, { "name": "NAMESPACE", @@ -40,6 +44,10 @@ "name": "DEPENDENCY_DAEMONSET", "value": "{{ include "joinListWithColon" $deps.daemonset }}" }, + { + "name": "DEPENDENCY_CONTAINER", + "value": "{{ include "joinListWithColon" $deps.container }}" + }, { "name": "COMMAND", "value": "echo done" diff --git a/maas/templates/bin/_import-boot-resources.sh.tpl b/maas/templates/bin/_import-boot-resources.sh.tpl index 95c6b657b7..6dda0c1674 100644 --- a/maas/templates/bin/_import-boot-resources.sh.tpl +++ b/maas/templates/bin/_import-boot-resources.sh.tpl @@ -4,24 +4,27 @@ set -ex function check_for_download { - if maas {{ .Values.credentials.admin_username }} boot-resources read | grep -q '\[\]'; - then - echo 'Did not find boot resources. Will try again' - sleep 60 - exit 1 - else - echo 'Boot resources found' - exit 0 - fi - + TIMEOUT={{ .Values.jobs.import_boot_resources.timeout }} + while [[ ${TIMEOUT} -gt 0 ]]; do + if maas {{ .Values.credentials.admin_username }} boot-resources read | grep -q '\[\]'; + then + echo 'Did not find boot resources. Will try again' + let TIMEOUT-={{ .Values.jobs.import_boot_resources.retry_timer }} + sleep {{ .Values.jobs.import_boot_resources.retry_timer }} + else + echo 'Boot resources found' + exit 0 + fi + done + exit 1 } maas-region local_config_set \ - --database-host "{{ .Values.db_service_name }}.{{ .Release.Namespace}}" \ + --database-host "{{ .Values.db_service_name }}.{{ .Release.Namespace }}" \ --database-name "{{ .Values.database.db_name }}" \ --database-user "{{ .Values.database.db_user }}" \ --database-pass "{{ .Values.database.db_password }}" \ - --maas-url "http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}:80/MAAS" + --maas-url "http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}:{{ .Values.network.port.service_gui }}/MAAS" KEY=$(maas-region apikey --username={{ .Values.credentials.admin_username }}) maas login {{ .Values.credentials.admin_username }} http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS/ $KEY @@ -29,5 +32,5 @@ maas login {{ .Values.credentials.admin_username }} http://{{ .Values.ui_service # make call to import images maas {{ .Values.credentials.admin_username }} boot-resources import # see if we can find > 0 images -sleep 10 -check_for_download +sleep {{ .Values.jobs.import_boot_resources.retry_timer }} +check_for_download \ No newline at end of file diff --git a/maas/templates/job-import.yaml b/maas/templates/job-import.yaml index 816f0d3378..2d5c9d30f6 100644 --- a/maas/templates/job-import.yaml +++ b/maas/templates/job-import.yaml @@ -1,3 +1,5 @@ +{{- $envAll := . }} +{{- $dependencies := .Values.dependencies.import_resources }} apiVersion: batch/v1 kind: Job metadata: @@ -7,39 +9,13 @@ spec: metadata: annotations: pod.beta.kubernetes.io/init-containers: '[ - { - "name": "init", - "image": "{{ .Values.images.entrypoint }}", - "imagePullPolicy": "{{ .Values.images.pull_policy }}", - "env": [ - { - "name": "NAMESPACE", - "value": "{{ .Release.Namespace }}" - }, - { - "name": "POD_NAME", - "value": "{{ .Values.dependencies.import_resources.pod }}" - }, - { - "name": "DEPENDENCY_SERVICE", - "value": "{{ include "joinListWithColon" .Values.dependencies.import_resources.service }}" - }, - { - "name": "DEPENDENCY_CONTAINER", - "value": "{{ .Values.dependencies.import_resources.container }}" - }, - { - "name": "COMMAND", - "value": "echo done" - } - ] - } +{{ tuple $envAll $dependencies | include "dep_check_init_cont" | indent 10 }} ]' spec: restartPolicy: OnFailure containers: - name: region-import-resources - image: {{ .Values.images.maas_toolbox }} + image: {{ .Values.images.maas_region }} imagePullPolicy: {{ .Values.images.pull_policy }} command: - bash diff --git a/maas/values.yaml b/maas/values.yaml index 9c3680c7b0..837d992f23 100644 --- a/maas/values.yaml +++ b/maas/values.yaml @@ -14,19 +14,26 @@ database: dependencies: import_resources: - pod: maas-region-0 - container: maas-region + pod: + - maas-region-0 + container: + - maas-region service: - maas-region-ui - db-service images: maas_region: quay.io/attcomdev/maas-region:2.1.2-2 - maas_toolbox: quay.io/attcomdev/maas-toolbox:2.1.2 maas_rack: quay.io/attcomdev/maas-rack:2.1.2-2 - entrypoint: quay.io/stackanetes/kubernetes-entrypoint:v0.1.0 + dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.1.0 pull_policy: Always +jobs: + import_boot_resources: + retry_timer: 10 + #default timeout: 15 minutes + timeout: 900 + labels: node_selector_key: openstack-control-plane node_selector_value: enabled From 674ea30c86b2225e9b0d8267e4de062ae52a265f Mon Sep 17 00:00:00 2001 From: Larry Rensing Date: Mon, 30 Jan 2017 23:40:35 +0000 Subject: [PATCH 3/4] Rebase to pull in changes in common --- common/templates/snippets/_k8s_init_dep_check.tpl | 4 ++-- maas/values.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/templates/snippets/_k8s_init_dep_check.tpl b/common/templates/snippets/_k8s_init_dep_check.tpl index d6ba9a2014..b918b10d74 100644 --- a/common/templates/snippets/_k8s_init_dep_check.tpl +++ b/common/templates/snippets/_k8s_init_dep_check.tpl @@ -9,7 +9,7 @@ { "name": "POD_NAME", {{- if $deps.pod -}} - "value": "{{- $deps.pod . 1 -}}" + "value": "{{ index $deps.pod 0 }}" {{- else -}} "valueFrom": { "fieldRef": { @@ -46,7 +46,7 @@ }, { "name": "DEPENDENCY_CONTAINER", - "value": "{{ include "joinListWithColon" $deps.container }}" + "value": "{{ include "joinListWithComma" $deps.container }}" }, { "name": "COMMAND", diff --git a/maas/values.yaml b/maas/values.yaml index 837d992f23..fe65b90fad 100644 --- a/maas/values.yaml +++ b/maas/values.yaml @@ -14,7 +14,7 @@ database: dependencies: import_resources: - pod: + pod: - maas-region-0 container: - maas-region From 96168b3c14641e61348023c462724ab276a31752 Mon Sep 17 00:00:00 2001 From: Larry Rensing Date: Mon, 13 Feb 2017 16:12:17 +0000 Subject: [PATCH 4/4] cleanup configmap names --- maas/templates/bin/_register-rack-controller.sh.tpl | 6 +++--- maas/templates/job-import.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/maas/templates/bin/_register-rack-controller.sh.tpl b/maas/templates/bin/_register-rack-controller.sh.tpl index 3445cc35fe..0c1d415a31 100644 --- a/maas/templates/bin/_register-rack-controller.sh.tpl +++ b/maas/templates/bin/_register-rack-controller.sh.tpl @@ -5,19 +5,19 @@ set -ex # show env env > /tmp/env -echo "register-rack-controller URL: "{{ .Values.service_name }}.{{ .Release.Namespace }} +echo "register-rack-controller URL: "{{ .Values.ui_service_name }}.{{ .Release.Namespace }} # note the secret must be a valid hex value # register forever while [ 1 ]; do - if maas-rack register --url=http://{{ .Values.service_name }}.{{ .Release.Namespace }}/MAAS --secret={{ .Values.secret | quote }}; + if maas-rack register --url=http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS --secret={{ .Values.secret | quote }}; then echo "Successfully registered with MaaS Region Controller" break else - echo "Unable to register with http://{{ .Values.service_name }}.{{ .Release.Namespace }}/MAAS... will try again" + echo "Unable to register with http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS... will try again" sleep 10 fi; diff --git a/maas/templates/job-import.yaml b/maas/templates/job-import.yaml index 2d5c9d30f6..419ab3c023 100644 --- a/maas/templates/job-import.yaml +++ b/maas/templates/job-import.yaml @@ -39,10 +39,10 @@ spec: volumes: - name: import-boot-resources configMap: - name: maas-region-bin + name: maas-bin - name: job-readiness configMap: - name: maas-region-bin + name: maas-bin - name: maas-dns-config configMap: - name: maas-region-etc + name: maas-etc