Skip to content

Commit ac1f901

Browse files
Merge pull request #2177 from openshift-cherrypick-robot/cherry-pick-2173-to-release-4.6
[release-4.6] Bug 1965307: Make ClusterOperator Available condition sticky.
2 parents b31c4ba + 7e68dc0 commit ac1f901

File tree

2 files changed

+160
-8
lines changed

2 files changed

+160
-8
lines changed

pkg/lib/operatorstatus/csv_reporter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ func (r *csvStatusReporter) GetNewStatus(existing *configv1.ClusterOperatorStatu
104104

105105
switch phase {
106106
case v1alpha1.CSVPhaseSucceeded:
107-
builder.WithAvailable(configv1.ConditionTrue, fmt.Sprintf("ClusterServiceVersion %v/%v is in phase %v", csv.Namespace, csv.Name, csv.Status.Phase), reasonCSVSucceeded)
108-
default:
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)
107+
builder.WithAvailable(configv1.ConditionTrue, fmt.Sprintf("ClusterServiceVersion %v/%v observed in phase %v", csv.Namespace, csv.Name, csv.Status.Phase), reasonCSVSucceeded)
108+
case v1alpha1.CSVPhaseFailed:
109+
builder.WithAvailable(configv1.ConditionFalse, fmt.Sprintf("ClusterServiceVersion %v/%v observed in phase %v with reason: %v, message: %v", csv.Namespace, csv.Name, csv.Status.Phase, csv.Status.Reason, csv.Status.Message), reasonCSVNotSucceeded)
110110
}
111111

