Skip to content

Commit 2f65bf9

Browse files
Add installPalnUpgradeCond earlyCon
Signed-off-by: yiraeChristineKim <[email protected]>
1 parent 2a42c2c commit 2f65bf9

File tree

2 files changed

+50
-62
lines changed

2 files changed

+50
-62
lines changed

controllers/operatorpolicy_controller.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,11 +2108,15 @@ func (r *OperatorPolicyReconciler) musthaveInstallPlan(
21082108
// Only report this status when not approving an InstallPlan, because otherwise it could easily
21092109
// oscillate between this and another condition.
21102110
if policy.Spec.RemediationAction.IsInform() || (!initialInstall && !autoUpgrade) {
2111+
// Emit an early event to record that an upgrade is available and requires approval
2112+
ipUpgrade := installPlanUpgradeCond(complianceConfig, ipCSVs, nil)
2113+
ipUpgrade.LastTransitionTime = metav1.Now()
2114+
21112115
return updateStatus(
21122116
policy,
2113-
installPlanUpgradeCond(complianceConfig, ipCSVs, nil),
2117+
ipUpgrade,
21142118
existingInstallPlanObj(&latestInstallPlan, string(phase), complianceConfig),
2115-
), []metav1.Condition{}, nil
2119+
), []metav1.Condition{ipUpgrade}, nil
21162120
}
21172121

21182122
remainingCSVsToApprove, err := r.getRemainingCSVApprovals(ctx, policy, sub, &latestInstallPlan)
@@ -2121,11 +2125,15 @@ func (r *OperatorPolicyReconciler) musthaveInstallPlan(
21212125
}
21222126

21232127
if len(remainingCSVsToApprove) != 0 {
2128+
// Emit an early event that approval is required for the listed CSVs
2129+
ipUpgrade := installPlanUpgradeCond(complianceConfig, ipCSVs, remainingCSVsToApprove)
2130+
ipUpgrade.LastTransitionTime = metav1.Now()
2131+
21242132
return updateStatus(
21252133
policy,
2126-
installPlanUpgradeCond(complianceConfig, ipCSVs, remainingCSVsToApprove),
2134+
ipUpgrade,
21272135
existingInstallPlanObj(&latestInstallPlan, string(phase), complianceConfig),
2128-
), []metav1.Condition{}, nil
2136+
), []metav1.Condition{ipUpgrade}, nil
21292137
}
21302138

