Update structure of local-path for install/remove

This commit is contained in:
Adrien Reslinger 2020-04-22 15:01:14 +02:00
parent aa28df3bf6
commit 7cb826a8f1
4 changed files with 32 additions and 121 deletions

View file

@ -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
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

View file

@ -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"]
}
]
}

27
tasks/local.yml Normal file
View file

@ -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"

View file

@ -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: