Skip to content

Commit e876c71

Browse files
authored
[cluster] Fix the 'preload_image' role (#596)
2 parents cd872b5 + a6caac5 commit e876c71

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

projects/cluster/toolbox/cluster_preload_image/tasks/main.yml

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
state: directory
66
mode: '0755'
77

8+
- name: Lookup the namespace user ID range
9+
shell:
10+
set -o pipefail;
11+
12+
oc get ns {{ cluster_preload_image_namespace }} -ojsonpath={.metadata.annotations} | jq -r '.["openshift.io/sa.scc.uid-range"]' | cut -d/ -f1
13+
register: namespace_uid_range_cmd
14+
15+
- name: Save the namespace uid as run_as_user
16+
set_fact:
17+
run_as_user: "{{ namespace_uid_range_cmd.stdout }}"
18+
819
- name: Apply the DaemonSet template
920
template:
1021
src: "{{ cluster_preload_image_ds_template }}"
@@ -89,26 +100,30 @@
89100
oc describe pods -l name={{ cluster_preload_image_name }}
90101
-n {{ cluster_preload_image_namespace }}
91102
> "{{ artifact_extra_logs_dir }}/pods.descr"
103+
failed_when: false
92104

93105
- name: Get the status of the preload Pods
94106
shell:
95107
oc get pods -l name={{ cluster_preload_image_name }}
96108
-owide
97109
-n {{ cluster_preload_image_namespace }}
98110
> "{{ artifact_extra_logs_dir }}/pods.status"
111+
failed_when: false
99112

100113
- name: Get the yaml of the daemonset
101114
shell:
102115
oc get ds/{{ cluster_preload_image_name }}
103116
-oyaml
104117
-n {{ cluster_preload_image_namespace }}
105118
> "{{ artifact_extra_logs_dir }}/daemonset.yaml"
119+
failed_when: false
106120

107121
- name: Get the status of the daemonset
108122
shell:
109123
oc get ds/{{ cluster_preload_image_name }}
110124
-n {{ cluster_preload_image_namespace }}
111125
> "{{ artifact_extra_logs_dir }}/daemonset.status"
126+
failed_when: false
112127

113128
- name: Delete the DaemonSet, it it exists
114129
command:

projects/cluster/toolbox/cluster_preload_image/templates/daemonset.yaml.j2

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ spec:
2929
- sleep
3030
- 1d
3131
securityContext:
32-
runAsUser: 999
32+
# prevent the image from requesting to run as root
33+
runAsUser: {{ run_as_user }}
3334
allowPrivilegeEscalation: false
3435
capabilities:
3536
drop: ["ALL"]

0 commit comments

Comments
 (0)