Skip to content

Emit Int32OrStringV1 as int from Kubernetes publisher. #9933

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

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

hewe-saxo
Copy link
Contributor

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

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions github-actions bot added the area-integrations Issues pertaining to Aspire Integrations packages label Jun 18, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 18, 2025
@davidfowl davidfowl merged commit 0ba4315 into dotnet:main Jun 18, 2025
253 checks passed
@davidfowl
Copy link
Member

Thanks @hewe-saxo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants