Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#3169 from gemmahou/firewallpol…
Browse files Browse the repository at this point in the history
…icyrule-direct-test

tests: Skip checking for changes in reference field
  • Loading branch information
google-oss-prow[bot] authored Nov 14, 2024
2 parents 2656148 + 4343c5c commit 3479289
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 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 @@ -831,14 +832,28 @@ func getChangedFields(initialObject, updatedObject map[string]interface{}, field
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).

// 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
if updatedObject["kind"] == "ComputeFirewallPolicyRule" {
computeFirewallPolicyRuleSkippedFields := []string{"targetResources", "targetServiceAccounts"}
if !slices.Contains(computeFirewallPolicyRuleSkippedFields, k) {
changedFields[k] = updated[k]
}
}
}
}
}
Expand Down

0 comments on commit 3479289

Please sign in to comment.