Monday, December 09, 2019

How to Refer Key and Value in Key-Value pair in OPA Gatekeeper in Rego


    We start to use OPA gatekeeper for our kubernetes clusters. Refer for more details.
    When we code some policies for kubernetes using OPA (open policy agent) Rego ,we would like to reference "key" name and "value"  in nodeSelector key-value pair.  ie we have
    app: mytest
I would like to refererence "app" which is key and "test" which is value in our OPA gatekeeper policy .


   The easy way to do it is
 myvalue :=[mykey]
The value of varible mykey will have  "app"
The value variable myvalue will have  "mytest"
And they are strings

To get "set" , we need to use special way to achieve it:
To get "set" for key : 
  provided := {mykey |[mykey]}
To get set for value: 
  provided := {myvalue | myvalue :=[_]}

No comments: