Skip to content

Conversation

yuwenma
Copy link
Contributor

@yuwenma yuwenma commented Mar 29, 2022

Current GetXXX(fields []string) and SetXXX(fields []string) requires theinternal.variantof each fields to be a MapVariant except the last field fields[len(fields)-1]. This PR allows the intermediate variant to be a sliceVariant and select the element from the sliceVariant by a KEY=VALUE matching
For example, to get the target namespace from a ClusterRoleBinding object, the users can easily call
obj.Get(ns, "subjects", "kind=ServiceAccount", "namespace")
obj.Set(newNs, "subjects", "kind=ServiceAccount", "namespace")
ns := obj.GetStringOrDie("subjects", "kind=ServiceAccount", "namespace") // ns = example
obj.SetStringOrDie(newNs, "subjects", "kind=ServiceAccount", "namespace")

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: read-secrets-global
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: secret-reader
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group 
  name: admin 
  namespace: irrelevant # not chosen
- apiGroup: rbac.authorization.k8s.io
  kind: ServiceAccount
  name: admin
  namespace: example # target namespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant