|
38 | 38 | log = logging.getLogger("assess_caas_charm_deployment") |
39 | 39 |
|
40 | 40 | JUJU_STORAGECLASS_NAME = "juju-storageclass" |
41 | | -JUJU_PV_TEMPLATE = """ |
42 | | -kind: PersistentVolume |
| 41 | +HOST_PATH_PROVISIONER = """ |
43 | 42 | apiVersion: v1 |
| 43 | +kind: ServiceAccount |
44 | 44 | metadata: |
45 | | - name: {model}-data |
46 | | -spec: |
47 | | - capacity: |
48 | | - storage: 100Mi |
49 | | - accessModes: |
50 | | - - ReadWriteOnce |
51 | | - persistentVolumeReclaimPolicy: Retain |
52 | | - storageClassName: {class_name} |
53 | | - hostPath: |
54 | | - path: "/mnt/data/{model}" |
55 | | -""" |
| 45 | + name: hostpath-provisioner |
| 46 | + namespace: kube-system |
| 47 | +--- |
56 | 48 |
|
57 | | -JUJU_STORAGECLASS_TEMPLATE = """ |
| 49 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 50 | +kind: ClusterRole |
| 51 | +metadata: |
| 52 | + name: hostpath-provisioner |
| 53 | + namespace: kube-system |
| 54 | +rules: |
| 55 | + - apiGroups: [""] |
| 56 | + resources: ["persistentvolumes"] |
| 57 | + verbs: ["get", "list", "watch", "create", "delete"] |
| 58 | + - apiGroups: [""] |
| 59 | + resources: ["persistentvolumeclaims"] |
| 60 | + verbs: ["get", "list", "watch", "update"] |
| 61 | + - apiGroups: ["storage.k8s.io"] |
| 62 | + resources: ["storageclasses"] |
| 63 | + verbs: ["get", "list", "watch"] |
| 64 | + - apiGroups: [""] |
| 65 | + resources: ["events"] |
| 66 | + verbs: ["list", "watch", "create", "update", "patch"] |
| 67 | +--- |
| 68 | +
|
| 69 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 70 | +kind: ClusterRoleBinding |
| 71 | +metadata: |
| 72 | + name: hostpath-provisioner |
| 73 | + namespace: kube-system |
| 74 | +subjects: |
| 75 | + - kind: ServiceAccount |
| 76 | + name: hostpath-provisioner |
| 77 | + namespace: kube-system |
| 78 | +roleRef: |
| 79 | + kind: ClusterRole |
| 80 | + name: hostpath-provisioner |
| 81 | + apiGroup: rbac.authorization.k8s.io |
| 82 | +--- |
| 83 | +
|
| 84 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 85 | +kind: Role |
| 86 | +metadata: |
| 87 | + name: hostpath-provisioner |
| 88 | + namespace: kube-system |
| 89 | +rules: |
| 90 | + - apiGroups: [""] |
| 91 | + resources: ["secrets"] |
| 92 | + verbs: ["create", "get", "delete"] |
| 93 | +--- |
| 94 | +
|
| 95 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 96 | +kind: RoleBinding |
| 97 | +metadata: |
| 98 | + name: hostpath-provisioner |
| 99 | + namespace: kube-system |
| 100 | +roleRef: |
| 101 | + apiGroup: rbac.authorization.k8s.io |
| 102 | + kind: Role |
| 103 | + name: hostpath-provisioner |
| 104 | +subjects: |
| 105 | + - kind: ServiceAccount |
| 106 | + name: hostpath-provisioner |
| 107 | +--- |
| 108 | +
|
| 109 | +# -- Create a daemon set for web requests and send them to the nginx-ingress-controller |
| 110 | +apiVersion: extensions/v1beta1 |
| 111 | +kind: DaemonSet |
| 112 | +metadata: |
| 113 | + name: hostpath-provisioner |
| 114 | + namespace: kube-system |
| 115 | +spec: |
| 116 | + revisionHistoryLimit: 3 |
| 117 | + template: |
| 118 | + metadata: |
| 119 | + labels: |
| 120 | + app: hostpath-provisioner |
| 121 | + spec: |
| 122 | + serviceAccountName: hostpath-provisioner |
| 123 | + terminationGracePeriodSeconds: 0 |
| 124 | + containers: |
| 125 | + - name: hostpath-provisioner |
| 126 | + image: mazdermind/hostpath-provisioner:latest |
| 127 | + imagePullPolicy: "IfNotPresent" |
| 128 | + env: |
| 129 | + - name: NODE_NAME |
| 130 | + valueFrom: |
| 131 | + fieldRef: |
| 132 | + fieldPath: spec.nodeName |
| 133 | + - name: PV_DIR |
| 134 | + value: /mnt/kubernetes |
| 135 | + volumeMounts: |
| 136 | + - name: pv-volume |
| 137 | + mountPath: /mnt/kubernetes |
| 138 | + volumes: |
| 139 | + - name: pv-volume |
| 140 | + hostPath: |
| 141 | + path: /mnt/kubernetes |
| 142 | +--- |
| 143 | +
|
| 144 | +# -- Create the standard storage class for running on-node hostpath storage |
58 | 145 | apiVersion: storage.k8s.io/v1 |
59 | 146 | kind: StorageClass |
60 | 147 | metadata: |
61 | | - namespace: {model} |
| 148 | + # namespace: kube-system |
62 | 149 | name: {class_name} |
63 | 150 | annotations: |
64 | | - storageclass.kubernetes.io/is-default-class: "true" |
| 151 | + storageclass.beta.kubernetes.io/is-default-class: "true" |
65 | 152 | labels: |
| 153 | + kubernetes.io/cluster-service: "true" |
66 | 154 | addonmanager.kubernetes.io/mode: EnsureExists |
67 | | -provisioner: kubernetes.io/host-path |
| 155 | +provisioner: hostpath |
| 156 | +--- |
68 | 157 | """ |
69 | 158 |
|
70 | 159 |
|
@@ -100,16 +189,15 @@ def assess_caas_charm_deployment(client): |
100 | 189 | model_name = 'testcaas' |
101 | 190 | k8s_model = caas_client.add_model(model_name) |
102 | 191 |
|
103 | | - # ensure storage class |
104 | | - caas_client.kubectl_apply(JUJU_STORAGECLASS_TEMPLATE.format(model=model_name, class_name=JUJU_STORAGECLASS_NAME)) |
105 | | - caas_client.kubectl_apply(JUJU_PV_TEMPLATE.format(model=model_name, class_name=JUJU_STORAGECLASS_NAME)) |
106 | | - |
107 | 192 | # ensure tmp dir for storage class.model_name |
108 | 193 | o = subprocess.check_output( |
109 | | - ('sudo', 'mkdir', '-p', '/mnt/data/%s' % model_name) # unfortunately, needs sudo |
| 194 | + ('sudo', 'mkdir', '-p', '/mnt/kubernetes/%s' % model_name) # unfortunately, needs sudo |
110 | 195 | ) |
111 | 196 | log.debug(o.decode('UTF-8').strip()) |
112 | 197 |
|
| 198 | + # ensure storage class |
| 199 | + caas_client.kubectl_apply(HOST_PATH_PROVISIONER.format(class_name=JUJU_STORAGECLASS_NAME)) |
| 200 | + |
113 | 201 | # ensure storage pool |
114 | 202 | k8s_model.juju( |
115 | 203 | 'create-storage-pool', |
|
0 commit comments