Skip to content

Commit

Permalink
policy: Fix CIDR json tag in CIDRRule
Browse files Browse the repository at this point in the history
Without the omitempty tag, the following valid policy:

```
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
  name: "echo-ingress-from-cidr-group-ref"
  namespace: "default"
spec:
  description: "Allow echo pods to receive ingress traffic from a specific CIDR Group"
  endpointSelector:
    matchLabels:
      kind: echo
  ingress:
  - fromCIDRSet:
    - cidrGroupRef: "connectivity-test-cidr-group"
```

cannot be correctly decoded from YAML:

```
CiliumNetworkPolicy.cilium.io "echo-ingress-from-cidr-group-ref" is invalid: [spec.ingress.fromCIDRSet.cidr: Invalid value: "": spec.ingress.fromCIDRSet.cidr in body should match '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/([0-9]|[1-2][0-9]|3[0-2])$|^s*((([0-9A-Fa-f]{1,4}:){7}(:|([0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){6}:([0-9A-Fa-f]{1,4})?)|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){0,1}):([0-9A-Fa-f]{1,4})?))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){0,2}):([0-9A-Fa-f]{1,4})?))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){0,3}):([0-9A-Fa-f]{1,4})?))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){0,4}):([0-9A-Fa-f]{1,4})?))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){0,5}):([0-9A-Fa-f]{1,4})?))|(:(:|((:[0-9A-Fa-f]{1,4}){1,7}))))(%.+)?s*/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$', : Invalid value: "": "spec.ingress.fromCIDRSet" must validate one and only one schema (oneOf). Found 2 valid alternatives]
```

Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
  • Loading branch information
pippolo84 authored and squeed committed May 24, 2023
1 parent e9a2805 commit 50e2f87
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/policy/api/cidr.go
Expand Up @@ -39,7 +39,7 @@ type CIDRRule struct {
// CIDR is a CIDR prefix / IP Block.
//
// +kubebuilder:validation:OneOf
Cidr CIDR `json:"cidr"`
Cidr CIDR `json:"cidr,omitempty"`

// CIDRGroupRef is a reference to a CiliumCIDRGroup object.
// A CiliumCIDRGroup contains a list of CIDRs that the endpoint, subject to
Expand Down

0 comments on commit 50e2f87

Please sign in to comment.