Skip to content

[release-4.7] Bug 1962302: Set reason/message for Available condition in packageserver co #2168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/lib/operatorstatus/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ func (b *Builder) WithDegraded(status configv1.ConditionStatus) *Builder {
}

// WithAvailable sets an OperatorAvailable type condition.
func (b *Builder) WithAvailable(status configv1.ConditionStatus, message string) *Builder {
func (b *Builder) WithAvailable(status configv1.ConditionStatus, message, reason string) *Builder {
b.init()
condition := &configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorAvailable,
Status: status,
Message: message,
Reason: reason,
LastTransitionTime: metav1.NewTime(b.clock.Now()),
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/lib/operatorstatus/csv_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
const (
// versionName reflects the name of the version CVO expects in Status.
versionName = "operator"

reasonCSVSucceeded = "ClusterServiceVersionSucceeded"

reasonCSVNotSucceeded = "ClusterServiceVersionNotSucceeded"

reasonCSVDeleted = "ClusterServiceVersionDeleted"
)

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

if context.WorkingToward == nil {
builder.WithProgressing(configv1.ConditionFalse, fmt.Sprintf("Uninstalled version %s", csv.Spec.Version)).
WithAvailable(configv1.ConditionFalse, "")
WithAvailable(configv1.ConditionFalse, fmt.Sprintf("Uninstalled version %s", csv.Spec.Version), reasonCSVDeleted)

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

switch phase {
case v1alpha1.CSVPhaseSucceeded:
builder.WithAvailable(configv1.ConditionTrue, "")
builder.WithAvailable(configv1.ConditionTrue, fmt.Sprintf("ClusterServiceVersion %v/%v is in phase %v", csv.Namespace, csv.Name, csv.Status.Phase), reasonCSVSucceeded)
default:
builder.WithAvailable(configv1.ConditionFalse, "")
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)
}

switch phase {
Expand Down
8 changes: 7 additions & 1 deletion pkg/lib/operatorstatus/csv_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func TestGetNewStatus(t *testing.T) {
},
},
Status: v1alpha1.ClusterServiceVersionStatus{
Phase: v1alpha1.CSVPhasePending,
Phase: v1alpha1.CSVPhasePending,
Reason: v1alpha1.CSVReasonWaiting,
Message: "Progressing towards 1.0.0",
},
},
},
Expand All @@ -64,6 +66,8 @@ func TestGetNewStatus(t *testing.T) {
{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionFalse,
Message: "ClusterServiceVersion foo-namespace/foo is in phase Pending with reason: InstallWaiting, message: Progressing towards 1.0.0",
Reason: "ClusterServiceVersionNotSucceeded",
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
},
{
Expand Down Expand Up @@ -131,6 +135,8 @@ func TestGetNewStatus(t *testing.T) {
{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionTrue,
Message: "ClusterServiceVersion foo-namespace/foo is in phase Succeeded",
Reason: "ClusterServiceVersionSucceeded",
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
},
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/operatorstatus/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func Waiting(clock clock.Clock, name string) *configv1.ClusterOperatorStatus {
}

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

Expand Down