Skip to content

Commit 60ca7c5

Browse files
committed
Bug: Fix incorrect deployment annotations
Problem: When OLM checks that the Operator's Deployment was created with the correct annotations, it will not update and redeploy the operator if the annotations are incorrect. Cause: This issue was found when creating an Operator in an OperatorGroup that uses a LabelSelector to identify namespaces in the OperatorGroup. When the operator is created, the set of namespaces returned by the LabelSelector may be different from the set of namespaces when checking the deployment annotations. Solution: OLM should rebuild the deployment with the correct set of annotations.
1 parent c7e4266 commit 60ca7c5

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

pkg/controller/install/deployment.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ func (i *StrategyDeploymentInstaller) checkForDeployments(deploymentSpecs []v1al
253253
return StrategyError{Reason: StrategyErrReasonAnnotationsMissing, Message: fmt.Sprintf("no annotations found on deployment")}
254254
}
255255
for key, value := range i.templateAnnotations {
256-
if dep.Spec.Template.Annotations[key] != value {
257-
return StrategyError{Reason: StrategyErrReasonAnnotationsMissing, Message: fmt.Sprintf("annotations on deployment don't match. couldn't find %s: %s", key, value)}
256+
if actualValue, ok := dep.Spec.Template.Annotations[key]; !ok {
257+
return StrategyError{Reason: StrategyErrReasonAnnotationsMissing, Message: fmt.Sprintf("annotations on deployment does not contain expected key: %s", key)}
258+
} else if dep.Spec.Template.Annotations[key] != value {
259+
return StrategyError{Reason: StrategyErrReasonAnnotationsMissing, Message: fmt.Sprintf("unexpected annotation on deployment. Expected %s:%s, found %s:%s", key, value, key, actualValue)}
258260
}
259261
}
260262

pkg/controller/operators/olm/operator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,8 @@ func (a *Operator) updateInstallStatus(csv *v1alpha1.ClusterServiceVersion, inst
17751775
}
17761776

17771777
if strategyErr != nil {
1778-
if install.ReasonForError(strategyErr) == install.StrategyErrDeploymentUpdated {
1778+
reasonForError := install.ReasonForError(strategyErr)
1779+
if reasonForError == install.StrategyErrDeploymentUpdated || reasonForError == install.StrategyErrReasonAnnotationsMissing {
17791780
csv.SetPhaseWithEventIfChanged(v1alpha1.CSVPhaseInstallReady, requeueConditionReason, fmt.Sprintf("installing: %s", strategyErr), now, a.recorder)
17801781
} else {
17811782
csv.SetPhaseWithEventIfChanged(requeuePhase, requeueConditionReason, fmt.Sprintf("installing: %s", strategyErr), now, a.recorder)

pkg/controller/operators/olm/operator_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,32 @@ func TestTransitionCSV(t *testing.T) {
22732273
},
22742274
},
22752275
},
2276+
{
2277+
name: "SingleCSVInstallingToInstallReadyDueToAnnotations",
2278+
initial: initial{
2279+
csvs: []runtime.Object{
2280+
csvWithAnnotations(csv("csv1",
2281+
namespace,
2282+
"0.0.0",
2283+
"",
2284+
installStrategy("csv1-dep1", nil, nil),
2285+
[]*apiextensionsv1.CustomResourceDefinition{},
2286+
[]*apiextensionsv1.CustomResourceDefinition{},
2287+
v1alpha1.CSVPhaseInstalling,
2288+
), defaultTemplateAnnotations),
2289+
},
2290+
clientObjs: []runtime.Object{defaultOperatorGroup},
2291+
crds: []runtime.Object{},
2292+
objs: []runtime.Object{
2293+
deployment("csv1-dep1", namespace, "sa", map[string]string{}),
2294+
},
2295+
},
2296+
expected: expected{
2297+
csvStates: map[string]csvState{
2298+
"csv1": {exists: true, phase: v1alpha1.CSVPhaseInstallReady, reason: ""},
2299+
},
2300+
},
2301+
},
22762302
{
22772303
name: "SingleCSVSucceededToSucceeded/UnmanagedDeploymentInNamespace",
22782304
initial: initial{

0 commit comments

Comments
 (0)