Skip to content

Commit

Permalink
Skip checking for changes in reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Nov 13, 2024
1 parent aeda6fd commit 1297e2f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/controller/dynamic/dynamic_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"slices"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -828,17 +829,28 @@ func getChangedFields(initialObject, updatedObject map[string]interface{}, field
changedFields := make(map[string]interface{})
initial, _ := initialObject[field].(map[string]interface{})
updated := updatedObject[field].(map[string]interface{})
// Fields containing a list of resource references do not have the "Ref" suffix in the field name.
// For example, targetResources field in ComputeFirewallPolicyRule.
// Manually add those fields to the skipped fields list.
// todo: Determine if we want to have "Refs" in those field names, like "targetResourceRefs"
// That would introduce breaking changes to DCL/TF resource
computeFirewallPolicyRuleSkippedFields := []string{"targetResources", "targetServiceAccounts"}
if !reflect.DeepEqual(initial, updated) {
for k, v := range updated {
if !reflect.DeepEqual(initial[k], v) {
if _, ok := v.(map[string]interface{}); ok {
switch v.(type) {
case map[string]interface{}:
// Skip checking for changes in resource reference fields, because there
// is no way to export the name and namespace fields (only external).
if !strings.HasSuffix(k, "Ref") {
changedFields[k] = getChangedFields(initial, updated, k)
}
} else {
changedFields[k] = updated[k]
default:
// Skip checking for changes in fields contains a list of resource references,
// because there is no way to export the name and namespace fields (only external).
if updatedObject["kind"] == "ComputeFirewallPolicyRule" && !slices.Contains(computeFirewallPolicyRuleSkippedFields, k) {
changedFields[k] = updated[k]
}
}
}
}
Expand Down

0 comments on commit 1297e2f

Please sign in to comment.