question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

targetPort does not accept integer as valid

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
itowlsoncommented, Oct 20, 2019

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.

0reactions
itowlsoncommented, Oct 24, 2019

Closed via #636.

Read more comments on GitHub >

github_iconTop Results From Across the Web

targetPort does not accept integer as valid · Issue #632 - GitHub
targetPort can be an integer, but VSCode reports a linting error that it expected a "string." apiVersion: v1 kind: Service metadata: name: ...
Read more >
Cannot port forward: "not a valid redirect target port. It must be ...
“The following input errors were detected: is not a valid redirect target port. It must be a port alias or integer between 1...
Read more >
How Do You Define a Kubernetes Service TargetPort as a ...
If you refer by integer, there is no need to define ports in pods at all, although it's reasonable to still do it...
Read more >
1383812 – Error setting ports using parameter in template ...
Doc Text: Feature: Support using parameter references in non-string template fields. Reason: Previously parameter references could not be used ...
Read more >
redirect targe port any does not work on TCP/UDP nat rule
A valid redirect target port must be specified. It must be a port alias or integer between 1 and 65535. I would take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found