Skip to content

Commit 0919c12

Browse files
committed
Multiple operatorconditions should not update the same deployment
Problem: If two OperatorConditions exist which target the same Deployment, they will both update the environment variables with their name continuously. 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 72d0608 commit 0919c12

File tree

3 files changed

+298
-219
lines changed

3 files changed

+298
-219
lines changed

pkg/controller/operators/operatorcondition_controller.go

+8
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 a CSV with the same name as the OperatorCondition.
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)