Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

fix labels and taints with spaced value for packet, aws, tinkerbell #1291

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

knrt10
Copy link
Member

@knrt10 knrt10 commented Dec 28, 2020

Now user cannot have spaced key or value in labels, taints map for worker pools.
Add tests.

closes: #1280

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 {
Copy link
Member

Choose a reason for hiding this comment

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

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, " ") {
Copy link
Member

Choose a reason for hiding this comment

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

What if I put tab character in key or value? I think we should also validate that.

@@ -428,6 +428,7 @@ func (c *config) checkValidConfig() hcl.Diagnostics {
diagnostics = append(diagnostics, c.checkWorkerPoolNamesUnique()...)
diagnostics = append(diagnostics, c.checkReservationIDs()...)
diagnostics = append(diagnostics, c.validateOSVersion()...)
diagnostics = append(diagnostics, c.checkWorkerPoolLabelsAndTaints()...)
Copy link
Member

Choose a reason for hiding this comment

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

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

@@ -355,3 +355,31 @@ func TestTerraformAddDeps(t *testing.T) {
})
}
}

func TestCheckWorkerPoolLabelsWithSpacedValue(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

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 {
Copy link
Member

Choose a reason for hiding this comment

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

This function should not be exported so we do not pollute the exported API. Config struct already exports generic Validate().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubelet fails with an "extra space" prefixed in the label value
2 participants