Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Update PVC permissions #395

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bundle/manifests/konveyor-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ metadata:
categories: Modernization & Migration
certified: "false"
containerImage: quay.io/konveyor/tackle2-operator:latest
createdAt: "2024-10-09T15:56:59Z"
createdAt: "2024-11-07T18:19:51Z"
description: Konveyor is an open-source application modernization platform that
helps organizations safely and predictably modernize applications to Kubernetes
at scale.
Expand Down Expand Up @@ -331,6 +331,14 @@ spec:
- '*'
verbs:
- '*'
- apiGroups:
- security.openshift.io
resourceNames:
- anyuid
resources:
- securitycontextconstraints
verbs:
- use
serviceAccountName: tackle-hub
- rules:
- apiGroups:
Expand Down
8 changes: 8 additions & 0 deletions helm/templates/rbac/hub_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ rules:
- '*'
verbs:
- '*'
- apiGroups:
- security.openshift.io
resourceNames:
- anyuid
resources:
- securitycontextconstraints
verbs:
- use
40 changes: 40 additions & 0 deletions roles/tackle/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
set_fact:
api_groups: "{{ lookup('k8s', cluster_info='api_groups') }}"

- name: Gather Facts
ansible.builtin.gather_facts:
gather_subset:
- user_uid

- name: "Retrieve UID"
set_fact:
hub_uid: "{{ ansible_facts['user_uid'] }}"

- name: "Transfer rwx_storage_class setting if hub_bucket_storage_class is not defined"
set_fact:
hub_bucket_storage_class: "{{ rwx_storage_class }}"
Expand Down Expand Up @@ -562,6 +571,37 @@
definition: "{{ lookup('template', 'route-ui.yml.j2') }}"
when: openshift_cluster|bool

- name: "Check if Cache PersistentVolumeClaim exists"
kubernetes.core.k8s_info:
api_version: v1
kind: PersistentVolumeClaim
namespace: "{{ app_namespace }}"
name: "{{ cache_data_volume_claim_name }}"
register: cache_pvc

- name: "Delete cache PVC if non-root label is missing so it can be recreated"
when: cache_pvc.resources|length > 0 and cache_pvc.resources[0].metadata.labels['non-root'] is not defined
block:
- name: Scale down Hub
k8s:
state: present
definition: "{{ lookup('template', 'deployment-hub.yml.j2') }}"
merge_type: merge
vars:
hub_deployment_replicas: 0

- name: Delete cache PVC
k8s:
state: absent
definition: "{{ lookup('template', 'persistentvolumeclaim-cache.yml.j2') }}"
wait: true

- name: Scale up Hub
k8s:
state: present
definition: "{{ lookup('template', 'deployment-hub.yml.j2') }}"
merge_type: merge

- name: "Setup Cache PersistentVolumeClaim"
k8s:
state: present
Expand Down
19 changes: 19 additions & 0 deletions roles/tackle/templates/deployment-hub.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ spec:
requests:
cpu: {{ hub_container_requests_cpu }}
memory: {{ hub_container_requests_memory }}
securityContext:
runAsUser: {{ hub_uid }}
# TODO: Add liveness and readiness probes
volumeMounts:
- name: {{ hub_database_volume_name }}
Expand All @@ -218,6 +220,23 @@ spec:
- name: {{ hub_tls_secret_name }}
mountPath: /var/run/secrets/{{ hub_tls_secret_name }}/tls.crt
{% endif %}
initContainers:
- command:
- chown
- -R
- {{ hub_uid }}:root
- {{ hub_database_volume_path }}
- {{ hub_bucket_volume_path }}
image: "{{ hub_image_fqin }}"
imagePullPolicy: "{{ image_pull_policy }}"
name: update-perms
securityContext:
runAsUser: 0
volumeMounts:
- mountPath: {{ hub_database_volume_path }}
name: {{ hub_database_volume_name }}
- mountPath: {{ hub_bucket_volume_path }}
name: {{ hub_bucket_volume_name }}
volumes:
{% if rwx_supported|bool %}
- name: {{ cache_data_volume_name }}
Expand Down
1 change: 1 addition & 0 deletions roles/tackle/templates/persistentvolumeclaim-cache.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
app.kubernetes.io/name: {{ cache_name }}
app.kubernetes.io/part-of: {{ app_name }}
volume: {{ cache_data_volume_name }}
non-root: "true"
spec:
accessModes:
- "{{ cache_data_volume_claim_mode }}"
Expand Down
Loading