java icon indicating copy to clipboard operation
java copied to clipboard

"invalid object type" applying v1 NetworkPolicy with Calico

Open SanjayVas opened this issue 4 months ago • 6 comments
trafficstars

Describe the bug I get an error status with message invalid object type: networking.k8s.io/v1, Kind=NetworkPolicy when calling Kubectl.apply from io.kubernetes.client.extended.kubectl on a V1NetworkPolicy object loaded from YAML. This specifically happens when calling a minikube instance with the Calico networking plugin. If it's using the default Kindnet plugin (which now supports NetworkPolicy), there's no error.

Note that there's also no error when applying the same YAML file using the kubectl CLI.

Client Version 24.0.0

Kubernetes Version 1.32.0

Java Version Kotlin 2.1.0 on Java 17

To Reproduce

  1. Start minikube with --cni=calico
  2. Load YAML file containing a v1 NetworkPolicy object using io.kubernetes.client.util.Yaml
  3. Call Kubectl.apply with that object.

Expected behavior NetworkPolicy object is applied (in this case, created) successfully.

Server (please complete the following information):

  • OS: Linux (Debian testing)
  • Environment: Local w/minikube

Additional context Full log message:

io.kubernetes.client.extended.kubectl.exception.KubectlException: io.kubernetes.client.openapi.ApiException: Message: class V1Status {
    apiVersion: v1
    code: 400
    details: null
    kind: Status
    message: invalid object type: networking.k8s.io/v1, Kind=NetworkPolicy
    metadata: class V1ListMeta {
        _continue: null
        remainingItemCount: null
        resourceVersion: null
        selfLink: null
    }
    reason: BadRequest
    status: Failure
}
HTTP response code: 400
HTTP response body: null
HTTP response headers: null
        at io.kubernetes.client.extended.kubectl.KubectlApply.executeServerSideApply(KubectlApply.java:102)
        at io.kubernetes.client.extended.kubectl.KubectlApply.execute(KubectlApply.java:66

SanjayVas avatar Jun 25 '25 23:06 SanjayVas