Update Helm to version 3.3.4
[infra/stack/kubernetes.git] / apps / spinnaker / kubespray / playbooks / roles / install / tasks / main.yml
1 ---
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19 #
20 - name: Load execution mode variables
21   include_vars: "{{ execution_mode }}.yaml"
22
23 - block:
24   - name: Create directories for helm repositories
25     file:
26       path: "{{ item.path }}"
27       state: "{{ item.state }}"
28     loop:
29       - {path: "{{ engine_workspace }}/offline/charts/stable", state: absent}
30       - {path: "{{ engine_workspace }}/offline/charts/stable", state: directory}
31       - {path: "{{ engine_workspace }}/offline/charts/local", state: absent}
32       - {path: "{{ engine_workspace }}/offline/charts/local", state: directory}
33
34   - name: Place index.yaml to webserver stable charts repository
35     template:
36       src: "index.yaml.j2"
37       dest: "{{ engine_workspace }}/offline/charts/stable/index.yaml"
38       force: true
39   when: execution_mode == "offline-deployment"
40
41 - name: Initialize Helm
42   command: helm init --client-only --local-repo-url {{ local_repo_url }} --stable-repo-url {{ stable_repo_url }}
43   register: helm_init_result
44   changed_when: true
45   when: helm_version is version('v3', '<')
46
47 - name: Check if stable helm repo exists (helm v3+)
48   command: "helm repo list"
49   changed_when: true
50   failed_when: false
51   register: helm_repo_list_result
52
53 - name: Add stable helm repo (helm v3+)
54   command: "helm repo add stable {{ stable_repo_url }}"
55   register: helm_repo_add_stable_result
56   changed_when: true
57   when: >
58     helm_version is version('v3.0.0', '>=')
59     and execution_mode == "online-deployment"
60     and helm_repo_list_result is not search(stable_repo_url)
61
62 - name: Clone Helm Charts repository
63   git:
64     repo: "{{ helm_charts_git_url }}"
65     dest: "{{ engine_cache }}/repos/charts"
66     version: "{{ charts_version }}"
67     force: true
68     recursive: true
69   environment:
70     http_proxy: "{{ lookup('env','http_proxy') }}"
71     https_proxy: "{{ lookup('env','https_proxy') }}"
72     no_proxy: "{{ lookup('env','no_proxy') }}"
73
74 - name: Generate values.yaml
75   template:
76     src: "values.yaml.j2"
77     dest: "{{ engine_cache }}/repos/charts/stable/spinnaker/values.yaml"
78     force: true
79
80 - name: Remove previous installations of Spinnaker
81   command: >
82     helm delete --purge "{{ spinnaker_service }}"
83   changed_when: true
84   ignore_errors: true
85   tags: reset
86
87 - name: Remove Spinnaker namespace
88   command: >
89     kubectl delete ns "{{ spinnaker_namespace }}"
90   changed_when: true
91   ignore_errors: true
92   tags: reset
93
94 - name: Create Spinnaker namespace
95   k8s:
96     state: present
97     definition:
98       apiVersion: v1
99       kind: Namespace
100       metadata:
101         name: "{{ spinnaker_namespace }}"
102
103 - name: Verify Spinnaker Helm charts are available to be deployed
104   command: helm search spinnaker -l
105   register: helm_search
106   changed_when: false
107
108 - name: Log Helm chart list to console
109   debug:
110     msg: "{{ helm_search.stdout_lines }}"
111
112 - name: Inform user about Spinnaker deployment
113   debug:
114     msg: >
115       Spinnaker deployment is about to start!
116       This takes a while and nothing will be logged to console until the process is completed.
117
118 - name: Fetch all helm dependencies for Spinnaker
119   command: >
120     helm dependency update
121       {{ engine_cache }}/repos/charts/stable/spinnaker
122   changed_when: true
123
124 - name: Install Spinnaker using helm
125   command: >
126     helm install
127       {% if helm_version is version('v3.0.0', '<')%} --name {% endif %}"{{ spinnaker_service }}"
128       --namespace "{{ spinnaker_namespace }}"
129       --timeout "900{% if helm_version is version('v3.0.0', '>=') %}s{% endif %}"
130       {{ engine_cache }}/repos/charts/stable/spinnaker
131   register: spinnaker_helm_log
132   changed_when: true
133
134 - name: Log Spinnaker helm output to console
135   debug:
136     msg: "{{ spinnaker_helm_log.stdout_lines }}"
137
138 # wait 10 minutes for all containers to be started
139 - name: Wait for all containers to be started
140   shell: |
141     set -o pipefail
142     kubectl get po -n spinnaker | grep ContainerCreating | wc -l
143   register: kube
144   changed_when:
145     kube.stdout  == '0'
146   until:
147     kube.stdout  == '0'
148   retries: 60
149   delay: 10
150
151 # wait 20 minutes for all containers to be initialized
152 - block:
153     - name: Wait for all containers to be initialized
154       shell: |
155         set -o pipefail
156         kubectl get po -n spinnaker | grep Init | grep -v Error | wc -l
157       register: kube
158       changed_when:
159         kube.stdout  == '0'
160       until:
161         kube.stdout  == '0'
162       retries: 120
163       delay: 10
164   always:
165     - name: Get POD status
166       command: kubectl get po -n spinnaker
167       changed_when: false
168       register: kube
169
170     - name: Log POD status to console
171       debug:
172         msg: "{{ kube.stdout_lines }}"
173
174     - name: Get summary of Spinnaker deployment
175       script: log-spinnaker-status.sh
176       register: spinnaker_status
177
178     - name: Log Spinnaker status to console
179       debug:
180         msg: "{{ spinnaker_status.stdout_lines }}"
181
182 # vim: set ts=2 sw=2 expandtab: