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