fix labels and taints with spaced value for packet, aws, tinkerbell - #1291
Kautilya Tripathi (knrt10) wants to merge 3 commits into
Conversation
Now user cannot have spaced key or value in labels, taints map for worker pools. Add tests.
Now user cannot have spaced key or value in labels, taints map for worker pools. Add tests.
Now user cannot have spaced key or value in labels, taints map for worker pools. Add tests. closes: #1280
| // checkWorkerPoolLabelsAndTaints verifies that all worker pool labels | ||
| // and taints are in correct format. Neither key nor value of labels | ||
| // and taints map should have empty space in them. | ||
| func (c *config) checkWorkerPoolLabelsAndTaints() hcl.Diagnostics { |
There was a problem hiding this comment.
I'd extend platform.WorkerPool interface and add generic validation for it so we don't duplicate code for each platform.
|
|
||
| for _, w := range c.WorkerPools { | ||
| for k, v := range w.Labels { | ||
| if strings.Contains(k, " ") || strings.Contains(v, " ") { |
There was a problem hiding this comment.
What if I put tab character in key or value? I think we should also validate that.
| diagnostics = append(diagnostics, c.checkWorkerPoolNamesUnique()...) | ||
| diagnostics = append(diagnostics, c.checkReservationIDs()...) | ||
| diagnostics = append(diagnostics, c.validateOSVersion()...) | ||
| diagnostics = append(diagnostics, c.checkWorkerPoolLabelsAndTaints()...) |
There was a problem hiding this comment.
Suggestion to improve commit messages:
- We do not fix anything here, but we add new validation rule, so commit message should reflect that.
- Your commit message does not explain why user cannot have whitespace characters in labels or taints.
- Your commit message only mentiones spaces, while we care about all whitespace characters.
- Commit message should briefly explain what it adds.
- Commit message should include issue reference to make it easier to find context for it, otherwise one needs
to look for associated merge commit later.
-Packet: fix labels and taints with spaced value
+packet: add labels and taints validation against whitespace
-Now user cannot have spaced key or value in labels, taints map for
-worker pools.
-Add tests.
+Currently if user adds whitespace characters to labels or taints, it breaks the cluster
+provisioning, as labels and taints are not allowed to contain whitespace.
+To fail early on such cases, this commit adds validation rules, so error is returned to
+ the user before cluster provisioning starts.
+Refs #X| } | ||
| } | ||
|
|
||
| func TestCheckWorkerPoolLabelsWithSpacedValue(t *testing.T) { |
There was a problem hiding this comment.
We already have TestCheckValidConfig which starts with valid configuration and lets you mutate it to introduce a bad config option. I think we should use this, as eventually it will allow only testing using exported interface.
| // CheckWorkerPoolLabelsAndTaints verifies that all worker pool labels | ||
| // and taints are in correct format. Neither key nor value of labels | ||
| // and taints map should have empty space in them. | ||
| func (c *Config) CheckWorkerPoolLabelsAndTaints() hcl.Diagnostics { |
There was a problem hiding this comment.
This function should not be exported so we do not pollute the exported API. Config struct already exports generic Validate().
Now user cannot have spaced key or value in labels, taints map for worker pools.
Add tests.
closes: #1280