Skip to content

Commit ea6f184

Browse files
committed
fix(olm): don't attempt to annotate deployments if the deployment hasn't
yet been created this should prevent some churn and possible races
1 parent b6ac382 commit ea6f184

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ setup-bare: clean e2e.namespace
7171
. ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources
7272

7373
e2e:
74-
go test -v -failfast -timeout 50m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager
74+
go test -v -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager
7575

7676
e2e-local:
7777
. ./scripts/build_local.sh

pkg/api/apis/operators/v1alpha1/clusterserviceversion.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ var uncopiableReasons = map[ConditionReason]struct{}{
3030
CSVReasonCannotModifyStaticOperatorGroupProvidedAPIs: {},
3131
}
3232

33+
// safeToAnnotateOperatorGroupReasons are the set of reasons that it's safe to attempt to update the operatorgroup
34+
// annotations
35+
var safeToAnnotateOperatorGroupReasons = map[ConditionReason]struct{}{
36+
CSVReasonOwnerConflict: {},
37+
CSVReasonInstallSuccessful: {},
38+
CSVReasonInvalidInstallModes: {},
39+
CSVReasonNoTargetNamespaces: {},
40+
CSVReasonUnsupportedOperatorGroup: {},
41+
CSVReasonNoOperatorGroup: {},
42+
CSVReasonTooManyOperatorGroups: {},
43+
CSVReasonInterOperatorGroupOwnerConflict: {},
44+
CSVReasonCannotModifyStaticOperatorGroupProvidedAPIs: {},
45+
}
46+
3347
// SetPhaseWithEventIfChanged emits a Kubernetes event with details of a phase change and sets the current phase if phase, reason, or message would changed
3448
func (c *ClusterServiceVersion) SetPhaseWithEventIfChanged(phase ClusterServiceVersionPhase, reason ConditionReason, message string, now metav1.Time, recorder record.EventRecorder) {
3549
if c.Status.Phase == phase && c.Status.Reason == reason && c.Status.Message == message {
@@ -120,6 +134,11 @@ func (c *ClusterServiceVersion) IsUncopiable() bool {
120134
return ok
121135
}
122136

137+
func (c *ClusterServiceVersion) IsSafeToUpdateOperatorGroupAnnotations() bool {
138+
_, ok := safeToAnnotateOperatorGroupReasons[c.Status.Reason]
139+
return ok
140+
}
141+
123142
// NewInstallModeSet returns an InstallModeSet instantiated from the given list of InstallModes.
124143
// If the given list is not a set, an error is returned.
125144
func NewInstallModeSet(modes []InstallMode) (InstallModeSet, error) {

pkg/controller/operators/olm/operator.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func NewOperator(logger *logrus.Logger, crClient versioned.Interface, opClient o
262262
op.RegisterQueueIndexer(csvQueueIndexer)
263263
op.copyQueueIndexer = csvQueueIndexer
264264

265-
// Register separate queue for copying csvs
265+
// Register separate queue for gcing csvs
266266
csvGCQueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "csvGC")
267267
csvGCQueueIndexer := queueinformer.NewQueueIndexer(csvGCQueue, csvIndexes, op.syncGcCsv, "csvGC", logger, metrics.NewMetricsNil())
268268
op.RegisterQueueIndexer(csvGCQueueIndexer)
@@ -513,7 +513,7 @@ func (a *Operator) removeDanglingChildCSVs(csv *v1alpha1.ClusterServiceVersion)
513513

514514
func (a *Operator) deleteChild(csv *v1alpha1.ClusterServiceVersion, logger *logrus.Entry) error {
515515
logger.Debug("gcing csv")
516-
return a.client.OperatorsV1alpha1().ClusterServiceVersions(csv.GetNamespace()).Delete(csv.GetName(), &metav1.DeleteOptions{})
516+
return a.client.OperatorsV1alpha1().ClusterServiceVersions(csv.GetNamespace()).Delete(csv.GetName(), metav1.NewDeleteOptions(0))
517517
}
518518

519519
// syncClusterServiceVersion is the method that gets called when we see a CSV event in the cluster
@@ -753,7 +753,6 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v
753753
return
754754
}
755755

756-
logger.Info("updated annotations to match current operatorgroup")
757756
if err := a.ensureDeploymentAnnotations(logger, out); err != nil {
758757
return nil, err
759758
}
@@ -1345,6 +1344,10 @@ func (a *Operator) cleanupCSVDeployments(logger *logrus.Entry, csv *v1alpha1.Clu
13451344
}
13461345

13471346
func (a *Operator) ensureDeploymentAnnotations(logger *logrus.Entry, csv *v1alpha1.ClusterServiceVersion) error {
1347+
if !csv.IsSafeToUpdateOperatorGroupAnnotations() {
1348+
return nil
1349+
}
1350+
13481351
// Get csv operatorgroup annotations
13491352
annotations := a.copyOperatorGroupAnnotations(&csv.ObjectMeta)
13501353

@@ -1376,7 +1379,6 @@ func (a *Operator) ensureDeploymentAnnotations(logger *logrus.Entry, csv *v1alph
13761379
for _, d := range existingDeployments {
13771380
existingMap[d.GetName()] = d
13781381
}
1379-
13801382
updateErrs := []error{}
13811383
for _, dep := range existingMap {
13821384
if dep.Spec.Template.Annotations == nil {
@@ -1389,5 +1391,7 @@ func (a *Operator) ensureDeploymentAnnotations(logger *logrus.Entry, csv *v1alph
13891391
updateErrs = append(updateErrs, err)
13901392
}
13911393
}
1394+
logger.Info("updated annotations to match current operatorgroup")
1395+
13921396
return utilerrors.NewAggregate(updateErrs)
13931397
}

scripts/run_e2e_local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ else
5858
fi
5959

6060
echo "${test_flags}"
61-
go test -mod=vendor -count=1 -failfast -tags=local -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 20m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace}-operator -olmNamespace=${namespace}
61+
go test -mod=vendor -count=1 -failfast -tags=local -covermode=count -coverpkg ./pkg/controller/... -test.v -test.timeout 30m ${test_flags} ./test/e2e/... -kubeconfig=${KUBECONFIG:-~/.kube/config} -namespace=${namespace}-operator -olmNamespace=${namespace}

0 commit comments

Comments
 (0)