From 9a59ef1257cefa23b26973e5f48917224c093f33 Mon Sep 17 00:00:00 2001 From: Lize Cai Date: Mon, 18 Nov 2024 18:54:15 +0800 Subject: [PATCH 1/3] allow parameterize storageClass.provisioner Signed-off-by: Lize Cai --- helm/README.md | 1 + helm/provisioner/templates/storageclass.yaml | 6 +++++- helm/provisioner/values.yaml | 12 ++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/helm/README.md b/helm/README.md index b4182d2a1..bfd187b6e 100644 --- a/helm/README.md +++ b/helm/README.md @@ -142,6 +142,7 @@ provisioner chart and their default values. | classes.[n].storageClass | Create storage class for this class and configure it optionally. | bool/map | `false` | | classes.[n].storageClass.reclaimPolicy | Specify reclaimPolicy of storage class, available: Delete/Retain. | str | `Delete` | | classes.[n].storageClass.isDefaultClass | Set storage class as default | bool | `false` | +| classes.[n].storageClass.provisioner | Specify provisioner of storage class. | str | `kubernetes.io/no-provisioner` | | podAnnotations | Annotations for each Pod in the DaemonSet. | map | `-` | | podLabels | Labels for each Pod in the DaemonSet. | map | `-` | | image | Provisioner image. | str | `registry.k8s.io/sig-storage/local-volume-provisioner:v2.5.0` | diff --git a/helm/provisioner/templates/storageclass.yaml b/helm/provisioner/templates/storageclass.yaml index 937dd5b0e..bec690f0c 100644 --- a/helm/provisioner/templates/storageclass.yaml +++ b/helm/provisioner/templates/storageclass.yaml @@ -16,7 +16,11 @@ metadata: app.kubernetes.io/name: {{ template "provisioner.name" $ }} app.kubernetes.io/managed-by: {{ $.Release.Service }} app.kubernetes.io/instance: {{ $.Release.Name }} -provisioner: kubernetes.io/no-provisioner +{{- if kindIs "map" $val.storageClass }} +provisioner: {{ $val.storageClass.provisioner | default "kubernetes.io/no-provisioner" }} +{{- else }} +provisioner: "kubernetes.io/no-provisioner" +{{- end }} volumeBindingMode: WaitForFirstConsumer {{- if kindIs "map" $val.storageClass }} reclaimPolicy: {{ $val.storageClass.reclaimPolicy | default "Delete" }} diff --git a/helm/provisioner/values.yaml b/helm/provisioner/values.yaml index 4f94321ad..576c8e25d 100644 --- a/helm/provisioner/values.yaml +++ b/helm/provisioner/values.yaml @@ -82,12 +82,16 @@ classes: - "2" # or blkdiscard utility by uncommenting the line below. # - "/scripts/blkdiscard.sh" - # Uncomment to create storage class object with default configuration. - # storageClass: true - # Uncomment to create storage class object and configure it. - # storageClass: + # Uncomment to create storage class object with default configuration. + # storageClass: true + # Uncomment to create storage class object and configure it. + # storageClass: # reclaimPolicy: Delete # Available reclaim policies: Delete/Retain, defaults: Delete. # isDefaultClass: true # set as default class + # If you are using cluster autoscaler to scale the workload using volume provisioned by this storage class, + # set the provisioner of the storage class to another value other than the default. + # Ref: https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner/issues/288 + # provisioner: kubernetes.io/no-provisioner # Defines annotations for each Pod in the DaemonSet. podAnnotations: {} From 9a440aa8b62825304c46d1f93b95af3c326800f9 Mon Sep 17 00:00:00 2001 From: Lize Cai Date: Mon, 18 Nov 2024 19:51:05 +0800 Subject: [PATCH 2/3] remove quote and add example Signed-off-by: Lize Cai --- helm/README.md | 1 + helm/examples/baremetal-provisioner.yaml | 8 + .../baremetal-provisioner.yaml | 158 ++++++++++++++++++ helm/provisioner/templates/storageclass.yaml | 2 +- 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 helm/examples/baremetal-provisioner.yaml create mode 100644 helm/generated_examples/baremetal-provisioner.yaml diff --git a/helm/README.md b/helm/README.md index bfd187b6e..4b8c07f49 100644 --- a/helm/README.md +++ b/helm/README.md @@ -172,6 +172,7 @@ Here are a list of examples for various environments: * [examples/baremetal-cleanbyjobs.yaml](examples/baremetal-cleanbyjobs.yaml) * [examples/baremetal-resyncperiod.yaml](examples/baremetal-resyncperiod.yaml) * [examples/baremetal-tolerations.yaml](examples/baremetal-tolerations.yaml) +* [examples/baremetal-provisioner.yaml](examples/baremetal-provisioner.yaml) * [examples/baremetal-with-resource-limits.yaml](examples/baremetal-with-resource-limits.yaml) * [examples/baremetal-without-rbac.yaml](examples/baremetal-without-rbac.yaml) * [examples/baremetal.yaml](examples/baremetal.yaml) diff --git a/helm/examples/baremetal-provisioner.yaml b/helm/examples/baremetal-provisioner.yaml new file mode 100644 index 000000000..6deb08878 --- /dev/null +++ b/helm/examples/baremetal-provisioner.yaml @@ -0,0 +1,8 @@ +classes: +- name: local-storage + hostDir: /mnt/disks + blockCleanerCommand: + - "/scripts/quick_reset.sh" + volumeMode: Block + storageClass: + provisioner: "local-provisioner" \ No newline at end of file diff --git a/helm/generated_examples/baremetal-provisioner.yaml b/helm/generated_examples/baremetal-provisioner.yaml new file mode 100644 index 000000000..0328f129e --- /dev/null +++ b/helm/generated_examples/baremetal-provisioner.yaml @@ -0,0 +1,158 @@ +--- +# Source: local-static-provisioner/templates/serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: local-static-provisioner + namespace: default + labels: + helm.sh/chart: local-static-provisioner-2.0.0 + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/instance: local-static-provisioner +--- +# Source: local-static-provisioner/templates/configmap.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: local-static-provisioner-config + namespace: default + labels: + helm.sh/chart: local-static-provisioner-2.0.0 + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/instance: local-static-provisioner +data: + storageClassMap: | + local-storage: + hostDir: /mnt/disks + mountDir: /mnt/disks + blockCleanerCommand: + - "/scripts/quick_reset.sh" + volumeMode: Block +--- +# Source: local-static-provisioner/templates/storageclass.yaml +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: local-storage + labels: + helm.sh/chart: local-static-provisioner-2.0.0 + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/instance: local-static-provisioner +provisioner: local-provisioner +volumeBindingMode: WaitForFirstConsumer +reclaimPolicy: Delete +--- +# Source: local-static-provisioner/templates/rbac.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: local-static-provisioner-node-clusterrole + labels: + helm.sh/chart: local-static-provisioner-2.0.0 + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/instance: local-static-provisioner +rules: +- apiGroups: [""] + resources: ["persistentvolumes"] + verbs: ["get", "list", "watch", "create", "delete"] +- apiGroups: ["storage.k8s.io"] + resources: ["storageclasses"] + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: ["events"] + verbs: ["watch"] +- apiGroups: ["", "events.k8s.io"] + resources: ["events"] + verbs: ["create", "update", "patch"] +- apiGroups: [""] + resources: ["nodes"] + verbs: ["get"] +--- +# Source: local-static-provisioner/templates/rbac.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: local-static-provisioner-node-binding + labels: + helm.sh/chart: local-static-provisioner-2.0.0 + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/instance: local-static-provisioner +subjects: +- kind: ServiceAccount + name: local-static-provisioner + namespace: default +roleRef: + kind: ClusterRole + name: local-static-provisioner-node-clusterrole + apiGroup: rbac.authorization.k8s.io +--- +# Source: local-static-provisioner/templates/daemonset_linux.yaml +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: local-static-provisioner + namespace: default + labels: + helm.sh/chart: local-static-provisioner-2.0.0 + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/instance: local-static-provisioner +spec: + selector: + matchLabels: + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/instance: local-static-provisioner + template: + metadata: + labels: + app.kubernetes.io/name: local-static-provisioner + app.kubernetes.io/instance: local-static-provisioner + annotations: + checksum/config: ab47134c2d9ee94cf8fc7f8a5a8dc9e51c2ab005a6ce67ff013328751015dec8 + spec: + serviceAccountName: local-static-provisioner + nodeSelector: + kubernetes.io/os: linux + containers: + - name: provisioner + image: registry.k8s.io/sig-storage/local-volume-provisioner:v2.6.0 + securityContext: + privileged: true + env: + - name: MY_NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: MY_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: JOB_CONTAINER_IMAGE + value: registry.k8s.io/sig-storage/local-volume-provisioner:v2.6.0 + ports: + - name: metrics + containerPort: 8080 + volumeMounts: + - name: provisioner-config + mountPath: /etc/provisioner/config + readOnly: true + - name: provisioner-dev + mountPath: /dev + - name: local-storage + mountPath: /mnt/disks + mountPropagation: HostToContainer + volumes: + - name: provisioner-config + configMap: + name: local-static-provisioner-config + - name: provisioner-dev + hostPath: + path: /dev + - name: local-storage + hostPath: + path: /mnt/disks diff --git a/helm/provisioner/templates/storageclass.yaml b/helm/provisioner/templates/storageclass.yaml index bec690f0c..812f2969a 100644 --- a/helm/provisioner/templates/storageclass.yaml +++ b/helm/provisioner/templates/storageclass.yaml @@ -19,7 +19,7 @@ metadata: {{- if kindIs "map" $val.storageClass }} provisioner: {{ $val.storageClass.provisioner | default "kubernetes.io/no-provisioner" }} {{- else }} -provisioner: "kubernetes.io/no-provisioner" +provisioner: kubernetes.io/no-provisioner {{- end }} volumeBindingMode: WaitForFirstConsumer {{- if kindIs "map" $val.storageClass }} From 979859671cd72a327799d8ec34ebc3af70ef4e2a Mon Sep 17 00:00:00 2001 From: Lize Cai Date: Mon, 18 Nov 2024 19:53:07 +0800 Subject: [PATCH 3/3] add new line Signed-off-by: Lize Cai --- helm/examples/baremetal-provisioner.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/examples/baremetal-provisioner.yaml b/helm/examples/baremetal-provisioner.yaml index 6deb08878..ba93bb460 100644 --- a/helm/examples/baremetal-provisioner.yaml +++ b/helm/examples/baremetal-provisioner.yaml @@ -5,4 +5,4 @@ classes: - "/scripts/quick_reset.sh" volumeMode: Block storageClass: - provisioner: "local-provisioner" \ No newline at end of file + provisioner: "local-provisioner"