Skip to content

Commit

Permalink
Refactor version sync to standalone method
Browse files Browse the repository at this point in the history
  • Loading branch information
jsafrane committed Apr 14, 2023
1 parent a704a57 commit 2386867
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pkg/operator/status/status_controller.go
Expand Up @@ -194,15 +194,7 @@ func (c StatusSyncer) Sync(ctx context.Context, syncCtx factory.SyncContext) err
configv1helpers.SetStatusCondition(&clusterOperatorObj.Status.Conditions, UnionClusterCondition("Available", operatorv1.ConditionTrue, nil, currentDetailedStatus.Conditions...))
configv1helpers.SetStatusCondition(&clusterOperatorObj.Status.Conditions, UnionClusterCondition("Upgradeable", operatorv1.ConditionTrue, nil, currentDetailedStatus.Conditions...))

// TODO work out removal. We don't always know the existing value, so removing early seems like a bad idea. Perhaps a remove flag.
versions := c.versionGetter.GetVersions()
for operand, version := range versions {
previousVersion := operatorv1helpers.SetOperandVersion(&clusterOperatorObj.Status.Versions, configv1.OperandVersion{Name: operand, Version: version})
if previousVersion != version {
// having this message will give us a marker in events when the operator updated compared to when the operand is updated
syncCtx.Recorder().Eventf("OperatorVersionChanged", "clusteroperator/%s version %q changed from %q to %q", c.clusterOperatorName, operand, previousVersion, version)
}
}
c.syncStatusVersions(clusterOperatorObj, syncCtx)

// if we have no diff, just return
if equality.Semantic.DeepEqual(clusterOperatorObj, originalClusterOperatorObj) {
Expand All @@ -217,6 +209,18 @@ func (c StatusSyncer) Sync(ctx context.Context, syncCtx factory.SyncContext) err
return nil
}

func (c StatusSyncer) syncStatusVersions(clusterOperatorObj *configv1.ClusterOperator, syncCtx factory.SyncContext) {
// TODO work out removal. We don't always know the existing value, so removing early seems like a bad idea. Perhaps a remove flag.
versions := c.versionGetter.GetVersions()
for operand, version := range versions {
previousVersion := operatorv1helpers.SetOperandVersion(&clusterOperatorObj.Status.Versions, configv1.OperandVersion{Name: operand, Version: version})
if previousVersion != version {
// having this message will give us a marker in events when the operator updated compared to when the operand is updated
syncCtx.Recorder().Eventf("OperatorVersionChanged", "clusteroperator/%s version %q changed from %q to %q", c.clusterOperatorName, operand, previousVersion, version)
}
}
}

func (c *StatusSyncer) watchVersionGetterPostRunHook(ctx context.Context, syncCtx factory.SyncContext) error {
defer utilruntime.HandleCrash()

Expand Down

0 comments on commit 2386867

Please sign in to comment.