Skip to content

Commit

Permalink
fix: only set restricted field to default value if none of the condit…
Browse files Browse the repository at this point in the history
…ionals set it (#284)

Signed-off-by: Jonah Back <jonah@jonahback.com>
  • Loading branch information
backjo authored Apr 29, 2021
1 parent 002bf72 commit 59dd8b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions controllers/provisioners/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ func (c *ProvisionerConfiguration) setRestrictedFields(unstructuredInstanceGroup
for _, pathStr := range c.Boundaries.Restricted {
path := common.FieldPath(pathStr)
// if a default value exists for the path, set it on the instance group
var setField = false
var field interface{}
var setFieldInAnyConditional = false
for _, conditional := range applicableConditionals {
if field, setField, _ = unstructured.NestedFieldCopy(conditional.Defaults, path...); setField {
if field, setField, _ := unstructured.NestedFieldCopy(conditional.Defaults, path...); setField {
setFieldInAnyConditional = true
err := unstructured.SetNestedField(unstructuredInstanceGroup, field, path...)
if err != nil {
errors.Wrap(err, "failed to set nested field")
}
}
}
if setField {
if setFieldInAnyConditional {
continue
}
if field, ok, _ := unstructured.NestedFieldCopy(c.Defaults, path...); ok {
Expand Down
8 changes: 7 additions & 1 deletion controllers/provisioners/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,18 @@ func TestSetDefaultsWithRestrictedConditional(t *testing.T) {
eks:
configuration:
image: ami-22222222222
- annotationSelector: "instancemgr.keikoproj.io/arch=arm64"
- annotationSelector: "instancemgr.keikoproj.io/arch in (arm64), instancemgr.keikoproj.io/os-family in (windows)"
defaults:
spec:
eks:
configuration:
image: ami-33333333333
- annotationSelector: "instancemgr.keikoproj.io/arch in (arm64), instancemgr.keikoproj.io/os-family in (windows)"
defaults:
spec:
eks:
configuration:
foo: bar
`

mockDefaults := `
Expand Down

0 comments on commit 59dd8b1

Please sign in to comment.