Skip to content

Commit 24f2e37

Browse files
authored
Merge pull request #8423 from cahillsf/cahillsf/dev2
🌱 Rename internal/util/ssa util functions for better naming consistency
2 parents e3ad957 + 4291641 commit 24f2e37

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

internal/controllers/topology/cluster/structuredmerge/drop_diff_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func Test_dropDiffForNotAllowedPaths(t *testing.T) {
6060
"foo": "123-changed",
6161
},
6262
},
63-
shouldDropDiffFunc: ssa.IsNotAllowedPath(
64-
[]contract.Path{ // NOTE: we are dropping everything not in this list (IsNotAllowed)
63+
shouldDropDiffFunc: ssa.IsPathNotAllowed(
64+
[]contract.Path{ // NOTE: we are dropping everything not in this list (IsPathNotAllowed)
6565
{"metadata", "labels"},
6666
{"metadata", "annotations"},
6767
{"spec"},
@@ -110,8 +110,8 @@ func Test_dropDiffForNotAllowedPaths(t *testing.T) {
110110
"foo": "123",
111111
},
112112
},
113-
shouldDropDiffFunc: ssa.IsNotAllowedPath(
114-
[]contract.Path{ // NOTE: we are dropping everything not in this list (IsNotAllowed)
113+
shouldDropDiffFunc: ssa.IsPathNotAllowed(
114+
[]contract.Path{ // NOTE: we are dropping everything not in this list (IsPathNotAllowed)
115115
{"metadata", "labels"},
116116
{"metadata", "annotations"},
117117
{"spec"},
@@ -146,8 +146,8 @@ func Test_dropDiffForNotAllowedPaths(t *testing.T) {
146146
"foo": "123",
147147
},
148148
},
149-
shouldDropDiffFunc: ssa.IsNotAllowedPath(
150-
[]contract.Path{}, // NOTE: we are dropping everything not in this list (IsNotAllowed)
149+
shouldDropDiffFunc: ssa.IsPathNotAllowed(
150+
[]contract.Path{}, // NOTE: we are dropping everything not in this list (IsPathNotAllowed)
151151
),
152152
},
153153
wantModified: map[string]interface{}{
@@ -194,7 +194,7 @@ func Test_dropDiffForIgnoredPaths(t *testing.T) {
194194
},
195195
},
196196
},
197-
shouldDropDiffFunc: ssa.IsIgnorePath(
197+
shouldDropDiffFunc: ssa.IsPathIgnored(
198198
[]contract.Path{
199199
{"spec", "controlPlaneEndpoint"},
200200
},
@@ -226,7 +226,7 @@ func Test_dropDiffForIgnoredPaths(t *testing.T) {
226226
},
227227
},
228228
},
229-
shouldDropDiffFunc: ssa.IsIgnorePath(
229+
shouldDropDiffFunc: ssa.IsPathIgnored(
230230
[]contract.Path{
231231
{"spec", "controlPlaneEndpoint"},
232232
},
@@ -251,7 +251,7 @@ func Test_dropDiffForIgnoredPaths(t *testing.T) {
251251
"foo": "123",
252252
},
253253
},
254-
shouldDropDiffFunc: ssa.IsIgnorePath(
254+
shouldDropDiffFunc: ssa.IsPathIgnored(
255255
[]contract.Path{
256256
{"spec", "foo"},
257257
},

internal/controllers/topology/cluster/structuredmerge/dryrun.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func cleanupManagedFieldsAndAnnotation(obj *unstructured.Unstructured) error {
183183
ssa.FilterIntent(&ssa.FilterIntentInput{
184184
Path: contract.Path{},
185185
Value: obj.Object,
186-
ShouldFilter: ssa.IsIgnorePath([]contract.Path{
186+
ShouldFilter: ssa.IsPathIgnored([]contract.Path{
187187
{"metadata", "annotations", clusterv1.TopologyDryRunAnnotation},
188188
// In case the ClusterClass we are reconciling is using not the latest apiVersion the conversion
189189
// annotation might be added to objects. As we don't care about differences in conversion as we
@@ -220,7 +220,7 @@ func cleanupManagedFieldsAndAnnotation(obj *unstructured.Unstructured) error {
220220
ssa.FilterIntent(&ssa.FilterIntentInput{
221221
Path: contract.Path{},
222222
Value: fieldsV1,
223-
ShouldFilter: ssa.IsIgnorePath([]contract.Path{
223+
ShouldFilter: ssa.IsPathIgnored([]contract.Path{
224224
{"f:metadata", "f:annotations", "f:" + clusterv1.TopologyDryRunAnnotation},
225225
{"f:metadata", "f:annotations", "f:" + conversion.DataAnnotation},
226226
}),

internal/controllers/topology/cluster/structuredmerge/twowayspatchhelper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func applyOptions(in *applyOptionsInput) ([]byte, error) {
171171
path: contract.Path{},
172172
original: originalMap,
173173
modified: modifiedMap,
174-
shouldDropDiffFunc: ssa.IsNotAllowedPath(in.options.allowedPaths),
174+
shouldDropDiffFunc: ssa.IsPathNotAllowed(in.options.allowedPaths),
175175
})
176176
}
177177

@@ -183,7 +183,7 @@ func applyOptions(in *applyOptionsInput) ([]byte, error) {
183183
path: contract.Path{},
184184
original: originalMap,
185185
modified: modifiedMap,
186-
shouldDropDiffFunc: ssa.IsIgnorePath(in.options.ignorePaths),
186+
shouldDropDiffFunc: ssa.IsPathIgnored(in.options.ignorePaths),
187187
})
188188
}
189189

internal/util/ssa/filterintent.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func FilterObject(obj *unstructured.Unstructured, input *FilterObjectInput) {
4141
FilterIntent(&FilterIntentInput{
4242
Path: contract.Path{},
4343
Value: obj.Object,
44-
ShouldFilter: IsNotAllowedPath(input.AllowedPaths),
44+
ShouldFilter: IsPathNotAllowed(input.AllowedPaths),
4545
})
4646
}
4747

@@ -51,7 +51,7 @@ func FilterObject(obj *unstructured.Unstructured, input *FilterObjectInput) {
5151
FilterIntent(&FilterIntentInput{
5252
Path: contract.Path{},
5353
Value: obj.Object,
54-
ShouldFilter: IsIgnorePath(input.IgnorePaths),
54+
ShouldFilter: IsPathIgnored(input.IgnorePaths),
5555
})
5656
}
5757
}
@@ -111,8 +111,8 @@ type FilterIntentInput struct {
111111
ShouldFilter func(path contract.Path) bool
112112
}
113113

114-
// IsAllowedPath returns true when the Path is one of the AllowedPaths.
115-
func IsAllowedPath(allowedPaths []contract.Path) func(path contract.Path) bool {
114+
// IsPathAllowed returns true when the Path is one of the AllowedPaths.
115+
func IsPathAllowed(allowedPaths []contract.Path) func(path contract.Path) bool {
116116
return func(path contract.Path) bool {
117117
for _, p := range allowedPaths {
118118
// NOTE: we allow everything Equal or one IsParentOf one of the allowed paths.
@@ -126,16 +126,16 @@ func IsAllowedPath(allowedPaths []contract.Path) func(path contract.Path) bool {
126126
}
127127
}
128128

129-
// IsNotAllowedPath returns true when the Path is NOT one of the AllowedPaths.
130-
func IsNotAllowedPath(allowedPaths []contract.Path) func(path contract.Path) bool {
129+
// IsPathNotAllowed returns true when the Path is NOT one of the AllowedPaths.
130+
func IsPathNotAllowed(allowedPaths []contract.Path) func(path contract.Path) bool {
131131
return func(path contract.Path) bool {
132-
isAllowed := IsAllowedPath(allowedPaths)
132+
isAllowed := IsPathAllowed(allowedPaths)
133133
return !isAllowed(path)
134134
}
135135
}
136136

137-
// IsIgnorePath returns true when the Path is one of the IgnorePaths.
138-
func IsIgnorePath(ignorePaths []contract.Path) func(path contract.Path) bool {
137+
// IsPathIgnored returns true when the Path is one of the IgnorePaths.
138+
func IsPathIgnored(ignorePaths []contract.Path) func(path contract.Path) bool {
139139
return func(path contract.Path) bool {
140140
for _, p := range ignorePaths {
141141
if path.Equal(p) {

internal/util/ssa/filterintent_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func Test_filterNotAllowedPaths(t *testing.T) {
5555
"foo": "123",
5656
},
5757
},
58-
ShouldFilter: IsNotAllowedPath(
58+
ShouldFilter: IsPathNotAllowed(
5959
[]contract.Path{ // NOTE: we are dropping everything not in this list
6060
{"apiVersion"},
6161
{"kind"},
@@ -96,7 +96,7 @@ func Test_filterNotAllowedPaths(t *testing.T) {
9696
"foo": "123",
9797
},
9898
},
99-
ShouldFilter: IsNotAllowedPath(
99+
ShouldFilter: IsPathNotAllowed(
100100
[]contract.Path{}, // NOTE: we are filtering out everything not in this list (everything)
101101
),
102102
},
@@ -135,7 +135,7 @@ func Test_filterIgnoredPaths(t *testing.T) {
135135
},
136136
},
137137
},
138-
ShouldFilter: IsIgnorePath(
138+
ShouldFilter: IsPathIgnored(
139139
[]contract.Path{
140140
{"spec", "controlPlaneEndpoint"},
141141
},
@@ -157,7 +157,7 @@ func Test_filterIgnoredPaths(t *testing.T) {
157157
"foo": "123",
158158
},
159159
},
160-
ShouldFilter: IsIgnorePath(
160+
ShouldFilter: IsPathIgnored(
161161
[]contract.Path{
162162
{"spec", "foo"},
163163
},
@@ -178,7 +178,7 @@ func Test_filterIgnoredPaths(t *testing.T) {
178178
},
179179
},
180180
},
181-
ShouldFilter: IsIgnorePath(
181+
ShouldFilter: IsPathIgnored(
182182
[]contract.Path{
183183
{"spec", "bar", "foo"},
184184
},

internal/util/ssa/managedfields.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func DropManagedFields(ctx context.Context, c client.Client, obj client.Object,
7474
FilterIntent(&FilterIntentInput{
7575
Path: contract.Path{},
7676
Value: fieldsV1,
77-
ShouldFilter: IsIgnorePath(paths),
77+
ShouldFilter: IsPathIgnored(paths),
7878
})
7979

8080
fieldsV1Raw, err := json.Marshal(fieldsV1)

internal/util/ssa/matchers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (fom *fieldOwnershipMatcher) Match(actual interface{}) (bool, error) {
9292
FilterIntent(&FilterIntentInput{
9393
Path: contract.Path{},
9494
Value: fieldsV1,
95-
ShouldFilter: IsNotAllowedPath([]contract.Path{fom.path}),
95+
ShouldFilter: IsPathNotAllowed([]contract.Path{fom.path}),
9696
})
9797
return len(fieldsV1) > 0, nil
9898
}

0 commit comments

Comments
 (0)