Skip to content

Commit

Permalink
feat(csi): make provider hostPaths configurable (hashicorp#603)
Browse files Browse the repository at this point in the history
*  add configurable values for providersDir and kubeletRootDir

Signed-off-by: Toni Tauro <[email protected]>

Co-authored-by: Ben Ash <[email protected]>
  • Loading branch information
2 people authored and illegalnumbers committed Mar 16, 2022
1 parent 67f330a commit 4632d8d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions templates/csi-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ spec:
volumes:
- name: providervol
hostPath:
path: "/etc/kubernetes/secrets-store-csi-providers"
path: {{ .Values.csi.daemonSet.providersDir }}
- name: mountpoint-dir
hostPath:
path: /var/lib/kubelet/pods
path: {{ .Values.csi.daemonSet.kubeletRootDir }}/pods
{{- if .Values.csi.volumes }}
{{- toYaml .Values.csi.volumes | nindent 8}}
{{- end }}
Expand Down
62 changes: 62 additions & 0 deletions test/unit/csi-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,68 @@ load _helpers
[ "${actual}" = "{}" ]
}

@test "csi/daemonset: csi providersDir default" {
cd `chart_dir`

# Test that it defines it
local object=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.volumes[] | select(.name == "providervol")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.hostPath.path' | tee /dev/stderr)
[ "${actual}" = "/etc/kubernetes/secrets-store-csi-providers" ]
}

@test "csi/daemonset: csi kubeletRootDir default" {
cd `chart_dir`

# Test that it defines it
local object=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.volumes[] | select(.name == "mountpoint-dir")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.hostPath.path' | tee /dev/stderr)
[ "${actual}" = "/var/lib/kubelet/pods" ]
}

@test "csi/daemonset: csi providersDir override " {
cd `chart_dir`

# Test that it defines it
local object=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set 'csi.daemonSet.providersDir=/alt/csi-prov-dir' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.volumes[] | select(.name == "providervol")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.hostPath.path' | tee /dev/stderr)
[ "${actual}" = "/alt/csi-prov-dir" ]
}

@test "csi/daemonset: csi kubeletRootDir override" {
cd `chart_dir`

# Test that it defines it
local object=$(helm template \
--show-only templates/csi-daemonset.yaml \
--set 'csi.enabled=true' \
--set 'csi.daemonSet.kubeletRootDir=/alt/kubelet-root' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.volumes[] | select(.name == "mountpoint-dir")' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.hostPath.path' | tee /dev/stderr)
[ "${actual}" = "/alt/kubelet-root/pods" ]
}

#--------------------------------------------------------------------
# volumeMounts

Expand Down
6 changes: 6 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"type": "string"
}
}
},
"providersDir": {
"type": "string"
},
"kubeletRootDir": {
"type": "string"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,10 @@ csi:
# YAML-formatted multi-line templated string map of the annotations to apply
# to the daemonSet.
annotations: {}
# Provider host path (must match the CSI provider's path)
providersDir: "/etc/kubernetes/secrets-store-csi-providers"
# Kubelet host path
kubeletRootDir: "/var/lib/kubelet"

pod:
# Extra annotations for the provider pods. This can either be YAML or a
Expand Down

0 comments on commit 4632d8d

Please sign in to comment.