hi all
I have a requirement where I need label which can be a list of values. for ex:
label:
app: app1, app2, app3
as based on these values my matchLabels can be any of these and if it matches any of these label values it will handle the network policy
Kind: Deployment
Meta:
Label:
name: app4
team: training
app: app1, app2, app3
my network policy stuff could be like this
kind: CiliumNetworkPolicy
specs:
- description: “some description”
endpointSelector:
matchLabels:
role: backend
ingress:
- fromEndpoint:
matchLabels:
“k8s:app”: “app1”
How do I set label as a list or array of values or how should I take it forward
Labels are intended to be singular key:value pairs and don’t have inherit logic to parse arrays of items in a single label.
For more information, see the Labels and Selectors | Kubernetes section of the docs.
Is there some work around to achieve it if labels cant have multiple values?
The easiest is to add more labels as descriptors. Break down the array into multiple key:value pairs as descriptors and use those in your selector.
labels:
name: my-awesome-thing
environment: dev
app: awesome-app
component: webserver
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "my-network-policy"
namespace: dev
spec:
endpointSelector:
matchLabels:
role: backend
ingress:
- fromEndpoints:
- matchLabels:
k8s:name: my-awesome-thing
k8s:app: awesome-app
k8s:component: webserver