Skip to content

Commit 5bd6354

Browse files
Merge pull request #2140 from anik120/clusteroperator-reason
Set reason/message for Available condition in packageserver co
2 parents e65b9fb + c21dcfc commit 5bd6354

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

pkg/lib/operatorstatus/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ func (b *Builder) WithDegraded(status configv1.ConditionStatus) *Builder {
5757
}
5858

5959
// WithAvailable sets an OperatorAvailable type condition.
60-
func (b *Builder) WithAvailable(status configv1.ConditionStatus, message string) *Builder {
60+
func (b *Builder) WithAvailable(status configv1.ConditionStatus, message, reason string) *Builder {
6161
b.init()
6262
condition := &configv1.ClusterOperatorStatusCondition{
6363
Type: configv1.OperatorAvailable,
6464
Status: status,
6565
Message: message,
66+
Reason: reason,
6667
LastTransitionTime: metav1.NewTime(b.clock.Now()),
6768
}
6869

pkg/lib/operatorstatus/csv_reporter.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import (
1111
const (
1212
// versionName reflects the name of the version CVO expects in Status.
1313
versionName = "operator"
14+
15+
reasonCSVSucceeded = "ClusterServiceVersionSucceeded"
16+
17+
reasonCSVNotSucceeded = "ClusterServiceVersionNotSucceeded"
18+
19+
reasonCSVDeleted = "ClusterServiceVersionDeleted"
1420
)
1521

1622
// newCSVStatusReporter returns a new instance of CSVStatusReporter
@@ -80,7 +86,7 @@ func (r *csvStatusReporter) GetNewStatus(existing *configv1.ClusterOperatorStatu
8086

8187
if context.WorkingToward == nil {
8288
builder.WithProgressing(configv1.ConditionFalse, fmt.Sprintf("Uninstalled version %s", csv.Spec.Version)).
83-
WithAvailable(configv1.ConditionFalse, "")
89+
WithAvailable(configv1.ConditionFalse, fmt.Sprintf("Uninstalled version %s", csv.Spec.Version), reasonCSVDeleted)
8490

8591
return
8692
}
@@ -98,9 +104,9 @@ func (r *csvStatusReporter) GetNewStatus(existing *configv1.ClusterOperatorStatu
98104

99105
switch phase {
100106
case v1alpha1.CSVPhaseSucceeded:
101-
builder.WithAvailable(configv1.ConditionTrue, "")
107+
builder.WithAvailable(configv1.ConditionTrue, fmt.Sprintf("ClusterServiceVersion %v/%v is in phase %v", csv.Namespace, csv.Name, csv.Status.Phase), reasonCSVSucceeded)
102108
default:
103-
builder.WithAvailable(configv1.ConditionFalse, "")
109+
builder.WithAvailable(configv1.ConditionFalse, fmt.Sprintf("ClusterServiceVersion %v/%v is in phase %v with reason: %v, message: %v", csv.Namespace, csv.Name, csv.Status.Phase, csv.Status.Reason, csv.Status.Message), reasonCSVNotSucceeded)
104110
}
105111

106112
switch phase {

pkg/lib/operatorstatus/csv_reporter_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func TestGetNewStatus(t *testing.T) {
4343
},
4444
},
4545
Status: v1alpha1.ClusterServiceVersionStatus{
46-
Phase: v1alpha1.CSVPhasePending,
46+
Phase: v1alpha1.CSVPhasePending,
47+
Reason: v1alpha1.CSVReasonWaiting,
48+
Message: "Progressing towards 1.0.0",
4749
},
4850
},
4951
},
@@ -64,6 +66,8 @@ func TestGetNewStatus(t *testing.T) {
6466
{
6567
Type: configv1.OperatorAvailable,
6668
Status: configv1.ConditionFalse,
69+
Message: "ClusterServiceVersion foo-namespace/foo is in phase Pending with reason: InstallWaiting, message: Progressing towards 1.0.0",
70+
Reason: "ClusterServiceVersionNotSucceeded",
6771
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
6872
},
6973
{
@@ -131,6 +135,8 @@ func TestGetNewStatus(t *testing.T) {
131135
{
132136
Type: configv1.OperatorAvailable,
133137
Status: configv1.ConditionTrue,
138+
Message: "ClusterServiceVersion foo-namespace/foo is in phase Succeeded",
139+
Reason: "ClusterServiceVersionSucceeded",
134140
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
135141
},
136142
{

pkg/lib/operatorstatus/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func Waiting(clock clock.Clock, name string) *configv1.ClusterOperatorStatus {
199199
}
200200

201201
status := builder.WithDegraded(configv1.ConditionFalse).
202-
WithAvailable(configv1.ConditionFalse, "").
202+
WithAvailable(configv1.ConditionFalse, "", "").
203203
WithProgressing(configv1.ConditionTrue, fmt.Sprintf("waiting for events - source=%s", name)).
204204
GetStatus()
205205

0 commit comments

Comments
 (0)