Skip to content

Passing V1Service and V1NetworkPolicy to CoreV1Api.replace methods can cause an API exception #322

@ceridwen

Description

@ceridwen

I'm trying to modify V1Service and V1NetworkPolicy objects by reading their current state, changing it, and then replacing the old state with the new state. However, when I pass these objects as the body of a CoreV1API.replace() call, I get the following Kubernetes error:

kubernetes.client.rest.ApiException: (422)
Reason: Unprocessable Entity
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Fri, 18 Aug 2017 19:03:09 GMT', 'Content-Length': '582'})
HTTP response body: {
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "Service \"cluster-ip-lh3lj\" is invalid: spec.ports[0].targetPort: Invalid value: \"5000\": must contain at least one letter or number (a-z, 0-9)",
  "reason": "Invalid",
  "details": {
    "name": "cluster-ip-lh3lj",
    "kind": "Service",
    "causes": [
      {
        "reason": "FieldValueInvalid",
        "message": "Invalid value: \"5000\": must contain at least one letter or number (a-z, 0-9)",
        "field": "spec.ports[0].targetPort"
      }
    ]
  },
  "code": 422
}

I believe this is happening because the objects V1NetworkPolicyPort and V1ServicePort have their types set to str rather than int like the other port fields in V1ServicePort, so during the conversion of the object into the actual HTTP passed to the Kubernetes API server, the string port is escaped to "5000" rather 5000. However, I haven't tested other objects, other creation methods, or other Kubernetes APIs that accept API model objects as arguments.

I don't know if this is a bug with the Kubernetes client, Swagger codegen, or the Swagger Kubernetes spec, so I thought I'd start at the bottom and move upstream if necessary. This is on minikube v0.21.0 (Kubernetes 1.7.0) on MacOS X 10.12.6 using 3.0.0 of the Python client.

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