-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17185 from smarterclayton/scc_cant_be_patched
Automatic merge from submit-queue (batch tested with PRs 17160, 17185). SCC can't be patched via JSONPatch because users is nil When users or groups are nil, standard JSONPatch can't be used to add a new item to the list because the array is nil instead of empty. Alter the serialization of SCC so that there is always a user or group array returned. ``` oc patch "securitycontextconstraints.v1.security.openshift.io" "hostnetwork" --type=json --patch="[{\"op\":\"add\",\"path\":\"/users/-\",\"value\":\"system:serviceaccount:myproject:router\"}]" Error from server: jsonpatch add operation does not apply: doc is missing path: /users/- ``` This allows us to do declarative patching against SCC until we move to PSP in a future release. @liggitt realized this while trying to switch router to a declarative model - patch is our best option for update, but you can't actually do a safe addition without JSONPatch and without this change. /kind bug
- Loading branch information
Showing
8 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
api/protobuf-spec/github_com_openshift_origin_pkg_security_apis_security_v1.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
54 changes: 54 additions & 0 deletions
54
pkg/security/registry/securitycontextconstraints/strategy_test.go
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,54 @@ | ||
package securitycontextconstraints | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
securityapi "github.com/openshift/origin/pkg/security/apis/security" | ||
) | ||
|
||
func TestCanonicalize(t *testing.T) { | ||
testCases := []struct { | ||
obj *securityapi.SecurityContextConstraints | ||
expect *securityapi.SecurityContextConstraints | ||
}{ | ||
{ | ||
obj: &securityapi.SecurityContextConstraints{}, | ||
expect: &securityapi.SecurityContextConstraints{}, | ||
}, | ||
{ | ||
obj: &securityapi.SecurityContextConstraints{ | ||
Users: []string{"a"}, | ||
}, | ||
expect: &securityapi.SecurityContextConstraints{ | ||
Users: []string{"a"}, | ||
}, | ||
}, | ||
{ | ||
obj: &securityapi.SecurityContextConstraints{ | ||
Users: []string{"a", "a"}, | ||
Groups: []string{"b", "b"}, | ||
}, | ||
expect: &securityapi.SecurityContextConstraints{ | ||
Users: []string{"a"}, | ||
Groups: []string{"b"}, | ||
}, | ||
}, | ||
{ | ||
obj: &securityapi.SecurityContextConstraints{ | ||
Users: []string{"a", "b", "a"}, | ||
Groups: []string{"c", "d", "c"}, | ||
}, | ||
expect: &securityapi.SecurityContextConstraints{ | ||
Users: []string{"a", "b"}, | ||
Groups: []string{"c", "d"}, | ||
}, | ||
}, | ||
} | ||
for i, testCase := range testCases { | ||
Strategy.Canonicalize(testCase.obj) | ||
if !reflect.DeepEqual(testCase.expect, testCase.obj) { | ||
t.Errorf("%d: unexpected object: %#v", i, testCase.obj) | ||
} | ||
} | ||
} |