diff options
Diffstat (limited to 'ansible/roles/k8s-persistent-volume')
7 files changed, 93 insertions, 0 deletions
diff --git a/ansible/roles/k8s-persistent-volume/.yamllint b/ansible/roles/k8s-persistent-volume/.yamllint new file mode 100644 index 00000000..c5ae64be --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/.yamllint @@ -0,0 +1,12 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/k8s-persistent-volume/defaults/main.yml b/ansible/roles/k8s-persistent-volume/defaults/main.yml new file mode 100644 index 00000000..de387323 --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/defaults/main.yml @@ -0,0 +1,10 @@ +--- +k8s_volumes: + - name: kube-prometheus-prometheus + capacity: "6Gi" + path_prefix: "{{ nfs_mount_path }}/kube-prometheus" + owner: 1000 # derived from prometheus.prometheusSpec.securityContext.runAsUser + group: 2000 # derived from prometheus.prometheusSpec.securityContext.fsGroup + - name: kube-prometheus-grafana + capacity: "4Gi" + path_prefix: "{{ nfs_mount_path }}/kube-prometheus" diff --git a/ansible/roles/k8s-persistent-volume/molecule/default/converge.yml b/ansible/roles/k8s-persistent-volume/molecule/default/converge.yml new file mode 100644 index 00000000..4e15b3c8 --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/molecule/default/converge.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + pre_tasks: + - name: Include kubernetes group variables + include_vars: ../../../../group_vars/kubernetes.yml + - name: Include test scenario variables + include_vars: vars.yml + tasks: + - name: "Include k8s-persistent-volume" + include_role: + name: "k8s-persistent-volume" diff --git a/ansible/roles/k8s-persistent-volume/molecule/default/molecule.yml b/ansible/roles/k8s-persistent-volume/molecule/default/molecule.yml new file mode 100644 index 00000000..dbbf0d81 --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/molecule/default/molecule.yml @@ -0,0 +1,23 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint . + flake8 +platforms: + - name: infrastructure-k8s-persistent-volume + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + groups: + - infrastructure +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + ANSIBLE_LIBRARY: ../../../../library +verifier: + name: testinfra diff --git a/ansible/roles/k8s-persistent-volume/molecule/default/vars.yml b/ansible/roles/k8s-persistent-volume/molecule/default/vars.yml new file mode 100644 index 00000000..ce473376 --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/molecule/default/vars.yml @@ -0,0 +1,2 @@ +--- +k8s_volumes: [] diff --git a/ansible/roles/k8s-persistent-volume/tasks/main.yml b/ansible/roles/k8s-persistent-volume/tasks/main.yml new file mode 100644 index 00000000..8428857f --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: Install OpenShift Python client library # community.kubernetes.k8s module dependency + package: + name: 'python2-openshift' + state: present + +- name: Create k8s persistent volumes + community.kubernetes.k8s: + wait: True + template: pv.yaml.j2 + loop: "{{ k8s_volumes }}" + +- name: Create host paths for PVs and set their permissions + file: + path: "{{ item.path_prefix }}/{{ item.name }}" + state: directory + owner: "{{ item.owner | default(0) }}" + group: "{{ item.group | default(0) }}" + loop: "{{ k8s_volumes }}" diff --git a/ansible/roles/k8s-persistent-volume/templates/pv.yaml.j2 b/ansible/roles/k8s-persistent-volume/templates/pv.yaml.j2 new file mode 100644 index 00000000..979ef2c6 --- /dev/null +++ b/ansible/roles/k8s-persistent-volume/templates/pv.yaml.j2 @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ item.name }} +spec: + capacity: + storage: {{ item.capacity }} + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: {{ item.name }} + hostPath: + path: {{ item.path_prefix }}/{{ item.name }} + type: "" |