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

Allow injection of env vars in any deployment #120

Merged
merged 6 commits into from
Sep 12, 2021

Conversation

valentintorikian
Copy link
Contributor

@valentintorikian valentintorikian commented Mar 10, 2020

This allows the user to inject any custom env variable in any deployment.

The need was the ability to configure a proxy so that st2 pack install doesn't fail when behind said proxy. The env variable needed to be injected in the st2actionrunner deployments.

There is a BC break on st2chatops configuration, if secrets are provided, they need to be added to secrets.st2.st2chatops.env instead of st2chatops.env.

This should also closes #119 and partially solves #14.

@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label Mar 10, 2020
values.yaml Outdated
@@ -158,6 +160,9 @@ ingress:
# TODO: Alternatively as part of reorganizing Helm values, consider moving values to existing `st2` and `st2web` sections ? (#14)
secrets:
st2:
st2chatops:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this is secrets.st2.st2chatops instead of secrets.st2chatops (i.e. why the nesting under st2)?

Copy link

@mickmcgrath13 mickmcgrath13 Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, any reason not to put the secrets specific to st2chatops under st2chatops (and the same for all other services) instead of aggregating all secrets to a central place?

i.e. instead of

secrets:
  st2:
    st2chatops:
      foo: bar

do

st2chatops:
  secrets:
    foo: bar

?

Copy link
Contributor Author

@valentintorikian valentintorikian Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this is secrets.st2.st2chatops instead of secrets.st2chatops (i.e. why the nesting under st2)?

For this part, no particular reason, it's true that it's a bit too verbose.

Also, any reason not to put the secrets specific to st2chatops under st2chatops (and the same for all other services) instead of aggregating all secrets to a central place?

See issue #14 :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I think it'd be preferable to spread the secrets out into their respective services, but we can tackle that when we tackle #14

Thanks!

Copy link
Member

@arm4b arm4b Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that secrets.st2.st2chatops looks too verbose and even counter-intuitive.

This also raises some inconsistencies in the context of #119 discussion. I'm thinking about exploring the alternatives for the Helm values definition.

Copy link

@mickmcgrath13 mickmcgrath13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me. I haven't tested them, though..

Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I absolutely like an idea of adding env for every new service, - that's a great addition! 👍

However secrets.st2.st2chatops is something that worries me 👎 in this PR and uncovers some inconsistencies described in issues like #14 #119.

values.yaml Outdated
@@ -158,6 +160,9 @@ ingress:
# TODO: Alternatively as part of reorganizing Helm values, consider moving values to existing `st2` and `st2web` sections ? (#14)
secrets:
st2:
st2chatops:
Copy link
Member

@arm4b arm4b Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that secrets.st2.st2chatops looks too verbose and even counter-intuitive.

This also raises some inconsistencies in the context of #119 discussion. I'm thinking about exploring the alternatives for the Helm values definition.

@arm4b arm4b added the enhancement New feature or request label Mar 10, 2020
@@ -16,7 +16,7 @@ metadata:
heritage: {{ .Release.Service }}
type: Opaque
data:
{{- range $env, $value := .Values.st2chatops.env }}
{{- range $env, $value := .Values.secrets.st2.st2chatops.env }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is at least an agreement about the 💯 need of raw ENV for every Pod and that's super helpful.
Can we keep raw ENV functionality in this PR to be able to merge it asap, but split the st2chatops secrets ENV enhancement into another PR?

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome start!

I think we might also want to add an env block to the jobs (all the jobs would share the same block).
In values.yaml, it would be something like:

jobs:
  env: {}
  # HTTP_PROXY: http://proxy:1234

Comment on lines 73 to 79
{{- if .Values.st2auth.env }}
env:
{{- range $env, $value := .Values.st2auth.env }}
- name: {{ $env | quote }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be extracted into a helper to avoid some repetition.
So, here it would have:

{{ include "custom-env" .Values.st2auth | indent 8 }}

And then the template would be:

{{- define "custom-env" -}}
  {{- if .env }}
env:
    {{- range $env, $value := .env }}
- name: {{ $env | quote }}
  value: {{ $value | quote }}
    {{- end }}
  {{- end }}
{{- end -}}

Comment on lines 932 to 938
{{- if .env }}
env:
{{- range $env, $value := .env }}
- name: {{ $env | quote }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the template here would just be:

{{ include "custom-env" . | indent 8 }}

Comment on lines 1460 to 1463
{{- range $env, $value := .Values.st2chatops.env }}
- name: {{ $env | quote }}
value: {{ $value | quote }}
{{- end }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would drop this, and leave the st2chatops env as is (in envFrom[1].secretRef below).

Suggested change
{{- range $env, $value := .Values.st2chatops.env }}
- name: {{ $env | quote }}
value: {{ $value | quote }}
{{- end }}

Comment on lines 1329 to 1332
{{- range $env, $value := .Values.st2client.env }}
- name: {{ $env | quote }}
value: {{ $value | quote }}
{{- end }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of jobs also have an env: block already. So, we could split the template into two to accommodate this usage.

{{- define "custom-env-entries" -}}
  {{- range $env, $value := .env }}
- name: {{ $env | quote }}
  value: {{ $value | quote }}
  {{- end }}
{{- end -}}
{{- define "custom-env" -}}
  {{- if .env }}
env:
{{ include "custom-env-entries" . }}
  {{- end }}
{{- end -}}

Which would make this block be:

{{ include "custom-env-entries" .Values.st2client }}

templates/secrets_st2chatops.yaml Outdated Show resolved Hide resolved
values.yaml Outdated Show resolved Hide resolved
Comment on lines +106 to +107
env: {}
# HTTP_PROXY: http://proxy:1234
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like the commented example. 👍

values.yaml Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/M PR that changes 30-99 lines. Good size to review. and removed size/L PR that changes 100-499 lines. Requires some effort to review. labels Sep 9, 2021
@cognifloyd cognifloyd self-requested a review September 9, 2021 03:31
@cognifloyd
Copy link
Member

I want to clear out old PRs by merging them if possible.
So, I just merged in master and made a few updates to address all the comments here.

I think a Changelog entry is the only thing left before merging this. @angrydeveloper what do you think of these changes?

Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look really helpful! 👍

Thanks @cognifloyd. I think it's also OK to inject the changelog as well to merge it.

@cognifloyd cognifloyd merged commit 718d769 into StackStorm:master Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/M PR that changes 30-99 lines. Good size to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

st2chatops env/secrets management
4 participants