Skip to content

Commit 2e1dbb9

Browse files
jmontleondymurray
authored andcommitted
🐛 Update PVC permissions (#395)
Signed-off-by: Jason Montleon <[email protected]> (cherry picked from commit a09410d)
1 parent 9fd1d2e commit 2e1dbb9

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

bundle/manifests/konveyor-operator.clusterserviceversion.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ metadata:
103103
categories: Modernization & Migration
104104
certified: "false"
105105
containerImage: quay.io/konveyor/tackle2-operator:latest
106-
createdAt: "2024-10-09T15:56:59Z"
106+
createdAt: "2024-11-07T18:19:51Z"
107107
description: Konveyor is an open-source application modernization platform that
108108
helps organizations safely and predictably modernize applications to Kubernetes
109109
at scale.
@@ -331,6 +331,14 @@ spec:
331331
- '*'
332332
verbs:
333333
- '*'
334+
- apiGroups:
335+
- security.openshift.io
336+
resourceNames:
337+
- anyuid
338+
resources:
339+
- securitycontextconstraints
340+
verbs:
341+
- use
334342
serviceAccountName: tackle-hub
335343
- rules:
336344
- apiGroups:

helm/templates/rbac/hub_role.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ rules:
1212
- '*'
1313
verbs:
1414
- '*'
15+
- apiGroups:
16+
- security.openshift.io
17+
resourceNames:
18+
- anyuid
19+
resources:
20+
- securitycontextconstraints
21+
verbs:
22+
- use

roles/tackle/tasks/main.yml

+40
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
set_fact:
44
api_groups: "{{ lookup('k8s', cluster_info='api_groups') }}"
55

6+
- name: Gather Facts
7+
ansible.builtin.gather_facts:
8+
gather_subset:
9+
- user_uid
10+
11+
- name: "Retrieve UID"
12+
set_fact:
13+
hub_uid: "{{ ansible_facts['user_uid'] }}"
14+
615
- name: "Transfer rwx_storage_class setting if hub_bucket_storage_class is not defined"
716
set_fact:
817
hub_bucket_storage_class: "{{ rwx_storage_class }}"
@@ -562,6 +571,37 @@
562571
definition: "{{ lookup('template', 'route-ui.yml.j2') }}"
563572
when: openshift_cluster|bool
564573

574+
- name: "Check if Cache PersistentVolumeClaim exists"
575+
kubernetes.core.k8s_info:
576+
api_version: v1
577+
kind: PersistentVolumeClaim
578+
namespace: "{{ app_namespace }}"
579+
name: "{{ cache_data_volume_claim_name }}"
580+
register: cache_pvc
581+
582+
- name: "Delete cache PVC if non-root label is missing so it can be recreated"
583+
when: cache_pvc.resources|length > 0 and cache_pvc.resources[0].metadata.labels['non-root'] is not defined
584+
block:
585+
- name: Scale down Hub
586+
k8s:
587+
state: present
588+
definition: "{{ lookup('template', 'deployment-hub.yml.j2') }}"
589+
merge_type: merge
590+
vars:
591+
hub_deployment_replicas: 0
592+
593+
- name: Delete cache PVC
594+
k8s:
595+
state: absent
596+
definition: "{{ lookup('template', 'persistentvolumeclaim-cache.yml.j2') }}"
597+
wait: true
598+
599+
- name: Scale up Hub
600+
k8s:
601+
state: present
602+
definition: "{{ lookup('template', 'deployment-hub.yml.j2') }}"
603+
merge_type: merge
604+
565605
- name: "Setup Cache PersistentVolumeClaim"
566606
k8s:
567607
state: present

roles/tackle/templates/deployment-hub.yml.j2

+19
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ spec:
204204
requests:
205205
cpu: {{ hub_container_requests_cpu }}
206206
memory: {{ hub_container_requests_memory }}
207+
securityContext:
208+
runAsUser: {{ hub_uid }}
207209
# TODO: Add liveness and readiness probes
208210
volumeMounts:
209211
- name: {{ hub_database_volume_name }}
@@ -218,6 +220,23 @@ spec:
218220
- name: {{ hub_tls_secret_name }}
219221
mountPath: /var/run/secrets/{{ hub_tls_secret_name }}/tls.crt
220222
{% endif %}
223+
initContainers:
224+
- command:
225+
- chown
226+
- -R
227+
- {{ hub_uid }}:root
228+
- {{ hub_database_volume_path }}
229+
- {{ hub_bucket_volume_path }}
230+
image: "{{ hub_image_fqin }}"
231+
imagePullPolicy: "{{ image_pull_policy }}"
232+
name: update-perms
233+
securityContext:
234+
runAsUser: 0
235+
volumeMounts:
236+
- mountPath: {{ hub_database_volume_path }}
237+
name: {{ hub_database_volume_name }}
238+
- mountPath: {{ hub_bucket_volume_path }}
239+
name: {{ hub_bucket_volume_name }}
221240
volumes:
222241
{% if rwx_supported|bool %}
223242
- name: {{ cache_data_volume_name }}

roles/tackle/templates/persistentvolumeclaim-cache.yml.j2

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
app.kubernetes.io/name: {{ cache_name }}
99
app.kubernetes.io/part-of: {{ app_name }}
1010
volume: {{ cache_data_volume_name }}
11+
non-root: "true"
1112
spec:
1213
accessModes:
1314
- "{{ cache_data_volume_claim_mode }}"

0 commit comments

Comments
 (0)