Skip to content

Commit f9ab7cc

Browse files
authored
perform immutable validation before update call (#351)
Description of changes: * immutable validation should be done before performing the update API call By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b80a751 commit f9ab7cc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

templates/pkg/resource/sdk_update.go.tpl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ func (rm *resourceManager) sdkUpdate(
1010
defer func() {
1111
exit(err)
1212
}()
13-
13+
{{- if .CRD.HasImmutableFieldChanges }}
14+
if immutableFieldChanges := rm.getImmutableFieldChanges(delta); len(immutableFieldChanges) > 0 {
15+
msg := fmt.Sprintf("Immutable Spec fields have been modified: %s", strings.Join(immutableFieldChanges, ","))
16+
return nil, ackerr.NewTerminalError(fmt.Errorf(msg))
17+
}
18+
{{- end }}
1419
{{- if $hookCode := Hook .CRD "sdk_update_pre_build_request" }}
1520
{{ $hookCode }}
1621
{{- end }}
@@ -37,12 +42,6 @@ func (rm *resourceManager) sdkUpdate(
3742
if err != nil {
3843
return nil, err
3944
}
40-
{{- if .CRD.HasImmutableFieldChanges }}
41-
if immutableFieldChanges := rm.getImmutableFieldChanges(delta); len(immutableFieldChanges) > 0 {
42-
msg := fmt.Sprintf("Immutable Spec fields have been modified: %s", strings.Join(immutableFieldChanges, ","))
43-
return nil, ackerr.NewTerminalError(fmt.Errorf(msg))
44-
}
45-
{{- end }}
4645
// Merge in the information we read from the API call above to the copy of
4746
// the original Kubernetes object we passed to the function
4847
ko := desired.ko.DeepCopy()

0 commit comments

Comments
 (0)