Skip to content

Commit 3653329

Browse files
authored
fix(omitUnchangedFields): only generate delta comparison check for spec fields (#476)
Skips the code generation of delta comparison check triggered by the use of the `omit_unchanged_fields:` field, if the field in question comes from the resource's `Status`. Such fields should always be included in the request, even with negative delta. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1cc9b51 commit 3653329

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

pkg/generate/code/set_sdk.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func SetSDK(
313313
// }
314314

315315
omitUnchangedFieldsOnUpdate := op == r.Ops.Update && r.OmitUnchangedFieldsOnUpdate()
316-
if omitUnchangedFieldsOnUpdate {
316+
if omitUnchangedFieldsOnUpdate && inSpec {
317317
fieldJSONPath := fmt.Sprintf("%s.%s", cfg.PrefixConfig.SpecField[1:], f.Names.Camel)
318318
out += fmt.Sprintf(
319319
"%sif delta.DifferentAt(%q) {\n", indent, fieldJSONPath,
@@ -384,7 +384,7 @@ func SetSDK(
384384
"%s}\n", indent,
385385
)
386386

387-
if omitUnchangedFieldsOnUpdate {
387+
if omitUnchangedFieldsOnUpdate && inSpec {
388388
// decrease indentation level
389389
indentLevel--
390390
indent = indent[1:]

pkg/generate/code/set_sdk_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -1387,10 +1387,8 @@ func TestSetSDK_MQ_Broker_newUpdateRequest_OmitUnchangedValues(t *testing.T) {
13871387
res.SetAutoMinorVersionUpgrade(*r.ko.Spec.AutoMinorVersionUpgrade)
13881388
}
13891389
}
1390-
if delta.DifferentAt("Spec.BrokerID") {
1391-
if r.ko.Status.BrokerID != nil {
1392-
res.SetBrokerId(*r.ko.Status.BrokerID)
1393-
}
1390+
if r.ko.Status.BrokerID != nil {
1391+
res.SetBrokerId(*r.ko.Status.BrokerID)
13941392
}
13951393
if delta.DifferentAt("Spec.Configuration") {
13961394
if r.ko.Spec.Configuration != nil {

0 commit comments

Comments
 (0)