Skip to content

Commit 41805e1

Browse files
committed
emit specific events for version changes
1 parent b428a47 commit 41805e1

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎pkg/operator/status/status_controller.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewClusterOperatorStatusController(
8787
func (c StatusSyncer) sync() error {
8888
detailedSpec, currentDetailedStatus, _, err := c.operatorClient.GetOperatorState()
8989
if apierrors.IsNotFound(err) {
90-
c.eventRecorder.Warningf("StatusNotFound", "Unable to determine current operator status for %s", c.clusterOperatorName)
90+
c.eventRecorder.Warningf("StatusNotFound", "Unable to determine current operator status for clusteroperator/%s", c.clusterOperatorName)
9191
if err := c.clusterOperatorClient.ClusterOperators().Delete(c.clusterOperatorName, nil); err != nil && !apierrors.IsNotFound(err) {
9292
return err
9393
}
@@ -99,7 +99,7 @@ func (c StatusSyncer) sync() error {
9999

100100
originalClusterOperatorObj, err := c.clusterOperatorLister.Get(c.clusterOperatorName)
101101
if err != nil && !apierrors.IsNotFound(err) {
102-
c.eventRecorder.Warningf("StatusFailed", "Unable to get current operator status for %s: %v", c.clusterOperatorName, err)
102+
c.eventRecorder.Warningf("StatusFailed", "Unable to get current operator status for clusteroperator/%s: %v", c.clusterOperatorName, err)
103103
return err
104104
}
105105

@@ -150,7 +150,11 @@ func (c StatusSyncer) sync() error {
150150
// TODO work out removal. We don't always know the existing value, so removing early seems like a bad idea. Perhaps a remove flag.
151151
versions := c.versionGetter.GetVersions()
152152
for operand, version := range versions {
153-
operatorv1helpers.SetOperandVersion(&clusterOperatorObj.Status.Versions, configv1.OperandVersion{Name: operand, Version: version})
153+
previousVersion := operatorv1helpers.SetOperandVersion(&clusterOperatorObj.Status.Versions, configv1.OperandVersion{Name: operand, Version: version})
154+
if previousVersion != version {
155+
// having this message will give us a marker in events when the operator updated compared to when the operand is updated
156+
c.eventRecorder.Eventf("OperatorVersionChanged", "clusteroperator/%s version %q changed from %q to %q", c.clusterOperatorName, operand, previousVersion, version)
157+
}
154158
}
155159

156160
// if we have no diff, just return
@@ -162,7 +166,7 @@ func (c StatusSyncer) sync() error {
162166
if _, updateErr := c.clusterOperatorClient.ClusterOperators().UpdateStatus(clusterOperatorObj); err != nil {
163167
return updateErr
164168
}
165-
c.eventRecorder.Eventf("OperatorStatusChanged", "Status for operator %s changed: %s", c.clusterOperatorName, configv1helpers.GetStatusDiff(originalClusterOperatorObj.Status, clusterOperatorObj.Status))
169+
c.eventRecorder.Eventf("OperatorStatusChanged", "Status for clusteroperator/%s changed: %s", c.clusterOperatorName, configv1helpers.GetStatusDiff(originalClusterOperatorObj.Status, clusterOperatorObj.Status))
166170
return nil
167171
}
168172

‎pkg/operator/v1helpers/helpers.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ import (
2121
operatorv1 "github.com/openshift/api/operator/v1"
2222
)
2323

24-
func SetOperandVersion(versions *[]configv1.OperandVersion, operandVersion configv1.OperandVersion) {
24+
// SetOperandVersion sets the new version and returns the previous value.
25+
func SetOperandVersion(versions *[]configv1.OperandVersion, operandVersion configv1.OperandVersion) string {
2526
if versions == nil {
2627
versions = &[]configv1.OperandVersion{}
2728
}
2829
existingVersion := FindOperandVersion(*versions, operandVersion.Name)
2930
if existingVersion == nil {
3031
*versions = append(*versions, operandVersion)
31-
return
32+
return ""
3233
}
34+
35+
previous := existingVersion.Version
3336
existingVersion.Version = operandVersion.Version
37+
return previous
3438
}
3539

3640
func FindOperandVersion(versions []configv1.OperandVersion, name string) *configv1.OperandVersion {

0 commit comments

Comments
 (0)