Sanitize namespace flag consistently #220
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This plugin accepts a
namespace
var and creates a K8s namespace using that value. K8s namespaces must contain only lowercase alphanumeric characters and dashes, and begin with an alphanumeric character (reference).To handle the possibility that users will provide values for
namespace
that are invalid as K8s namespace names, the plugin sanitizes the value before creating the namespace. This ensures that namespace creation does not fail due to an invalid name.However, when the plugin calls
kubectl rollout
, it passes the unsanitized, user-provided namespace value. As a result, if thenamespace
var required sanitization to be a valid K8s namespace name, the rollout command will specify a namespace that does not exist, and will fail with the message:Fix
I see two options here:
namespace
values that are not valid K8s namespaces.I've implemented (2) in
checkParams
.I prefer approach because it allows the most flexibility for users. For instance, a common usage pattern is to pass the git branch name as the drone-gke namespace value. Branch names can have capital letters and other characters not allowed in K8s branch names. Option (2) allows users to continue the practice of using branch names without having to restrict the characters they can use in their git branches.
PR Form
If this is a change to the core functionality, did you make a corresponding PR to drone-eks?
https://github.com/nytimes/drone-eks/pull/75
Did you update the tests?
Did you update the docs?