Skip to content

NetworkPolicy.spec.ingress.from is not correctly serialized #2396

@schrodit

Description

@schrodit

Describe the bug

A network policy resource is correctly deserialized when read from the cluster.
The ingress spec is correctly converted from from to _from. See https://github.com/kubernetes-client/javascript/blob/main/src/gen/models/V1NetworkPolicyIngressRule.ts#L24

But the serialization (e.g. when using with client.replace) does not correctly set from field. see the snippet below.

Client Version
e.g. 1.1.2

To Reproduce
See example

Expected behavior

Resource is correctly serialized

Example Code

const netPol: V1 NetworkPolicy = {
        apiVersion: 'networking.k8s.io/v1',
        kind: 'NetworkPolicy',
        metadata: {
            name: 'test',
            namespace: 'default',
        },
        spec: {
            podSelector: {
                matchLabels: {
                    app: 'workspace',
                },
            },
            policyTypes: ['Ingress', 'Egress'],
            ingress: [
                {
                    _from: [{
                        podSelector: {matchLabels: {app: 'foo'}},
                    }],
                    ports: [{port: 123}],
                },
            ],
            egress: [
                {
                    to: [{
                        matchLabels: {app: 'bar'},
                    }],
                },
            ],
        },
    };
    client.create(netPol); // does not include the spec.ingress.from fields

Environment (please complete the following information):

  • OS: Linux
  • Node.js version: 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions