Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

injector: add get for nodes in clusterrole #1005

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

Bugs:
* injector: add missing `get` `nodes` permission to ClusterRole [GH-1005](https://github.com/hashicorp/vault-helm/pull/1005)

## 0.27.0 (November 16, 2023)

Changes:
Expand Down
6 changes: 6 additions & 0 deletions templates/injector-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ rules:
- "list"
- "watch"
- "patch"
{{- if and (eq (.Values.injector.leaderElector.enabled | toString) "true") (gt (.Values.injector.replicas | int) 1) }}
- apiGroups: [""]
resources: ["nodes"]
verbs:
- "get"
{{ end }}
{{ end }}
30 changes: 30 additions & 0 deletions test/unit/injector-clusterrole.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,33 @@ load _helpers
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
}

@test "injector/ClusterRole: no nodes permissions when replicas=1" {
cd `chart_dir`
local rules=$(helm template \
--show-only templates/injector-clusterrole.yaml \
--set 'injector.replicas=1' \
. | tee /dev/stderr |
yq '.rules' | tee /dev/stderr)
rules_length=$(echo "${rules}" | yq 'length')
[ "${rules_length}" = "1" ]
resources_length=$(echo "${rules}" | yq '.[0].resources | length')
[ "${resources_length}" = "1" ]
resource=$(echo "${rules}" | yq -r '.[0].resources[0]')
[ "${resource}" = "mutatingwebhookconfigurations" ]
}

@test "injector/ClusterRole: nodes permissions when replicas=2" {
cd `chart_dir`
local rules=$(helm template \
--show-only templates/injector-clusterrole.yaml \
--set 'injector.replicas=2' \
. | tee /dev/stderr |
yq '.rules' | tee /dev/stderr)
rules_length=$(echo "${rules}" | yq 'length')
[ "${rules_length}" = "2" ]
resources_length=$(echo "${rules}" | yq '.[1].resources | length')
[ "${resources_length}" = "1" ]
resource=$(echo "${rules}" | yq -r '.[1].resources[0]')
[ "${resource}" = "nodes" ]
}
Loading