Skip to content

Replace hyphens with underscores in Helm environment variable keys #10839

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

codingzerotohero
Copy link

@codingzerotohero codingzerotohero commented Aug 5, 2025

Replace hyphens with underscores in Helm environment variable keys, adjust relevant test to properly validate this scenario.

Description

Take this configMap example, taken from issue #10820

---
apiVersion: "v1"
kind: "ConfigMap"
metadata:
  name: "xx-yy-xx-webspa-config"
  labels:
    app: "aspire"
    component: "xx-yy-xx-webspa"
data:
  ASPNETCORE_URLS: "{{ .Values.config.xx_yy_xx_webspa.ASPNETCORE_URLS }}"
  ConnectionStrings__HangfireDb: "{{ .Values.config.xx_yy_xx_webspa.ConnectionStrings__HangfireDb }}"
  ConnectionStrings__rabbitmq: "{{ .Values.config.xx_yy_xx_webspa.ConnectionStrings__rabbitmq }}"
  services__xx-yy-xx-bookings__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-bookings__https__0 }}"
  services__xx-yy-xx-filestorage__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-filestorage__https__0 }}"
  services__xx-yy-xx-institutions__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-institutions__https__0 }}"
  services__xx-yy-xx-mapobjects__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-mapobjects__https__0 }}"
  services__xx-yy-xx-messenger__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-messenger__https__0 }}"
  services__xx-yy-xx-permissions__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-permissions__https__0 }}"
  services__xx-yy-xx-projects__https__0: "{{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-projects__https__0 }}"

While hyphens are allowed in the data keys, and in values environment variable names, they are NOT allowed in the Helm expressions. This for example: {{ .Values.config.xx_yy_xx_webspa.services__xx-yy-xx-bookings__https__0 }} fails when ran through the helm template command.

Replacing the hyphens with underscores only in the Helm expression is not an option, because that makes the 'link' invalid, as there are no services__xx_yy_xx_bookings__https__0 environment variable keys with that name, if they don't also get changed there.

Therefore, it has to be changed this way, so they are reflected both places.

Unit test PublishAsync_HandlesSpecialResourceName() was also changed, to properly test this scenario by adding a container resources, and adding a reference to it in the project resource, so it adds the services__xx-yy-xx-bookings__https__0 reference, allowing us to properly test it.

Fixes #10820

NOTE!!
This also makes any connectionstrings for example ConnectionStrings__some-service -> ConnectionStrings__some_service but I think that's fine, usually environment variables don't contain hyphens in most systems anyway.

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?

…djust relevant test to properly validate this cenario
@github-actions github-actions bot added the area-integrations Issues pertaining to Aspire Integrations packages label Aug 5, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 5, 2025
@codingzerotohero
Copy link
Author

@codingzerotohero please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

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.

Helm output of 'aspire publish' produces invalid yaml when services have dashes in name
2 participants