21312139
opLog.Info("Approving InstallPlan", "InstallPlanName", latestInstallPlan.Name,

controllers/operatorpolicy_status.go

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -204,109 +204,89 @@ func calculateComplianceCondition(policy *policyv1beta1.OperatorPolicy) metav1.C
204204
idx, cond := policy.Status.GetCondition(validPolicyConditionType)
205205
if idx == -1 {
206206
return shortReturn("the validity of the policy is unknown")
207-
} else {
208-
if cond.Status != metav1.ConditionTrue {
209-
// When invalid, short-circuit immediately with only the validation message.
210-
return shortReturn(cond.Message)
211-
}
212-
213-
messages = append(messages, cond.Message)
214207
}
208+
if cond.Status != metav1.ConditionTrue {
209+
// When invalid, short-circuit immediately with only the validation message.
210+
return shortReturn(cond.Message)
211+
}
212+
messages = append(messages, cond.Message)
215213

216214
idx, cond = policy.Status.GetCondition(opGroupConditionType)
217215
if idx == -1 {
218216
return shortReturn("the status of the OperatorGroup is unknown")
219-
} else {
220-
if cond.Status != metav1.ConditionTrue {
221-
return shortReturn(cond.Message)
222-
}
223-
224-
messages = append(messages, cond.Message)
225217
}
218+
if cond.Status != metav1.ConditionTrue {
219+
return shortReturn(cond.Message)
220+
}
221+
messages = append(messages, cond.Message)
226222

227223
idx, cond = policy.Status.GetCondition(subConditionType)
228224
if idx == -1 {
229225
return shortReturn("the status of the Subscription is unknown")
230-
} else {
231-
if cond.Status != metav1.ConditionTrue {
232-
return shortReturn(cond.Message)
233-
}
234-
235-
messages = append(messages, cond.Message)
236226
}
227+
if cond.Status != metav1.ConditionTrue {
228+
return shortReturn(cond.Message)
229+
}
230+
messages = append(messages, cond.Message)
237231

238232
idx, cond = policy.Status.GetCondition(installPlanConditionType)
239-
240233
if idx == -1 {
241234
return shortReturn("the status of the InstallPlan is unknown")
242-
} else {
243-
if cond.Status != metav1.ConditionTrue {
244-
return shortReturn(cond.Message)
245-
}
246-
247-
messages = append(messages, cond.Message)
248235
}
236+
if cond.Status != metav1.ConditionTrue {
237+
return shortReturn(cond.Message)
238+
}
239+
messages = append(messages, cond.Message)
249240

250241
idx, cond = policy.Status.GetCondition(csvConditionType)
251242
if idx == -1 {
252243
return shortReturn("the status of the ClusterServiceVersion is unknown")
253-
} else {
254-
if cond.Status != metav1.ConditionTrue {
255-
return shortReturn(cond.Message)
256-
}
257-
258-
messages = append(messages, cond.Message)
259244
}
245+
if cond.Status != metav1.ConditionTrue {
246+
return shortReturn(cond.Message)
247+
}
248+
messages = append(messages, cond.Message)
260249

261250
idx, cond = policy.Status.GetCondition(crdConditionType)
262251
if idx == -1 {
263252
return shortReturn("the status of the CustomResourceDefinitions is unknown")
264-
} else {
265-
266-
if cond.Status != metav1.ConditionTrue {
267-
return shortReturn(cond.Message)
268-
}
269-
270-
messages = append(messages, cond.Message)
271253
}
254+
if cond.Status != metav1.ConditionTrue {
255+
return shortReturn(cond.Message)
256+
}
257+
messages = append(messages, cond.Message)
272258

273259
idx, cond = policy.Status.GetCondition(deploymentConditionType)
274-
275260
if idx == -1 {
276261
return shortReturn("the status of the Deployments are unknown")
277-
} else {
278-
279-
if cond.Status != metav1.ConditionTrue {
280-
return shortReturn(cond.Message)
281-
}
262+
}
282263

283-
messages = append(messages, cond.Message)
264+
if cond.Status != metav1.ConditionTrue {
265+
return shortReturn(cond.Message)
284266
}
285267

286-
idx, cond = policy.Status.GetCondition(catalogSrcConditionType)
268+
messages = append(messages, cond.Message)
287269

270+
idx, cond = policy.Status.GetCondition(catalogSrcConditionType)
288271
if idx == -1 {
289272
return shortReturn("the status of the CatalogSource is unknown")
290-
} else {
291-
messages = append(messages, cond.Message)
273+
}
292274

293-
if cond.Status != metav1.ConditionFalse {
294-
return shortReturn(cond.Message)
295-
}
275+
messages = append(messages, cond.Message)
276+
if cond.Status != metav1.ConditionFalse {
277+
return shortReturn(cond.Message)
296278
}
297279

298280
idx, cond = policy.Status.GetCondition(deprecationType)
299281
if !policy.Spec.ComplianceType.IsMustNotHave() &&
300282
policy.Spec.ComplianceConfig.DeprecationsPresent == "NonCompliant" {
301283
if idx == -1 {
302284
return shortReturn("The deprecation status is unknown")
303-
} else {
304-
if cond.Status != metav1.ConditionTrue {
305-
return shortReturn(cond.Message)
306-
}
307-
308-
messages = append(messages, cond.Message)
309285
}
286+
if cond.Status != metav1.ConditionTrue {
287+
return shortReturn(cond.Message)
288+
}
289+
messages = append(messages, cond.Message)
310290
}
311291

312292
message := strings.Join(messages, ", ")

0 commit comments

Comments
 (0)