Skip to content

Commit 3470a35

Browse files
cbandyJonathan S. Katz
authored andcommitted
Allow Ansible installs from within Kubernetes
kubectl will work without any configured contexts when run inside a pod with service environment variables and a service account token. Using kubectl this way is a requirement of the GCP Marketplace Kubernetes application installer. Issue: [ch6131]
1 parent d02feea commit 3470a35

File tree

9 files changed

+51
-32
lines changed

9 files changed

+51
-32
lines changed

ansible/roles/pgo-metrics/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
kubernetes_context: ""
3+
kubernetes_in_cluster: "false"
4+
openshift_host: ""
5+
26
grafana_default_dashboards: "true"
37
grafana_port: "3000"
48
grafana_service_name: "crunchy-grafana"

ansible/roles/pgo-metrics/tasks/grafana.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
---
2-
- fail:
3-
msg: "Only set one of kubernetes_context or openshift_host"
4-
when: openshift_host is defined and kubernetes_context is defined
5-
tags: always
6-
72
- name: Set output directory fact
83
set_fact:
94
grafana_output_dir: "{{ ansible_env.HOME }}/.pgo/{{ metrics_namespace }}/output"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
- name: Set the Kubernetes Context
33
shell: "kubectl config use-context {{ kubernetes_context }}"
4+
when: not (kubernetes_in_cluster | bool)
45
tags: always

ansible/roles/pgo-metrics/tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- openshift.yml
1414
loop_control:
1515
loop_var: tasks
16-
when: openshift_host is defined
16+
when: openshift_host != ''
1717
tags: always
1818

1919
- include_tasks: "{{ tasks }}"
@@ -22,18 +22,18 @@
2222
- kubernetes.yml
2323
loop_control:
2424
loop_var: tasks
25-
when: kubernetes_context is defined
25+
when: kubernetes_context != '' or kubernetes_in_cluster | bool
2626
tags: always
2727

2828
- include_tasks: cleanup.yml
2929
tags: [uninstall-metrics, upgrade-metrics]
3030

3131
- include_tasks: kubernetes_cleanup.yml
32-
when: kubernetes_context is defined
32+
when: kubernetes_context != '' or kubernetes_in_cluster | bool
3333
tags: [uninstall-metrics]
3434

3535
- include_tasks: openshift_cleanup.yml
36-
when: openshift_host is defined
36+
when: openshift_host != ''
3737
tags: [uninstall-metrics]
3838

3939
- name: Use kubectl or oc

ansible/roles/pgo-metrics/tasks/prometheus.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
---
2-
- fail:
3-
msg: "Only set one of kubernetes_context or openshift_host"
4-
when: openshift_host is defined and kubernetes_context is defined
5-
tags: always
6-
72
- name: Set output directory fact
83
set_fact:
94
prom_output_dir: "{{ ansible_env.HOME }}/.pgo/{{ metrics_namespace }}/output"

ansible/roles/pgo-operator/defaults/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
kubernetes_context: ""
3+
kubernetes_in_cluster: "false"
4+
openshift_host: ""
5+
26
backrest_aws_s3_key: ""
37
backrest_aws_s3_secret: ""
48
backrest_aws_s3_bucket: ""
@@ -28,4 +32,4 @@ pgo_apiserver_port: 8443
2832
delete_operator_namespace: "false"
2933
delete_watched_namespaces: "false"
3034
delete_metrics_namespace: "false"
31-
preserve_pg_clusters: "false"
35+
preserve_pg_clusters: "false"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
- name: Set the Kubernetes Context
33
shell: "kubectl config use-context {{ kubernetes_context }}"
4+
when: not (kubernetes_in_cluster | bool)
45
tags: always

ansible/roles/pgo-operator/tasks/main.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
---
2-
- fail:
3-
msg: "Only set one of kubernetes_context or openshift_host"
4-
when: openshift_host is defined and kubernetes_context is defined
5-
tags: always
6-
72
- name: Set output directory fact
83
set_fact:
94
output_dir: "{{ ansible_env.HOME }}/.pgo/{{ pgo_operator_namespace }}/output"
@@ -22,7 +17,7 @@
2217
- openshift.yml
2318
loop_control:
2419
loop_var: tasks
25-
when: openshift_host is defined
20+
when: openshift_host != ''
2621
tags: always
2722

2823
- include_tasks: "{{ tasks }}"
@@ -31,18 +26,18 @@
3126
- kubernetes.yml
3227
loop_control:
3328
loop_var: tasks
34-
when: kubernetes_context is defined
29+
when: kubernetes_context != '' or kubernetes_in_cluster | bool
3530
tags: always
3631

3732
- include_tasks: cleanup.yml
3833
tags: [uninstall, update]
3934

4035
- include_tasks: kubernetes_cleanup.yml
41-
when: kubernetes_context is defined
36+
when: kubernetes_context != '' or kubernetes_in_cluster | bool
4237
tags: [uninstall]
4338

4439
- include_tasks: openshift_cleanup.yml
45-
when: openshift_host is defined
40+
when: openshift_host != ''
4641
tags: [uninstall]
4742

4843
- include_tasks: certs.yml

ansible/roles/pgo-preflight/tasks/main.yml

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,44 @@
99
register: uname_result
1010
tags: [install, update]
1111

12-
- name: Check if required Kube or OpenShift variables are defined
13-
fail: msg="Please specify either OpenShift or Kubernetes variables in inventory"
14-
when: >
15-
(openshift_host is undefined or (openshift_host is defined and openshift_host == ''))
16-
and (kubernetes_context is undefined or (kubernetes_context is defined and kubernetes_context == ''))
17-
or ((openshift_host is defined and openshift_host != '') and (kubernetes_context is defined and kubernetes_context != ''))
12+
- assert:
13+
msg: Please specify either OpenShift or Kubernetes variables in inventory
14+
that:
15+
- openshift_host | default('') != '' or
16+
kubernetes_context | default('') != '' or
17+
kubernetes_in_cluster | default(False) | bool
18+
tags: always
19+
20+
- assert:
21+
msg: Only set one of kubernetes_context, kubernetes_in_cluster, or openshift_host
22+
that:
23+
- kubernetes_context | default('') == ''
24+
- not (kubernetes_in_cluster | default(False) | bool)
25+
when: openshift_host | default('') != ''
26+
tags: always
27+
28+
- assert:
29+
msg: Only set one of kubernetes_context, kubernetes_in_cluster, or openshift_host
30+
that:
31+
- openshift_host | default('') == ''
32+
- not (kubernetes_in_cluster | default(False) | bool)
33+
when: kubernetes_context | default('') != ''
34+
tags: always
35+
36+
- assert:
37+
msg: Only set one of kubernetes_context, kubernetes_in_cluster, or openshift_host
38+
that:
39+
- openshift_host | default('') == ''
40+
- kubernetes_context | default('') == ''
41+
when: kubernetes_in_cluster | default(False) | bool
1842
tags: always
1943

2044
- include_tasks: check_openshift.yml
21-
when: openshift_host is defined and openshift_host != ''
45+
when: openshift_host | default('') != ''
2246
tags: always
2347

2448
- include_tasks: check_kubernetes.yml
25-
when: kubernetes_context is defined and kubernetes_context != ''
49+
when: kubernetes_context | default('') != '' or kubernetes_in_cluster | default(False) | bool
2650
tags: always
2751

2852
- include_tasks: check_inventory.yml

0 commit comments

Comments
 (0)