From 1273e7cd01813cf00a9d776ae6f24756afded893 Mon Sep 17 00:00:00 2001 From: Craig Cooper Date: Mon, 19 Aug 2024 20:50:44 +0800 Subject: [PATCH] WAC-108 fix: Refactor volumes (#25) * fix: removed duplicated storages * fix: merge local and azure volume decorations * fix: merge local and aws and azure volume decorations * fix: bad jinja template typo * fix: bad jinja template typo AGAIN * fix: use old azure volume sizes as can't shrink exisiting ones * fix: restore RWO for aws * fix: don't change the provisioner * fix: correct ansible ternary syntax * chore: tidy ordering, restore non-azure sizings --- roles/ckan/tasks/azure-deploy.yml | 2 +- .../kubernetes/aks/ckan_volumes.yaml | 55 ------------ roles/ckan/templates/kubernetes/ckan.yaml | 16 +--- .../templates/kubernetes/ckan_volumes.yaml | 89 +++++++------------ 4 files changed, 36 insertions(+), 126 deletions(-) delete mode 100644 roles/ckan/templates/kubernetes/aks/ckan_volumes.yaml diff --git a/roles/ckan/tasks/azure-deploy.yml b/roles/ckan/tasks/azure-deploy.yml index c74c5e8..847eed0 100644 --- a/roles/ckan/tasks/azure-deploy.yml +++ b/roles/ckan/tasks/azure-deploy.yml @@ -11,7 +11,7 @@ --command "kubectl create namespace {{ application_namespace }}" - set_fact: - storage_class_name: managed-csi # Azure + storage_class_name: azureblob-nfs-premium # Azure. This can actually be anything as we create a custom StorageClass with this name - name: Get datalake info azure.azcollection.azure_rm_storageaccount_info: diff --git a/roles/ckan/templates/kubernetes/aks/ckan_volumes.yaml b/roles/ckan/templates/kubernetes/aks/ckan_volumes.yaml deleted file mode 100644 index 5733a01..0000000 --- a/roles/ckan/templates/kubernetes/aks/ckan_volumes.yaml +++ /dev/null @@ -1,55 +0,0 @@ ---- -apiVersion: storage.k8s.io/v1 -kind: StorageClass -metadata: - name: azureblob-nfs-premium -provisioner: file.csi.azure.com -volumeBindingMode: Immediate -allowVolumeExpansion: true -mountOptions: - - uid=900 - - gid=900 - -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - labels: - app: ckan - name: ckan-resources -spec: - accessModes: - - ReadWriteMany - storageClassName: azureblob-nfs-premium - resources: - requests: - storage: 1Gi - ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - labels: - app: ckan - name: ckan-webassets -spec: - accessModes: - - ReadWriteMany - storageClassName: azureblob-nfs-premium - resources: - requests: - storage: 1Gi - ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - labels: - app: ckan - name: ckan-storage -spec: - accessModes: - - ReadWriteMany - storageClassName: azureblob-nfs-premium - resources: - requests: - storage: 1Gi diff --git a/roles/ckan/templates/kubernetes/ckan.yaml b/roles/ckan/templates/kubernetes/ckan.yaml index 54ee789..1b1f467 100644 --- a/roles/ckan/templates/kubernetes/ckan.yaml +++ b/roles/ckan/templates/kubernetes/ckan.yaml @@ -198,8 +198,8 @@ spec: name: ckan-webassets - mountPath: /var/lib/ckan/resources name: ckan-resources - - name: ckan-configs - mountPath: /etc/ckan + - mountPath: /etc/ckan + name: ckan-configs readOnly: true {% if fjelltopp_env_type == 'local' %} @@ -208,17 +208,6 @@ spec: {% endif %} restartPolicy: Always volumes: -{% if fjelltopp_cloud_provider == 'azure' %} - - name: ckan-storage - persistentVolumeClaim: - claimName: ckan-storage-blob - - name: ckan-webassets - persistentVolumeClaim: - claimName: ckan-webassets-blob - - name: ckan-resources - persistentVolumeClaim: - claimName: ckan-resources-blob -{% else %} - name: ckan-storage persistentVolumeClaim: claimName: ckan-storage @@ -228,7 +217,6 @@ spec: - name: ckan-resources persistentVolumeClaim: claimName: ckan-resources -{% endif %} {% if fjelltopp_env_type == 'local' %} - name: localckan diff --git a/roles/ckan/templates/kubernetes/ckan_volumes.yaml b/roles/ckan/templates/kubernetes/ckan_volumes.yaml index 8f5bc9a..590e6f0 100644 --- a/roles/ckan/templates/kubernetes/ckan_volumes.yaml +++ b/roles/ckan/templates/kubernetes/ckan_volumes.yaml @@ -1,20 +1,35 @@ -{% if fjelltopp_env_type == 'local' %} +# Setup Azure Storage Class +{% if fjelltopp_cloud_provider == 'azure' %} +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: "{{ storage_class_name }}" +provisioner: blob.csi.azure.com +volumeBindingMode: Immediate +allowVolumeExpansion: true +mountOptions: + - uid=900 + - gid=900 +{% endif %} + --- apiVersion: v1 kind: PersistentVolumeClaim metadata: + name: ckan-storage creationTimestamp: null labels: app: ckan - name: ckan-storage spec: +{% if fjelltopp_env_type != 'local' %} + storageClassName: "{{ storage_class_name }}" +{% endif %} accessModes: - - ReadWriteOnce + - "{{ (fjelltopp_cloud_provider == 'azure') | ternary('ReadWriteMany', 'ReadWriteOnce') }}" # Azure supports ReadWriteMany and it's required for rolling deployments resources: requests: - storage: 100Mi -status: {} - + storage: "{{ (fjelltopp_cloud_provider == 'azure') | ternary('1Gi', '100Mi') }}" --- apiVersion: v1 kind: PersistentVolumeClaim @@ -24,12 +39,14 @@ metadata: app: ckan name: ckan-webassets spec: +{% if fjelltopp_env_type != 'local' %} + storageClassName: "{{ storage_class_name }}" +{% endif %} accessModes: - - ReadWriteOnce + - "{{ (fjelltopp_cloud_provider == 'azure') | ternary('ReadWriteMany', 'ReadWriteOnce') }}" resources: requests: - storage: 100Mi -status: {} + storage: "{{ (fjelltopp_cloud_provider == 'azure') | ternary('1Gi', '100Mi') }}" --- apiVersion: v1 @@ -40,14 +57,18 @@ metadata: app: ckan name: ckan-resources spec: +{% if fjelltopp_env_type != 'local' %} + storageClassName: "{{ storage_class_name }}" +{% endif %} accessModes: - - ReadWriteOnce + - "{{ (fjelltopp_cloud_provider == 'azure') | ternary('ReadWriteMany', 'ReadWriteOnce') }}" resources: requests: - storage: 100Mi + storage: "{{ (fjelltopp_cloud_provider == 'azure') | ternary('1Gi', '100Mi') }}" status: {} - +# Local Only Volumes +{% if fjelltopp_env_type == 'local' %} --- apiVersion: v1 kind: PersistentVolume @@ -84,48 +105,4 @@ spec: storage: 20Gi volumeName: localckan status: {} - -{% else %} ---- -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: ckan-storage -spec: - storageClassName: "{{ storage_class_name }}" - accessModes: - - ReadWriteMany - resources: - requests: - storage: 1000Mi ---- -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: ckan-webassets -spec: - storageClassName: "{{ storage_class_name }}" - accessModes: - - ReadWriteMany - resources: - requests: - storage: 1000Mi - ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - labels: - app: ckan - name: ckan-resources -spec: - storageClassName: "{{ storage_class_name }}" - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 100Mi -status: {} - {% endif %} -