diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index f561d107f29b..bc93acc830a5 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -1489,6 +1489,11 @@ func writePropertiesToBody(missingProperties []propertyPath, bodyParams map[stri for _, containerName := range prop.path { innerBodyContainer, bodyOk := currentBodyContainer[containerName] innerStateContainer, stateOk := currentStateContainer[containerName] + // If the container doesn't exist in either body or state, create it and continue iterating. + // But if it doesn't exist in either, there is no point in continuing. + if !bodyOk && !stateOk { + break + } if !bodyOk { innerBodyContainer = map[string]interface{}{} currentBodyContainer[containerName] = innerBodyContainer diff --git a/provider/pkg/provider/provider_test.go b/provider/pkg/provider/provider_test.go index 046e83129d95..95653dcd5b48 100644 --- a/provider/pkg/provider/provider_test.go +++ b/provider/pkg/provider/provider_test.go @@ -134,6 +134,27 @@ func TestWritePropertiesToBody(t *testing.T) { assert.Equal(t, expected, bodyParams) }) + // Regression test for #3036 - do not add empty containers to the body that will not be filled + t.Run("two containers missing from remote", func(t *testing.T) { + missingProperties := []propertyPath{{ + propertyName: "remote", + path: []string{"properties", "privateNetworks"}, + }} + bodyParams := map[string]interface{}{ + "properties": map[string]interface{}{ + "existing": "value", + }, + } + response := map[string]interface{}{} + writePropertiesToBody(missingProperties, bodyParams, response) + expected := map[string]interface{}{ + "properties": map[string]interface{}{ + "existing": "value", + }, + } + assert.Equal(t, expected, bodyParams) + }) + t.Run("properties container missing in body", func(t *testing.T) { missingProperties := []propertyPath{{ propertyName: "remote", @@ -162,10 +183,7 @@ func TestWritePropertiesToBody(t *testing.T) { bodyParams := map[string]interface{}{} response := map[string]interface{}{} writePropertiesToBody(missingProperties, bodyParams, response) - expected := map[string]interface{}{ - // Container is auto-created - "properties": map[string]interface{}{}, - } + expected := map[string]interface{}{} assert.Equal(t, expected, bodyParams) })