Kubernetes core/Service: targetPort doesn't accept number
- Dominant language
- TypeScript
- Stars
- 108
- Forks
- 44
- Avg merge
- 18h 53m
- Merged PRs (30d)
- 29
Description
### 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
```bicep
@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
- [x] I have read the troubleshooting guide and looked for duplicates.
Contributor guide
No contributing guide indexed for this repository
Research direction
Find the Kubernetes core/Service@v1 type definition and inspect the spec.ports.targetPort property. Reproduce the warning with the Bicep example in the issue, then update the definition so numeric targetPort values are accepted and verify that deployment no longer reports the inaccurate type warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes, typescript
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100