Skip to content

Commit

Permalink
feat(operatorstatus): report packageserver as upgradeable
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Aug 16, 2019
1 parent 9cb8d1e commit 652070d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/lib/operatorstatus/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ func (b *Builder) WithAvailable(status configv1.ConditionStatus, message string)
return b
}

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

b.setCondition(condition)

return b
}

// WithVersion adds the specific version into the status.
func (b *Builder) WithVersion(name, version string) *Builder {
b.init()
Expand Down
84 changes: 84 additions & 0 deletions pkg/lib/operatorstatus/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,90 @@ func TestBuilder(t *testing.T) {
},
},

// Condition: (Upgradeable, True).
// existing status.Conditions is empty.
{
name: "WithUpgradeable/NoUpgradeableConditionPresentInExistingStatus",
action: func(b *Builder) {
b.WithUpgradeable(configv1.ConditionTrue, "message")
},
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorUpgradeable,
Status: configv1.ConditionTrue,
Message: "message",
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
},
},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{},
},
},

// Condition: (Upgradeable, True).
// (Upgradeable, False) is already present in existing status.Conditions.
{
name: "WithUpgradeable/UpgradeableConditionPresentInExistingStatus",
action: func(b *Builder) {
b.WithProgressing(configv1.ConditionTrue, "message")
},
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorUpgradeable,
Status: configv1.ConditionFalse,
},
},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{},
},
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorUpgradeable,
Status: configv1.ConditionTrue,
Message: "message",
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
},
},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{},
},
},

// Condition: (Upgradeable, True).
// (Upgradeable, True) is already present in existing status.Conditions.
{
name: "WithUpgradeable/UpgradeableConditionMatchesInExistingStatus",
action: func(b *Builder) {
b.WithProgressing(configv1.ConditionTrue, "message")
},
existing: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorUpgradeable,
Status: configv1.ConditionTrue,
LastTransitionTime: minuteAgo,
},
},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{},
},
expected: &configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorUpgradeable,
Status: configv1.ConditionTrue,
Message: "message",
LastTransitionTime: minuteAgo,
},
},
Versions: []configv1.OperandVersion{},
RelatedObjects: []configv1.ObjectReference{},
},
},

// A new version is being added to status.
// Existing status does not have any matching name.
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/lib/operatorstatus/csv_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func (r *csvStatusReporter) GetNewStatus(existing *configv1.ClusterOperatorStatu
// We don't monitor whether the CSV backed operator is in degraded status.
builder.WithDegraded(configv1.ConditionFalse)

// CSV status won't block cluster upgrades
builder.WithUpgradeable(configv1.ConditionTrue, "Safe to upgrade")

// A CSV has been deleted.
if context.CurrentDeleted {
csv := context.Current
Expand Down

0 comments on commit 652070d

Please sign in to comment.