Emit Int32OrStringV1 as int from Kubernetes publisher. #9933
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The Int32OrStringV1 type is used in the ServicePortV1:port and :TargetPort as well as ContainerPortV1:ContainerPort and :HostPort. Each of these needs to be serialized as int, so that helm is able to parse the values. If these values are quoted, helm will generate the following error message, also mentioned in issue #9382.
"json: cannot unmarshal string into Go struct field ServicePort.spec.ports.port of type int32"
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#containerport-v1-core
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#serviceport-v1-core
Discussion
This pull request fixes all cases where the port numbers are non-variables. However, when using WithHttpEndpoint() on a project resource, Aspire will generate a variable like "{{ .Values.parameters.myapp.port_http }}", which will be serialized as quoted string. Helm will not accept this. The variable should be serialized unquoted instead, but I have not found an elegant way of doing this.
Changing the IntOrStringConvert:WriteYaml() to use the emitter instead of the serializer works great, but unfortunately the ForceQuotedStringsEventEmitter will lose its position and start doublequoting scalar keys instead of the scalar values. The issue is described here.
aaubry/YamlDotNet#473
Checklist
<remarks />
and<code />
elements on your triple slash comments?doc-idea
templatebreaking-change
templatediagnostic
template