Skip to content

Commit 5ab8acb

Browse files
committed
feat(operatorstatus): report packageserver as upgradeable
1 parent 53524d1 commit 5ab8acb

File tree

4 files changed

+126
-12
lines changed

4 files changed

+126
-12
lines changed

pkg/lib/operatorstatus/builder.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ func (b *Builder) WithAvailable(status configv1.ConditionStatus, message string)
7171
return b
7272
}
7373

74+
// WithUpgradeable sets an OperatorUpgradeable type condition.
75+
func (b *Builder) WithUpgradeable(status configv1.ConditionStatus, message string) *Builder {
76+
b.init()
77+
condition := &configv1.ClusterOperatorStatusCondition{
78+
Type: configv1.OperatorUpgradeable,
79+
Status: status,
80+
Message: message,
81+
LastTransitionTime: metav1.NewTime(b.clock.Now()),
82+
}
83+
84+
b.setCondition(condition)
85+
86+
return b
87+
}
88+
7489
// WithVersion adds the specific version into the status.
7590
func (b *Builder) WithVersion(name, version string) *Builder {
7691
b.init()

pkg/lib/operatorstatus/builder_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,90 @@ func TestBuilder(t *testing.T) {
105105
},
106106
},
107107

108+
// Condition: (Upgradeable, True).
109+
// existing status.Conditions is empty.
110+
{
111+
name: "WithUpgradeable/NoUpgradeableConditionPresentInExistingStatus",
112+
action: func(b *Builder) {
113+
b.WithUpgradeable(configv1.ConditionTrue, "message")
114+
},
115+
expected: &configv1.ClusterOperatorStatus{
116+
Conditions: []configv1.ClusterOperatorStatusCondition{
117+
{
118+
Type: configv1.OperatorUpgradeable,
119+
Status: configv1.ConditionTrue,
120+
Message: "message",
121+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
122+
},
123+
},
124+
Versions: []configv1.OperandVersion{},
125+
RelatedObjects: []configv1.ObjectReference{},
126+
},
127+
},
128+
129+
// Condition: (Upgradeable, True).
130+
// (Upgradeable, False) is already present in existing status.Conditions.
131+
{
132+
name: "WithUpgradeable/UpgradeableConditionPresentInExistingStatus",
133+
action: func(b *Builder) {
134+
b.WithUpgradeable(configv1.ConditionTrue, "message")
135+
},
136+
existing: &configv1.ClusterOperatorStatus{
137+
Conditions: []configv1.ClusterOperatorStatusCondition{
138+
{
139+
Type: configv1.OperatorUpgradeable,
140+
Status: configv1.ConditionFalse,
141+
},
142+
},
143+
Versions: []configv1.OperandVersion{},
144+
RelatedObjects: []configv1.ObjectReference{},
145+
},
146+
expected: &configv1.ClusterOperatorStatus{
147+
Conditions: []configv1.ClusterOperatorStatusCondition{
148+
{
149+
Type: configv1.OperatorUpgradeable,
150+
Status: configv1.ConditionTrue,
151+
Message: "message",
152+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
153+
},
154+
},
155+
Versions: []configv1.OperandVersion{},
156+
RelatedObjects: []configv1.ObjectReference{},
157+
},
158+
},
159+
160+
// Condition: (Upgradeable, True).
161+
// (Upgradeable, True) is already present in existing status.Conditions.
162+
{
163+
name: "WithUpgradeable/UpgradeableConditionMatchesInExistingStatus",
164+
action: func(b *Builder) {
165+
b.WithUpgradeable(configv1.ConditionTrue, "message")
166+
},
167+
existing: &configv1.ClusterOperatorStatus{
168+
Conditions: []configv1.ClusterOperatorStatusCondition{
169+
{
170+
Type: configv1.OperatorUpgradeable,
171+
Status: configv1.ConditionTrue,
172+
LastTransitionTime: minuteAgo,
173+
},
174+
},
175+
Versions: []configv1.OperandVersion{},
176+
RelatedObjects: []configv1.ObjectReference{},
177+
},
178+
expected: &configv1.ClusterOperatorStatus{
179+
Conditions: []configv1.ClusterOperatorStatusCondition{
180+
{
181+
Type: configv1.OperatorUpgradeable,
182+
Status: configv1.ConditionTrue,
183+
Message: "message",
184+
LastTransitionTime: minuteAgo,
185+
},
186+
},
187+
Versions: []configv1.OperandVersion{},
188+
RelatedObjects: []configv1.ObjectReference{},
189+
},
190+
},
191+
108192
// A new version is being added to status.
109193
// Existing status does not have any matching name.
110194
{

pkg/lib/operatorstatus/csv_reporter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func (r *csvStatusReporter) GetNewStatus(existing *configv1.ClusterOperatorStatu
6767
// We don't monitor whether the CSV backed operator is in degraded status.
6868
builder.WithDegraded(configv1.ConditionFalse)
6969

70+
// CSV status won't block cluster upgrades
71+
builder.WithUpgradeable(configv1.ConditionTrue, "Safe to upgrade")
72+
7073
// A CSV has been deleted.
7174
if context.CurrentDeleted {
7275
csv := context.Current

pkg/lib/operatorstatus/csv_reporter_test.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,23 @@ func TestGetNewStatus(t *testing.T) {
5050

5151
expected: &configv1.ClusterOperatorStatus{
5252
Conditions: []configv1.ClusterOperatorStatusCondition{
53-
configv1.ClusterOperatorStatusCondition{
53+
{
5454
Type: configv1.OperatorDegraded,
5555
Status: configv1.ConditionFalse,
5656
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
5757
},
58-
configv1.ClusterOperatorStatusCondition{
58+
{
59+
Type: configv1.OperatorUpgradeable,
60+
Status: configv1.ConditionTrue,
61+
Message: "Safe to upgrade",
62+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
63+
},
64+
{
5965
Type: configv1.OperatorAvailable,
6066
Status: configv1.ConditionFalse,
6167
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
6268
},
63-
configv1.ClusterOperatorStatusCondition{
69+
{
6470
Type: configv1.OperatorProgressing,
6571
Status: configv1.ConditionTrue,
6672
Message: "Working toward 1.0.0",
@@ -69,13 +75,13 @@ func TestGetNewStatus(t *testing.T) {
6975
},
7076
Versions: []configv1.OperandVersion{},
7177
RelatedObjects: []configv1.ObjectReference{
72-
configv1.ObjectReference{
78+
{
7379
Group: "",
7480
Resource: "namespaces",
7581
Namespace: "",
7682
Name: "foo-namespace",
7783
},
78-
configv1.ObjectReference{
84+
{
7985
Group: v1alpha1.GroupName,
8086
Resource: v1alpha1.ClusterServiceVersionKind,
8187
Namespace: "foo-namespace",
@@ -111,41 +117,47 @@ func TestGetNewStatus(t *testing.T) {
111117

112118
expected: &configv1.ClusterOperatorStatus{
113119
Conditions: []configv1.ClusterOperatorStatusCondition{
114-
configv1.ClusterOperatorStatusCondition{
120+
{
115121
Type: configv1.OperatorDegraded,
116122
Status: configv1.ConditionFalse,
117123
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
118124
},
119-
configv1.ClusterOperatorStatusCondition{
125+
{
126+
Type: configv1.OperatorUpgradeable,
127+
Status: configv1.ConditionTrue,
128+
Message: "Safe to upgrade",
129+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
130+
},
131+
{
120132
Type: configv1.OperatorAvailable,
121133
Status: configv1.ConditionTrue,
122134
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
123135
},
124-
configv1.ClusterOperatorStatusCondition{
136+
{
125137
Type: configv1.OperatorProgressing,
126138
Status: configv1.ConditionFalse,
127139
Message: "Deployed version 1.0.0",
128140
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
129141
},
130142
},
131143
Versions: []configv1.OperandVersion{
132-
configv1.OperandVersion{
144+
{
133145
Name: "operator",
134146
Version: "snapshot",
135147
},
136-
configv1.OperandVersion{
148+
{
137149
Name: "foo",
138150
Version: "1.0.0",
139151
},
140152
},
141153
RelatedObjects: []configv1.ObjectReference{
142-
configv1.ObjectReference{
154+
{
143155
Group: "",
144156
Resource: "namespaces",
145157
Namespace: "",
146158
Name: "foo-namespace",
147159
},
148-
configv1.ObjectReference{
160+
{
149161
Group: v1alpha1.GroupName,
150162
Resource: v1alpha1.ClusterServiceVersionKind,
151163
Namespace: "foo-namespace",

0 commit comments

Comments
 (0)