-
Notifications
You must be signed in to change notification settings - Fork 1k
Ability to set pod environment variables on cluster resource #1794
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
Conversation
@FxKu could you please to have a look at the fix approach. If it will be suitable, I will add docs and unit-test for it. Thanks in advance. |
In CRD, Is there possible to add only some environment variables to pod? for example spec:
env:
- name: ENV_1
value: VALUE_1 |
Not sure, that's good approach as will need to support both setup for predefined ConfigMap/Secret and current one. Common way much better and didn't overload CR if it's not needed |
@FxKu could you please to find a time and have a look at the fix approach. If it will be suitable, I will add docs and unit-test for it. Thanks in advance. |
Hey @dmvolod, while it looks elegant at first, I don't think it should be solved like this because only one way is possible - global config map or the need to add config maps for each cluster. The latter will be tedious if you need cluster-specific variables only for a handful of clusters while the rest of your fleet should be configured in the same way. Better have env variables from cluster-specific config maps / secrets to overwrite global ones - like we do it with other options, too. Probably, partly overwriting (in case of same env variables) will be most convenient. |
Thanks for feedback, @FxKu . I'm also agree with approach to have a ConfigMap/Secret parameter for each cluster individually if needed and present. If you agree with this approach I will add these options to the CRD and implement logic to overwrite global parameters if CR parameters are present and find in the cluster ConfigMap/Secret. |
I‘m looking forward to the progress of this PR. |
@cdmikechen note that you can already run multiple operators next to each other configured differently. They could either watch only one namespace or you define a CONTROLLER_ID in deployment and manifests to specify ownership over clusters. |
@FxKu |
@FxKu please have a look at the new approach with individual |
Hi @dmvolod, thanks for this PR. Do you still plan to add the possibility to refer to a cluster specific secret for environment variables in the postgresql custom resource? I’ve a slightly different set of requirements, where we maintain our cluster configuration in Git, but aren’t allowed to store confidential information (like wal-g backup settings) in plain text. To circumvent this, we use SealedSecrets [1] to store the settings encrypted in Git. In our k8s cluster the SealedSecrets get decrypted into normal secrets that can be used by the cluster. I’ve also the requirement that we’ve multiple postgresql clusters in the same namespace, and the need that they use different wal-g backup settings. Therefore, it would be great if in addition to use individual [1] https://github.com/bitnami-labs/sealed-secrets |
Hi @gc-jro ! Yes, sure. Could you please to have a look at the What do you think about it? |
Ah I see. Thanks a lot for clearing that up for me. I really like it, it'll solve all my problems 😄 I'll just have to define something like apiVersion: v1
kind: Secret
metadata:
name: wal-g-envs
namespace: yyy
data:
BACKUP_NUM_TO_RETAIN: xxx
...
---
apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
name: wal01-postgres-cluster
namespace: yyy
spec:
teamId: "wal01"
volume:
size: 20Gi
env:
- name: BACKUP_NUM_TO_RETAIN
valueFrom:
secretKeyRef:
key: BACKUP_NUM_TO_RETAIN
name: wal-g-envs
... to forward the values from the secret to the database. Very neat. Thank you very much. I can't wait to give it a spin once its merged into master. |
Thank @dmvolod ! Like the new approach much better. As you already pointed out, docs and unit test are the remaining bits to get this merged. |
I got it working now. See my gist: https://gist.github.com/FxKu/0b4e0641f1c846a2a0edbc2c6ee6a0cc |
Thanks for test, @FxKu |
pkg/cluster/k8sres.go
Outdated
} | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it might be even better to do isEnvVarPresent
in generateSpiloPodEnvVars, too, instead of appending duplicate variables and resolving it later with deduplicateEnvVars
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix logic, please review.
envVarConstant: "WAL_S3_BUCKET", | ||
envVarValue: "custom-s3-bucket", | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom variables should not be pre-pended so this addition is also obsolete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is approach from the following point
- A custom variable called like a hard-coded variable that can be overridden (like WAL_S3_BUCKET)
}, | ||
}, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should incl. 3 kinds of variables - like in my gist.
- A custom variable called like a hard-coded variable that cannot be overridden (I uses
KUBERNETES_SCOPE_LABEL
) - A custom variable called like a hard-coded variable that can be overridden (like WAL_S3_BUCKET)
- And a custom variable that's not in the list of hard-coded variables. And there we can test, if a variable from c.Spec.Env overwrites on from environment ConfigMap and/or Secret.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks will implement this options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented tests, please review.
Ok aside from missing unit tests there's one problem that has to be fixed. Right now we only append env vars and rely on This logic will not work anymore now that we have a third layer, the cluster-specific
That's why I suggested that we should not simply append to the list of envVars but only do so if the key does not exists yet. So basically what you partly did with |
Does it means that we need to utilize new |
Yes, inside
I don't see why anything related to spilo env vars should happen outside of |
Thanks for idea, please have a look at the code. Added functions and changed from plain |
👍 |
1 similar comment
👍 |
Thanks @dmvolod for your contribution. Good collaboration! |
Thanks @FxKu and @sdudoladov for review and ideas. |
Fixes #1566
Closes #1209
Closes #1422
Closes #907
Closes #1807
Please pay attention, that this PR implementing an individual
[]EnvVar
option to the cluster CR and has higher priority to the clusterpod_environment_secret
andpod_environment_configmap
options.TODO (after approach approve)