diff --git a/ansible/roles_ocp_workloads/ocp4_workload_portworx/defaults/main.yml b/ansible/roles_ocp_workloads/ocp4_workload_portworx/defaults/main.yml index 234020367eb..9282b3ebd2e 100644 --- a/ansible/roles_ocp_workloads/ocp4_workload_portworx/defaults/main.yml +++ b/ansible/roles_ocp_workloads/ocp4_workload_portworx/defaults/main.yml @@ -18,14 +18,12 @@ ocp4_workload_portworx_storagecluster_name: portworx-storage-cluster ocp4_workload_portworx_storagecluster_storage_class: gp3 ocp4_workload_portworx_storagecluster_storage_size: 50 +# Update the default storage class with a Portworx provided one +ocp4_workload_portworx_update_default_storageclass: false + # Define StorageCluster metadata (default when empty) ocp4_workload_portworx_image: "" # ocp4_workload_portworx_image: portworx/oci-monitor:3.1.3 # Define AWS polcy metadata ocp4_workload_portworx_policy_name: portworx-ebbs - -# AWS creds placeHolder value for testing -AWS_KEY: ABC123 -AWS_SECRET: abc123 -aws_region: us-east-2 diff --git a/ansible/roles_ocp_workloads/ocp4_workload_portworx/files/portworx_storageclass.yaml b/ansible/roles_ocp_workloads/ocp4_workload_portworx/files/portworx_storageclass.yaml new file mode 100644 index 00000000000..0b4f258c1c3 --- /dev/null +++ b/ansible/roles_ocp_workloads/ocp4_workload_portworx/files/portworx_storageclass.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: px-csi-vm + annotations: + storageclass.kubernetes.io/is-default-class: "true" +parameters: + repl: "3" + sharedv4: "true" + sharedv4_svc_type: "ClusterIP" + sharedv4_mount_options: vers=3.0,nolock +provisioner: pxd.portworx.com +reclaimPolicy: Delete +volumeBindingMode: WaitForFirstConsumer +allowVolumeExpansion: true diff --git a/ansible/roles_ocp_workloads/ocp4_workload_portworx/tasks/workload.yml b/ansible/roles_ocp_workloads/ocp4_workload_portworx/tasks/workload.yml index 82bfa3063d0..02cc036f0cf 100644 --- a/ansible/roles_ocp_workloads/ocp4_workload_portworx/tasks/workload.yml +++ b/ansible/roles_ocp_workloads/ocp4_workload_portworx/tasks/workload.yml @@ -165,3 +165,35 @@ spec: plugins: - portworx + + - name: Update default storage class with a Portworx provided one + when: ocp4_workload_portworx_update_default_storageclass | bool + block: + - name: Get all current storage classes + kubernetes.core.k8s_info: + api_version: storage.k8s.io/v1 + kind: StorageClass + register: r_sc + + - name: Remove default from previous default storage class + when: storage_class.metadata.annotations['storageclass.kubernetes.io/is-default-class'] is defined + kubernetes.core.k8s: + api_version: storage.k8s.io/v1 + kind: StorageClass + name: "{{ storage_class.metadata.name }}" + definition: + kind: StorageClass + apiVersion: v1 + name: "{{ storage_class }}" + metadata: + annotations: + storageclass.kubernetes.io/is-default-class: "false" + loop: "{{ r_sc.resources }}" + loop_control: + loop_var: storage_class + label: "{{ storage_class.metadata.name }}" + + - name: Create new Portworx VM default storage class + kubernetes.core.k8s: + state: present + definition: "{{ lookup('file', 'portworx_storageclass.yaml') | from_yaml }}"