-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jsonpath support for get/set multiple values
- Move only-one-match logic into mutator impl
- Loading branch information
Showing
4 changed files
with
241 additions
and
118 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 |
---|---|---|
|
@@ -327,6 +327,43 @@ spec: | |
- containerPort: 8081 | ||
` | ||
|
||
var clusterrole1y = ` | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: example-role | ||
labels: | ||
domain: example.com | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["pods"] | ||
verbs: ["get", "watch", "list"] | ||
` | ||
|
||
var clusterrolebinding1y = ` | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: read-secrets | ||
annotations: | ||
config.kubernetes.io/apply-time-mutation: | | ||
- sourceRef: | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
name: example-role | ||
sourcePath: $.metadata.labels.domain | ||
targetPath: $.subjects[0].name | ||
token: ${domain} | ||
subjects: | ||
- kind: User | ||
name: "bob@${domain}" | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: ClusterRole | ||
name: secret-reader | ||
apiGroup: rbac.authorization.k8s.io | ||
` | ||
|
||
type nestedFieldValue struct { | ||
Field []interface{} | ||
Value interface{} | ||
|
@@ -344,6 +381,8 @@ func TestMutate(t *testing.T) { | |
ingress2 := ktestutil.YamlToUnstructured(t, ingress2y) | ||
service1 := ktestutil.YamlToUnstructured(t, service1y) | ||
deployment1 := ktestutil.YamlToUnstructured(t, deployment1y) | ||
clusterrole1 := ktestutil.YamlToUnstructured(t, clusterrole1y) | ||
clusterrolebinding1 := ktestutil.YamlToUnstructured(t, clusterrolebinding1y) | ||
|
||
joinedPaths := make([]interface{}, 0) | ||
err := yaml.Unmarshal([]byte(joinedPathsYaml), &joinedPaths) | ||
|
@@ -510,6 +549,18 @@ func TestMutate(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
"cluster-scoped": { | ||
target: clusterrolebinding1, | ||
sources: []*unstructured.Unstructured{clusterrole1}, | ||
mutated: true, | ||
reason: expectedReason, | ||
expected: []nestedFieldValue{ | ||
{ | ||
Field: []interface{}{"subjects", 0, "name"}, | ||
Value: "[email protected]", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
|
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
Oops, something went wrong.