From 7cb826a8f12cb8923434ad07c0ae74a205b1a094 Mon Sep 17 00:00:00 2001 From: Adrien Reslinger Date: Wed, 22 Apr 2020 15:01:14 +0200 Subject: [PATCH] Update structure of local-path for install/remove --- bin/gen_list.sh | 5 +- files/local-path-storage_20200316.yaml | 105 ------------------------- tasks/local.yml | 27 +++++++ tasks/main.yml | 16 +--- 4 files changed, 32 insertions(+), 121 deletions(-) delete mode 100644 files/local-path-storage_20200316.yaml create mode 100644 tasks/local.yml diff --git a/bin/gen_list.sh b/bin/gen_list.sh index 07e0584..d748d5c 100755 --- a/bin/gen_list.sh +++ b/bin/gen_list.sh @@ -1,6 +1,9 @@ #!/bin/bash wget https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml kubernetes-split-yaml local-path-storage.yaml > generated.log +mv local{,.old} mv generated local cat generated.log | while read LIGNE; do if [ $(echo "${LIGNE}" | grep -c ^File) -eq 1 ]; then echo -n "${LIGNE} "; else echo "${LIGNE}"; fi; done | grep ^File | sort -V | sed 's|.*\(generated/\)\(.*\.yaml\)| - "local/\2"|' -sed 's|/opt/local-path-provisioner|/mnt/shared|' -i local/local-path-config-ConfigMap.yaml \ No newline at end of file +sed 's|/opt/local-path-provisioner|/mnt/local|' -i local/local-path-config-ConfigMap.yaml +#mv local-path-storage.yaml local-path-storage_$(date +%Y%m%d).yaml +rm -fr local.old generated.log local-path-storage.yaml diff --git a/files/local-path-storage_20200316.yaml b/files/local-path-storage_20200316.yaml deleted file mode 100644 index d83c368..0000000 --- a/files/local-path-storage_20200316.yaml +++ /dev/null @@ -1,105 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: local-path-storage ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: local-path-provisioner-service-account - namespace: local-path-storage ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: local-path-provisioner-role -rules: -- apiGroups: [""] - resources: ["nodes", "persistentvolumeclaims"] - verbs: ["get", "list", "watch"] -- apiGroups: [""] - resources: ["endpoints", "persistentvolumes", "pods"] - verbs: ["*"] -- apiGroups: [""] - resources: ["events"] - verbs: ["create", "patch"] -- apiGroups: ["storage.k8s.io"] - resources: ["storageclasses"] - verbs: ["get", "list", "watch"] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: local-path-provisioner-bind -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: local-path-provisioner-role -subjects: -- kind: ServiceAccount - name: local-path-provisioner-service-account - namespace: local-path-storage ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: local-path-provisioner - namespace: local-path-storage -spec: - replicas: 1 - selector: - matchLabels: - app: local-path-provisioner - template: - metadata: - labels: - app: local-path-provisioner - spec: - serviceAccountName: local-path-provisioner-service-account - containers: - - name: local-path-provisioner - image: rancher/local-path-provisioner:v0.0.12 - imagePullPolicy: IfNotPresent - command: - - local-path-provisioner - - --debug - - start - - --config - - /etc/config/config.json - volumeMounts: - - name: config-volume - mountPath: /etc/config/ - env: - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - volumes: - - name: config-volume - configMap: - name: local-path-config ---- -apiVersion: storage.k8s.io/v1 -kind: StorageClass -metadata: - name: local-path -provisioner: rancher.io/local-path -volumeBindingMode: WaitForFirstConsumer -reclaimPolicy: Delete ---- -kind: ConfigMap -apiVersion: v1 -metadata: - name: local-path-config - namespace: local-path-storage -data: - config.json: |- - { - "nodePathMap":[ - { - "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES", - "paths":["/opt/local-path-provisioner"] - } - ] - } - diff --git a/tasks/local.yml b/tasks/local.yml new file mode 100644 index 0000000..af99df0 --- /dev/null +++ b/tasks/local.yml @@ -0,0 +1,27 @@ +--- + - name: Defined local-path-storage state to present + set_fact: + storage_localpath_state: present + when: + - storage_localpath|bool + + - name: find state of local-path-storage + set_fact: + storage_localpath_state: absent + when: + - not storage_localpath|bool + + - name: local-path-storage need to be {{ storage_localpath_state }} + k8s: + state: "{{ storage_localpath_state }}" + context: "{{ my_context }}" + merge_type: merge + resource_definition: "{{ lookup('file', item) | from_yaml }}" + with_items: + - "local/local-path-storage-Namespace.yaml" + - "local/local-path-provisioner-service-account-ServiceAccount.yaml" + - "local/local-path-provisioner-role-ClusterRole.yaml" + - "local/local-path-provisioner-bind-ClusterRoleBinding.yaml" + - "local/local-path-provisioner-Deployment.yaml" + - "local/local-path-StorageClass.yaml" + - "local/local-path-config-ConfigMap.yaml" diff --git a/tasks/main.yml b/tasks/main.yml index efad415..606cf9f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,20 +1,6 @@ - name: Local Path setup block: - - name: local-path-storage install - k8s: - state: present - context: "{{ my_context }}" - resource_definition: "{{ lookup('file', item) | from_yaml }}" - with_items: - - "local/local-path-storage-Namespace.yaml" - - "local/local-path-provisioner-service-account-ServiceAccount.yaml" - - "local/local-path-provisioner-role-ClusterRole.yaml" - - "local/local-path-provisioner-bind-ClusterRoleBinding.yaml" - - "local/local-path-provisioner-Deployment.yaml" - - "local/local-path-StorageClass.yaml" - - "local/local-path-config-ConfigMap.yaml" - when: - - storage_localpath == true + - include_tasks: "local.yml" - name: Select the default StorageClass k8s: