-
Notifications
You must be signed in to change notification settings - Fork 48
fix labels and taints with spaced value for packet, aws, tinkerbell #1291
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()...) | ||
|
||
if c.ConntrackMaxPerCore < 0 { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
|
@@ -525,6 +526,37 @@ func (c *config) validateOSVersion() hcl.Diagnostics { | |
return diagnostics | ||
} | ||
|
||
// 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd extend |
||
var diagnostics hcl.Diagnostics | ||
|
||
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. Choose a reason for hiding this commentThe 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. |
||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "Worker pools labels map should not contain empty spaces", | ||
Detail: fmt.Sprintf("Worker pool %q label with key %q is incorrect", w.Name, k), | ||
}) | ||
} | ||
} | ||
|
||
for k, v := range w.Taints { | ||
if strings.Contains(k, " ") || strings.Contains(v, " ") { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "Worker pools taints map should not contain empty spaces", | ||
Detail: fmt.Sprintf("Worker pool %q taints with key %q is incorrect", w.Name, k), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
return diagnostics | ||
} | ||
|
||
// checkEachReservation checks that hardware reservations are in the correct | ||
// format and, when it will cause problems, that reservation IDs values in this | ||
// pool are not mixed between using "next-available" and specific UUIDs, as this | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,3 +355,31 @@ func TestTerraformAddDeps(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestCheckWorkerPoolLabelsWithSpacedValue(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have |
||
c := config{ | ||
WorkerPools: []workerPool{ | ||
{ | ||
Labels: map[string]string{"foo-1": "bar "}, | ||
}, | ||
}, | ||
} | ||
|
||
if d := c.checkWorkerPoolLabelsAndTaints(); !d.HasErrors() { | ||
t.Error("Should fail with space in worker pool labels") | ||
} | ||
} | ||
|
||
func TestCheckWorkerPoolTaintsWithSpacedValue(t *testing.T) { | ||
c := config{ | ||
WorkerPools: []workerPool{ | ||
{ | ||
Taints: map[string]string{"foo-1": "bar "}, | ||
}, | ||
}, | ||
} | ||
|
||
if d := c.checkWorkerPoolLabelsAndTaints(); !d.HasErrors() { | ||
t.Error("Should fail with space in worker pool taints") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,7 @@ func (c *Config) Validate() hcl.Diagnostics { | |
|
||
d = append(d, platform.WorkerPoolNamesUnique(x)...) | ||
d = append(d, c.validateRequiredFields()...) | ||
d = append(d, c.CheckWorkerPoolLabelsAndTaints()...) | ||
|
||
return d | ||
} | ||
|
@@ -288,3 +289,34 @@ func (c *Config) validateRequiredFields() hcl.Diagnostics { | |
|
||
return d | ||
} | ||
|
||
// 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. Choose a reason for hiding this commentThe 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 |
||
var diagnostics hcl.Diagnostics | ||
|
||
for _, w := range c.WorkerPools { | ||
for k, v := range w.Labels { | ||
if strings.Contains(k, " ") || strings.Contains(v, " ") { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "Worker pools labels map should not contain empty spaces", | ||
Detail: fmt.Sprintf("Worker pool %q label with key %q is incorrect", w.PoolName, k), | ||
}) | ||
} | ||
} | ||
|
||
for k, v := range w.Taints { | ||
if strings.Contains(k, " ") || strings.Contains(v, " ") { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "Worker pools taints map should not contain empty spaces", | ||
Detail: fmt.Sprintf("Worker pool %q taints with key %q is incorrect", w.PoolName, k), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
return diagnostics | ||
} |
There was a problem hiding this comment.
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:
to look for associated merge commit later.