From b2cb0725ac4c22f69ebbcaa969d8414f8a54bea2 Mon Sep 17 00:00:00 2001 From: Stanislav Makar Date: Tue, 19 Dec 2017 16:47:00 +0200 Subject: [PATCH] Default OpenStack Cinder Storage Class (#2083) Add possibility to create default OpenStack Cinder Storage Class Closes: #1609 --- inventory/group_vars/k8s-cluster.yml | 3 +++ roles/kubernetes-apps/meta/main.yml | 5 +++++ .../persistent_volumes/meta/main.yml | 8 +++++++ .../openstack/defaults/main.yml | 2 ++ .../openstack/tasks/main.yml | 21 +++++++++++++++++++ .../templates/openstack-storage-class.yml | 9 ++++++++ roles/kubespray-defaults/defaults/main.yaml | 1 + 7 files changed, 49 insertions(+) create mode 100644 roles/kubernetes-apps/persistent_volumes/meta/main.yml create mode 100644 roles/kubernetes-apps/persistent_volumes/openstack/defaults/main.yml create mode 100644 roles/kubernetes-apps/persistent_volumes/openstack/tasks/main.yml create mode 100644 roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml diff --git a/inventory/group_vars/k8s-cluster.yml b/inventory/group_vars/k8s-cluster.yml index 800d9dbb9..f8210f291 100644 --- a/inventory/group_vars/k8s-cluster.yml +++ b/inventory/group_vars/k8s-cluster.yml @@ -159,6 +159,9 @@ istio_enabled: false # Local volume provisioner deployment local_volumes_enabled: false +# Add Persistent Volumes Storage Class for corresponding cloud provider ( OpenStack is only supported now ) +persistent_volumes_enabled: false + # Make a copy of kubeconfig on the host that runs Ansible in GITDIR/artifacts # kubeconfig_localhost: false # Download kubectl onto the host that runs Ansible in GITDIR/artifacts diff --git a/roles/kubernetes-apps/meta/main.yml b/roles/kubernetes-apps/meta/main.yml index 1cd093b33..bfcec80b4 100644 --- a/roles/kubernetes-apps/meta/main.yml +++ b/roles/kubernetes-apps/meta/main.yml @@ -33,3 +33,8 @@ dependencies: tags: - apps - istio + - role: kubernetes-apps/persistent_volumes + when: persistent_volumes_enabled + tags: + - apps + - persistent_volumes diff --git a/roles/kubernetes-apps/persistent_volumes/meta/main.yml b/roles/kubernetes-apps/persistent_volumes/meta/main.yml new file mode 100644 index 000000000..8a4855bff --- /dev/null +++ b/roles/kubernetes-apps/persistent_volumes/meta/main.yml @@ -0,0 +1,8 @@ +--- +dependencies: + - role: kubernetes-apps/persistent_volumes/openstack + when: + - cloud_provider is defined + - cloud_provider in [ 'openstack' ] + tags: + - persistent_volumes_openstack diff --git a/roles/kubernetes-apps/persistent_volumes/openstack/defaults/main.yml b/roles/kubernetes-apps/persistent_volumes/openstack/defaults/main.yml new file mode 100644 index 000000000..8553ec5e2 --- /dev/null +++ b/roles/kubernetes-apps/persistent_volumes/openstack/defaults/main.yml @@ -0,0 +1,2 @@ +--- +persistent_volumes_enabled: false diff --git a/roles/kubernetes-apps/persistent_volumes/openstack/tasks/main.yml b/roles/kubernetes-apps/persistent_volumes/openstack/tasks/main.yml new file mode 100644 index 000000000..e4d1b138c --- /dev/null +++ b/roles/kubernetes-apps/persistent_volumes/openstack/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: Kubernetes Persistent Volumes | Lay down OpenStack Cinder Storage Class template + template: + src: "{{item.file}}" + dest: "{{kube_config_dir}}/{{item.file}}" + with_items: + - {file: openstack-storage-class.yml, type: StorageClass, name: storage-class } + register: manifests + when: + - inventory_hostname == groups['kube-master'][0] + +- name: Kubernetes Persistent Volumes | Add OpenStack Cinder Storage Class + kube: + name: "{{item.item.name}}" + kubectl: "{{bin_dir}}/kubectl" + resource: "{{item.item.type}}" + filename: "{{kube_config_dir}}/{{item.item.file}}" + state: "latest" + with_items: "{{ manifests.results }}" + when: + - inventory_hostname == groups['kube-master'][0] diff --git a/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml b/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml new file mode 100644 index 000000000..c643cfa09 --- /dev/null +++ b/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml @@ -0,0 +1,9 @@ +kind: StorageClass +apiVersion: storage.k8s.io/v1 +metadata: + name: standard + annotations: + storageclass.kubernetes.io/is-default-class: "true" +provisioner: kubernetes.io/cinder +parameters: + availability: nova diff --git a/roles/kubespray-defaults/defaults/main.yaml b/roles/kubespray-defaults/defaults/main.yaml index ec928b298..579eb7b83 100644 --- a/roles/kubespray-defaults/defaults/main.yaml +++ b/roles/kubespray-defaults/defaults/main.yaml @@ -144,6 +144,7 @@ helm_enabled: false istio_enabled: false enable_network_policy: false local_volumes_enabled: false +persistent_volumes_enabled: false # Base path for local volume provisioner addon local_volume_base_dir: /mnt/disks