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

Prevent using reserved names for ns's/partitions #846

Merged
merged 2 commits into from
Nov 8, 2021

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented Nov 5, 2021

Some names are reserved by Consul and can't be used for namespaces or
partitions. Catching this early before the helm install is a better UX
than having the install fail (in the case of partitions) or succeed (in
the case of namespaces) and then fail during syncing or injection.

This code uses some tricks:

  1. The code for failing on reserved names is extracted into a helper template so it can be re-used in other templates
  2. The test code uses a helper function so there's less duplication in the tests

Fixes #593

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

Some names are reserved by Consul and can't be used for namespaces or
partitions. Catching this early before the helm install is a better UX
than having the install fail (in the case of partitions) or succeed (in
the case of namespaces) and then fail during syncing or injection.
{{- if or (eq "system" $name) (eq "universal" $name) (eq "consul" $name) (eq "operator" $name) (eq "root" $name) }}
{{- fail (cat "The name" $name "set for key" $key "is reserved by Consul for future use." ) }}
{{- end }}
{{- end -}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes:

  • See template docs for how it works
  • I'm using cat inside fail to get those values interpolated into the error string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

@lkysow lkysow requested review from a team, ishustava and thisisnotashwin and removed request for a team November 5, 2021 17:03
@lkysow lkysow marked this pull request as ready for review November 5, 2021 17:03
{{- if or (eq "system" $name) (eq "universal" $name) (eq "consul" $name) (eq "operator" $name) (eq "root" $name) }}
{{- fail (cat "The name" $name "set for key" $key "is reserved by Consul for future use." ) }}
{{- end }}
{{- end -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAICE!

Comment on lines +1542 to +1552
cd `chart_dir`
local -r name="$1"
run helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set "connectInject.consulNamespaces.consulDestinationNamespace=$name" .

[ "$status" -eq 1 ]
[[ "$output" =~ "The name $name set for key connectInject.consulNamespaces.consulDestinationNamespace is reserved by Consul for future use" ]]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

@lkysow lkysow merged commit 9e20ed1 into main Nov 8, 2021
@lkysow lkysow deleted the lkysow/reserved-namespaces branch November 8, 2021 18:10
rrondeau pushed a commit to rrondeau/consul-k8s that referenced this pull request Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add validation to ConnectInject Consul destination namespace
3 participants