112112
switch phase {

pkg/lib/operatorstatus/csv_reporter_test.go

Lines changed: 157 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,165 @@ func TestGetNewStatus(t *testing.T) {
6363
Message: "Safe to upgrade",
6464
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
6565
},
66+
{
67+
Type: configv1.OperatorProgressing,
68+
Status: configv1.ConditionTrue,
69+
Message: "Working toward 1.0.0",
70+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
71+
},
72+
},
73+
Versions: []configv1.OperandVersion{},
74+
RelatedObjects: []configv1.ObjectReference{
75+
{
76+
Group: "",
77+
Resource: "namespaces",
78+
Namespace: "",
79+
Name: "foo-namespace",
80+
},
81+
{
82+
Group: v1alpha1.GroupName,
83+
Resource: clusterServiceVersionResource,
84+
Namespace: "foo-namespace",
85+
Name: "foo",
86+
},
87+
},
88+
},
89+
},
90+
91+
{
92+
name: "WithCSVInProgressAlreadyAvailableTrue",
93+
context: &csvEventContext{
94+
Name: "foo",
95+
CurrentDeleted: false,
96+
Current: &v1alpha1.ClusterServiceVersion{
97+
ObjectMeta: metav1.ObjectMeta{
98+
Name: "foo",
99+
Namespace: "foo-namespace",
100+
},
101+
Spec: v1alpha1.ClusterServiceVersionSpec{
102+
Version: version.OperatorVersion{
103+
semver.Version{
104+
Major: 1, Minor: 0, Patch: 0,
105+
},
106+
},
107+
},
108+
Status: v1alpha1.ClusterServiceVersionStatus{
109+
Phase: v1alpha1.CSVPhasePending,
110+
Reason: v1alpha1.CSVReasonWaiting,
111+
Message: "Progressing towards 1.0.0",
112+
},
113+
},
114+
},
115+
existing: &configv1.ClusterOperatorStatus{
116+
Conditions: []configv1.ClusterOperatorStatusCondition{
117+
{
118+
Type: configv1.OperatorAvailable,
119+
Status: configv1.ConditionTrue,
120+
Message: "test message",
121+
Reason: "test reason",
122+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
123+
},
124+
},
125+
},
126+
127+
expected: &configv1.ClusterOperatorStatus{
128+
Conditions: []configv1.ClusterOperatorStatusCondition{
66129
{
67130
Type: configv1.OperatorAvailable,
131+
Status: configv1.ConditionTrue,
132+
Message: "test message",
133+
Reason: "test reason",
134+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
135+
},
136+
{
137+
Type: configv1.OperatorDegraded,
68138
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",
139+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
140+
},
141+
{
142+
Type: configv1.OperatorUpgradeable,
143+
Status: configv1.ConditionTrue,
144+
Message: "Safe to upgrade",
145+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
146+
},
147+
{
148+
Type: configv1.OperatorProgressing,
149+
Status: configv1.ConditionTrue,
150+
Message: "Working toward 1.0.0",
151+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
152+
},
153+
},
154+
RelatedObjects: []configv1.ObjectReference{
155+
{
156+
Group: "",
157+
Resource: "namespaces",
158+
Namespace: "",
159+
Name: "foo-namespace",
160+
},
161+
{
162+
Group: v1alpha1.GroupName,
163+
Resource: clusterServiceVersionResource,
164+
Namespace: "foo-namespace",
165+
Name: "foo",
166+
},
167+
},
168+
},
169+
},
170+
171+
{
172+
name: "WithCSVInProgressAlreadyAvailableFalse",
173+
context: &csvEventContext{
174+
Name: "foo",
175+
CurrentDeleted: false,
176+
Current: &v1alpha1.ClusterServiceVersion{
177+
ObjectMeta: metav1.ObjectMeta{
178+
Name: "foo",
179+
Namespace: "foo-namespace",
180+
},
181+
Spec: v1alpha1.ClusterServiceVersionSpec{
182+
Version: version.OperatorVersion{
183+
semver.Version{
184+
Major: 1, Minor: 0, Patch: 0,
185+
},
186+
},
187+
},
188+
Status: v1alpha1.ClusterServiceVersionStatus{
189+
Phase: v1alpha1.CSVPhasePending,
190+
Reason: v1alpha1.CSVReasonWaiting,
191+
Message: "Progressing towards 1.0.0",
192+
},
193+
},
194+
},
195+
existing: &configv1.ClusterOperatorStatus{
196+
Conditions: []configv1.ClusterOperatorStatusCondition{
197+
{
198+
Type: configv1.OperatorAvailable,
199+
Status: configv1.ConditionFalse,
200+
Message: "test message",
201+
Reason: "test reason",
202+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
203+
},
204+
},
205+
},
206+
207+
expected: &configv1.ClusterOperatorStatus{
208+
Conditions: []configv1.ClusterOperatorStatusCondition{
209+
{
210+
Type: configv1.OperatorAvailable,
211+
Status: configv1.ConditionFalse,
212+
Message: "test message",
213+
Reason: "test reason",
214+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
215+
},
216+
{
217+
Type: configv1.OperatorDegraded,
218+
Status: configv1.ConditionFalse,
219+
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
220+
},
221+
{
222+
Type: configv1.OperatorUpgradeable,
223+
Status: configv1.ConditionTrue,
224+
Message: "Safe to upgrade",
71225
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
72226
},
73227
{
@@ -77,7 +231,6 @@ func TestGetNewStatus(t *testing.T) {
77231
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
78232
},
79233
},
80-
Versions: []configv1.OperandVersion{},
81234
RelatedObjects: []configv1.ObjectReference{
82235
{
83236
Group: "",
@@ -95,7 +248,6 @@ func TestGetNewStatus(t *testing.T) {
95248
},
96249
},
97250

98-
// A CSV has successfully installed.
99251
{
100252
name: "WithCSVSuccessfullyInstalled",
101253
context: &csvEventContext{
@@ -135,7 +287,7 @@ func TestGetNewStatus(t *testing.T) {
135287
{
136288
Type: configv1.OperatorAvailable,
137289
Status: configv1.ConditionTrue,
138-
Message: "ClusterServiceVersion foo-namespace/foo is in phase Succeeded",
290+
Message: "ClusterServiceVersion foo-namespace/foo observed in phase Succeeded",
139291
Reason: "ClusterServiceVersionSucceeded",
140292
LastTransitionTime: metav1.NewTime(fakeClock.Now()),
141293
},

0 commit comments

Comments
 (0)