Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
schrodit opened this issue Apr 28, 2025 · 1 comment · Fixed by #2400
Closed

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

schrodit opened this issue Apr 28, 2025 · 1 comment · Fixed by #2400

Comments

@schrodit
Copy link
Contributor

schrodit commented Apr 28, 2025

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
@schrodit
Copy link
Contributor Author

schrodit commented Apr 29, 2025

found the issue:

During create (or any other command (replace, patch, etc.)) the objects are serialized using ObjectSerializer.serialize(spec, 'KubernetesObject').
Using KubernetesObject here means that the specs are not correctly serialized.

https://github.com/kubernetes-client/javascript/blob/main/src/object.ts#L115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant