Skip to content

Commit

Permalink
feat(nfs): allow sts volume expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
jobcespedes committed Sep 1, 2022
1 parent 8c3caf7 commit b96d799
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
9 changes: 5 additions & 4 deletions roles/v1alpha1/nfs/server/defaults/main/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,16 @@ server_pvc_data_spec: |
- '{{ server_pvc_data_storage_access_mode }}'
resources:
requests:
storage: '{{ server_pvc_datata_size | default((server_pvc_data_size_gib | string + 'Gi'),true) }}'
storage: '{{ server_pvc_data_size }}'
server_pvc_data_current_size: "{{ lookup('k8s', api_version='v1', kind='StatefulSet', namespace=meta_namespace,
resource_name=server_sts).spec.volumeClaimTemplates[0].spec.resources.requests.storage | default('') }}"
server_pvc_data_size:
"{{
false
server_pvc_data_size_gib | string + 'Gi'
if
server_pvc_data_autoexpansion
else
lookup('k8s', api_version='v1', kind='PersistentVolumeClaim', namespace=meta_namespace,
resource_name=server_pvc_data).spec.resources.requests.storage | default('1Gi')
server_pvc_data_current_size | default('1Gi', true)
}}"
server_pvc_data_size_gib: "{{ cr_status_properties[routine_pvc_autoexpand_info_keyname].autoexpandSizeGib
| default(server_pvc_data_autoexpansion_increment_gib) }}"
Expand Down
46 changes: 46 additions & 0 deletions roles/v1alpha1/nfs/server/tasks/resource/sts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,52 @@
set_fact:
server_sts_spec: "{{ lookup('template', server_sts_spec_template) }}"

# workaround for sts volume expansion until https://github.com/kubernetes/enhancements/pull/2842
- name: save (nfs) server statefulset pvc current and new sizes
set_fact:
server_sts_pvc_expansion_data_size: "{{ server_pvc_data_size }}"
server_sts_pvc_expansion_data_current_size: "{{ server_pvc_data_current_size }}"

- name: allow (nfs) server statefulset pvc expansion
when:
- server_sts_pvc_expansion_data_current_size is defined and server_sts_pvc_expansion_data_current_size
- server_sts_pvc_expansion_data_current_size != server_sts_pvc_expansion_data_size
- server_sts_pvc_expansion_list | length > 0
- "server_sts_state | default(server_state) != 'absent'"
vars:
server_sts_pvc_expansion_label_selector: "app={{ metadata_app }}"
server_sts_pvc_expansion_list: "{{ query('k8s', api_version='v1', kind='PersistentVolumeClaim',
namespace=meta_namespace,label_selector=server_sts_pvc_expansion_label_selector) | default([]) }}"
block:
- name: delete (nfs) server statefulset without removing pods and data
k8s:
state: absent
delete_options:
propagationPolicy: Orphan
definition:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: "{{ server_sts }}"
namespace: "{{ meta_namespace }}"
register: k8s_server_sts_delete_orphan_task

- name: patch (nfs) server statefulset pvc(s)
loop: "{{ server_sts_pvc_expansion_list }}"
k8s:
state: patched
definition:
apiVersion: "{{ item.apiVersion }}"
kind: "{{ item.kind }}"
metadata:
name: "{{ item.metadata.name }}"
namespace: "{{ item.metadata.namespace }}"
spec:
resources:
requests:
storage: "{{ server_sts_pvc_expansion_data_size }}"
###### end of workaround ######

- name: (nfs) server statefulset resource definition
vars:
k8s_kind: StatefulSet
Expand Down

0 comments on commit b96d799

Please sign in to comment.