Skip to content

Commit 35d4050

Browse files
committed
OperatorConditions can fight over dep envvars
Problem: If two OperatorConditions exist which target the same Deployment, they will both update the environment variables to with their name. Solution: Only allow OperatorConditions to update a deployment's environment variables if the deployment is owned by a CSV with the same name of the OperatorCondition.
1 parent ffb66b0 commit 35d4050

File tree

2 files changed

+248
-139
lines changed

2 files changed

+248
-139
lines changed

pkg/controller/operators/operatorcondition_controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"sigs.k8s.io/controller-runtime/pkg/source"
2020

2121
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
22+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2223
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
2324
)
2425

@@ -201,6 +202,13 @@ func (r *OperatorConditionReconciler) ensureDeploymentEnvVars(operatorCondition
201202
if err != nil {
202203
return err
203204
}
205+
206+
// Check the deployment is owned by CSV Owner before updating the deployment EnvVars.
207+
deploymentOwner := ownerutil.GetOwnerByKind(deployment, operatorsv1alpha1.ClusterServiceVersionKind)
208+
if deploymentOwner == nil || deploymentOwner.Name != operatorCondition.GetName() {
209+
continue
210+
}
211+
204212
deploymentNeedsUpdate := false
205213
for i := range deployment.Spec.Template.Spec.Containers {
206214
envVars, containedEnvVar := ensureEnvVarIsPresent(deployment.Spec.Template.Spec.Containers[i].Env, corev1.EnvVar{Name: OperatorConditionEnvVarKey, Value: operatorCondition.GetName()})

0 commit comments

Comments
 (0)