-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for recording the diff in the ConfigurationPolicy status
A new recordDiff option of "InStatus" allows the diff to be stored in the object properties in the ConfigurationPolicy status. The new default recordDiff value is "InStatus" unless sensitive data may be in the diff. Then the user must explicitly set recordDiff. Relates: https://issues.redhat.com/browse/ACM-11421 Signed-off-by: mprahl <mprahl@users.noreply.github.com>
- Loading branch information
Showing
21 changed files
with
645 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright Contributors to the Open Cluster Management project | ||
|
||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestRecordDiffWithDefault(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := map[string]struct { | ||
apiVersion string | ||
kind string | ||
recordDiff RecordDiff | ||
expected RecordDiff | ||
}{ | ||
"Namespace-recordDiff-unset": { | ||
apiVersion: "v1", | ||
kind: "Namespace", | ||
expected: RecordDiffInStatus, | ||
}, | ||
"Namespace-recordDiff-set": { | ||
apiVersion: "v1", | ||
kind: "Namespace", | ||
recordDiff: RecordDiffLog, | ||
expected: RecordDiffLog, | ||
}, | ||
"Configmap-recordDiff-unset": { | ||
apiVersion: "v1", | ||
kind: "ConfigMap", | ||
expected: RecordDiffCensored, | ||
}, | ||
"Secret-recordDiff-unset": { | ||
apiVersion: "v1", | ||
kind: "Secret", | ||
expected: RecordDiffCensored, | ||
}, | ||
"Secret-recordDiff-set": { | ||
apiVersion: "v1", | ||
kind: "Secret", | ||
recordDiff: RecordDiffInStatus, | ||
expected: RecordDiffInStatus, | ||
}, | ||
"OAuthAccessToken-recordDiff-unset": { | ||
apiVersion: "oauth.openshift.io/v1", | ||
kind: "OAuthAccessToken", | ||
expected: RecordDiffCensored, | ||
}, | ||
"OAuthAuthorizeTokens-recordDiff-unset": { | ||
apiVersion: "oauth.openshift.io/v1", | ||
kind: "OAuthAuthorizeTokens", | ||
expected: RecordDiffCensored, | ||
}, | ||
"Route-recordDiff-unset": { | ||
apiVersion: "route.openshift.io/v1", | ||
kind: "Route", | ||
expected: RecordDiffCensored, | ||
}, | ||
} | ||
|
||
for testName, test := range tests { | ||
test := test | ||
|
||
t.Run( | ||
testName, | ||
func(t *testing.T) { | ||
t.Parallel() | ||
|
||
objTemp := ObjectTemplate{ | ||
ObjectDefinition: runtime.RawExtension{ | ||
Raw: []byte(fmt.Sprintf(`{"apiVersion": "%s", "kind": "%s"}`, test.apiVersion, test.kind)), | ||
}, | ||
RecordDiff: test.recordDiff, | ||
} | ||
|
||
if objTemp.RecordDiffWithDefault() != test.expected { | ||
t.Fatalf("Expected %s but got %s", test.expected, objTemp.RecordDiffWithDefault()) | ||
} | ||
}, | ||
) | ||
} | ||
} |
Oops, something went wrong.