Skip to content
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

Kubernetes core/Service: targetPort doesn't accept number #2433

Open
1 task done
cmbankester opened this issue Feb 13, 2025 · 0 comments
Open
1 task done

Kubernetes core/Service: targetPort doesn't accept number #2433

cmbankester opened this issue Feb 13, 2025 · 0 comments

Comments

@cmbankester
Copy link

Resource Type

Kubernetes core/Service

Api Version

v1

Issue Type

Inaccurate property type(s)

Other Notes

Property spec.ports.targetPort has warning when proving it with a number. The description for the property says:

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.

Providing a stringified number, (e.g. '8080') produces an error during deployment, so a number is required here. Providing a number here produces this warning:

The property "targetPort" expected a value of type "null | string" but the provided value is of type "8080". If this is a resource type definition inaccuracy, report it using https://aka.ms/bicep-type-issues

Bicep Repro

@secure()
param kubeConfig string

extension kubernetes with {
  namespace: 'ingress'
  kubeConfig: kubeConfig
}

var defaultBackendServiceName = 'contoso-default-backend'
var ingressName = 'contoso-web-ingress'

resource defaultBackendService 'core/Service@v1' = {
  metadata: {
    name: defaultBackendServiceName
    labels: {
      'app.kubernetes.io/name': defaultBackendServiceName
      'app.kubernetes.io/part-of': ingressName
    }
  }
  spec: {
    selector: {
      'app.kubernetes.io/name': defaultBackendServiceName
      'app.kubernetes.io/part-of': ingressName
    }
    ports: [
      {
        port: 80
        targetPort: 8080
        name: 'http'
      }
    ]
  }
}

Confirm

  • I have read the troubleshooting guide and looked for duplicates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

1 participant