vscode-kubernetes-tools: targetPort does not accept integer as valid

targetPort can be an integer, but VSCode reports a linting error that it expected a “string.”

apiVersion: v1
kind: Service
metadata:
  name: hello
spec:
  selector:
    app: hello
  type: ClusterIP
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (3 by maintainers)

Most upvoted comments

The difference between the fallback schema (which behaves correctly) and the schema given by Kubernetes itself is that in the fallback schema we have:

        "io.k8s.apimachinery.pkg.util.intstr.IntOrString": {
            "oneOf": [
                {
                    "type": "string"
                },
                {
                    "type": "integer"
                }
            ]
        },

whereas live clusters tell us to use:

    "io.k8s.apimachinery.pkg.util.intstr.IntOrString": {
      "description": "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.",
      "format": "int-or-string",
      "type": "string"
    },

The latter feels semantically less correct, though arguably Red Hat YAML mishandled it by requiring the quotation marks; I wonder if we should raise an issue against upstream k8s to represent it using the oneOf form.

In any case, we can massage it when we retrieve it from the cluster. And now I have a repro I can actually confirm the massaging works.

Thanks everyone for your patience. Hopefully I’ll have a fix for you soon.