-
Notifications
You must be signed in to change notification settings - Fork 16
ESO-334: Adds implementation logic for Environment Variables to support customizations at install time #106
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -661,7 +661,7 @@ func (r *Reconciler) removeTrustedCAVolumeMount(container *corev1.Container) { | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // applyUserDeploymentConfigs updates the deployment resource spec with user specified configurations. | ||||||||||||||||||||||||||||||||||||||||||||||
| func (r *Reconciler) applyUserDeploymentConfigs(deployment *appsv1.Deployment, esc *operatorv1alpha1.ExternalSecretsConfig, assetName string) error { | ||||||||||||||||||||||||||||||||||||||||||||||
| componentName, err := getComponentNameFromAsset(assetName) | ||||||||||||||||||||||||||||||||||||||||||||||
| componentName, containerName, err := getComponentNameFromAsset(assetName) | ||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -672,25 +672,60 @@ func (r *Reconciler) applyUserDeploymentConfigs(deployment *appsv1.Deployment, e | |||||||||||||||||||||||||||||||||||||||||||||
| if i.DeploymentConfigs != nil && i.DeploymentConfigs.RevisionHistoryLimit != nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| deployment.Spec.RevisionHistoryLimit = i.DeploymentConfigs.RevisionHistoryLimit | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Apply OverrideEnv if set | ||||||||||||||||||||||||||||||||||||||||||||||
| if len(i.OverrideEnv) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||
| for j := range deployment.Spec.Template.Spec.Containers { | ||||||||||||||||||||||||||||||||||||||||||||||
| if deployment.Spec.Template.Spec.Containers[j].Name == containerName { | ||||||||||||||||||||||||||||||||||||||||||||||
| mergeEnvVars(&deployment.Spec.Template.Spec.Containers[j], i.OverrideEnv) | ||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| // Apply to all init containers in the deployment without name filtering, | ||||||||||||||||||||||||||||||||||||||||||||||
| for j := range deployment.Spec.Template.Spec.InitContainers { | ||||||||||||||||||||||||||||||||||||||||||||||
| mergeEnvVars(&deployment.Spec.Template.Spec.InitContainers[j], i.OverrideEnv) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+676
to
+688
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OverrideEnv is applied to all init containers—potential secret leakage. 🛠️ Option: restrict overrideEnv to the target container only- // Apply to all init containers in the deployment without name filtering,
- for j := range deployment.Spec.Template.Spec.InitContainers {
- mergeEnvVars(&deployment.Spec.Template.Spec.InitContainers[j], i.OverrideEnv)
- }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @siddhibhor-56 I think we should consider, though I had suggested we consider init containers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // getComponentNameFromAsset maps asset file names to ComponentName enum values. | ||||||||||||||||||||||||||||||||||||||||||||||
| func getComponentNameFromAsset(assetName string) (operatorv1alpha1.ComponentName, error) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // mergeEnvVars merges user-defined environment variables into a container, User-defined values take precedence over existing values. | ||||||||||||||||||||||||||||||||||||||||||||||
| func mergeEnvVars(container *corev1.Container, overrideEnv []corev1.EnvVar) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if container.Env == nil { | ||||||||||||||||||||||||||||||||||||||||||||||
| container.Env = []corev1.EnvVar{} | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| for _, override := range overrideEnv { | ||||||||||||||||||||||||||||||||||||||||||||||
| found := false | ||||||||||||||||||||||||||||||||||||||||||||||
| for i, existing := range container.Env { | ||||||||||||||||||||||||||||||||||||||||||||||
| if existing.Name == override.Name { | ||||||||||||||||||||||||||||||||||||||||||||||
| container.Env[i] = override // User-defined value takes precedence | ||||||||||||||||||||||||||||||||||||||||||||||
| found = true | ||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if !found { | ||||||||||||||||||||||||||||||||||||||||||||||
| container.Env = append(container.Env, override) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // getComponentNameFromAsset maps asset file names to ComponentName enum values and container names. | ||||||||||||||||||||||||||||||||||||||||||||||
| func getComponentNameFromAsset(assetName string) (operatorv1alpha1.ComponentName, string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||
| switch assetName { | ||||||||||||||||||||||||||||||||||||||||||||||
| case controllerDeploymentAssetName: | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.CoreController, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.CoreController, controllerContainerName, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| case webhookDeploymentAssetName: | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.Webhook, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.Webhook, webhookContainerName, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| case certControllerDeploymentAssetName: | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.CertController, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.CertController, certControllerContainerName, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| case bitwardenDeploymentAssetName: | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.BitwardenSDKServer, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| return operatorv1alpha1.BitwardenSDKServer, bitwardenContainerName, nil | ||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||
| return "", fmt.Errorf("unknown deployment asset name: %s", assetName) | ||||||||||||||||||||||||||||||||||||||||||||||
| return "", "", fmt.Errorf("unknown deployment asset name: %s", assetName) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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 doesn't look right. These consts can be defined in this file along with others after line 77 with proper comment.