cdk8s-team / cdk8s-plus

A software development framework that provides high level abstractions for authoring Kubernetes applications.
https://cdk8s.io/docs/latest/plus/
Apache License 2.0
128 stars 33 forks source link

Invalid network policy when using allUdp and allTcp #4395

Open emagiz opened 4 days ago

emagiz commented 4 days ago

Description of the bug:

When using ports: [kplus.NetworkPolicyPort.allTcp(), kplus.NetworkPolicyPort.allUdp()] when rendering a NetworkPolicy, it will generate a manifest like

[{\"endPort\":65535,\"port\":0,\"protocol\":\"TCP\"},{\"endPort\":65535,\"port\":0,\"protocol\":\"UDP\"}]

However, when applying this to AWS, the following error is generated The NetworkPolicy "mynetworkpolicy" is invalid: \n* spec.egress[0].ports[0].port: Invalid value: 0: must be between 1 and 65535, inclusive\n* spec.egress[0].ports[1].port: Invalid value: 0: must be between 1 and 65535, inclusive

This seems to originate from: https://github.com/cdk8s-team/cdk8s-plus/blob/k8s-29/main/src/network-policy.ts#L60

Reproduction Steps:

const NetworkPolicy = new kplus.NetworkPolicy(
      scope,
      `allow-ns-np`,
      {
        metadata: {
          namespace: "mynamespace",
        },
        egress: {
          rules: [
            {
              peer: kplus.Namespaces.select(
                scope,
                `allow-ns-np-mynamespace-select`,
                { names: ["mynamespace"] }
              ),
              ports: [kplus.NetworkPolicyPort.allTcp(), kplus.NetworkPolicyPort.allUdp()],
            },
          ],
        },
      }
    );

Error Log:

The NetworkPolicy "mynetworkpolicy" is invalid: \n* spec.egress[0].ports[0].port: Invalid value: 0: must be between 1 and 65535, inclusive\n* spec.egress[0].ports[1].port: Invalid value: 0: must be between 1 and 65535, inclusive

Environment:

Other:

We use Kubectl layer 1.29, and cluster version 1.29.


This is :bug: Bug Report