Skip to content

Commit d590121

Browse files
authored
Remove sourceName and sourceNamespace fields from OperandRegistry (#2592)
* Remove sourceName and sourceNamespace fields from OperandRegistry Signed-off-by: Daniel Fan <[email protected]> * Add RemoveCondition method and update warning conditions for CatalogSource configuration Signed-off-by: Daniel Fan <[email protected]> * Remove unnecessary conditions in SetReadyCondition method Signed-off-by: Daniel Fan <[email protected]> --------- Signed-off-by: Daniel Fan <[email protected]>
1 parent 4b06b0e commit d590121

File tree

4 files changed

+45
-146
lines changed

4 files changed

+45
-146
lines changed

api/v3/commonservice_types.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ const (
303303
)
304304

305305
const (
306-
ConditionMessageReconcile = "reconciling CommonService CR."
307-
ConditionMessageInit = "initializing/updating: waiting for OperandRegistry and OperandConfig to become ready."
308-
ConditionMessageConfig = "configuring CommonService CR."
309-
ConditionMessageMissSC = "warning: StorageClass is not configured in CommonService CR, if KeyCloak or IBM IM service will be deployed, please configure StorageClass in the CS CR. Refer to the documentation for more information: https://www.ibm.com/docs/en/cloud-paks/foundational-services/4.6?topic=options-configuring-foundational-services#storage-class"
310-
ConditionMessageReady = "CommonService CR is ready."
306+
ConditionMessageReconcile = "reconciling CommonService CR."
307+
ConditionMessageInit = "initializing/updating: waiting for OperandRegistry and OperandConfig to become ready."
308+
ConditionMessageConfig = "configuring CommonService CR."
309+
ConditionMessageMissSC = "warning: StorageClass is not configured in CommonService CR, if KeyCloak or IBM IM service will be deployed, please configure StorageClass in the CS CR. Refer to the documentation for more information: https://www.ibm.com/docs/en/cloud-paks/foundational-services/4.6?topic=options-configuring-foundational-services#storage-class"
310+
ConditionMessageReady = "CommonService CR is ready."
311+
ConditionMessageCatalogNotSupported = "warning: CatalogSource configuration is not supported. Please remove .spec.CatalogName and .spec.CatalogNamespace from the CommonService CR."
311312
)
312313

313314
// +kubebuilder:object:root=true
@@ -356,7 +357,6 @@ func (r *CommonService) UpdateConfigStatus(CSData *CSData, operatorDeployed, ser
356357
}
357358

358359
r.Status.ConfigStatus.CatalogName = r.Spec.CatalogName
359-
360360
r.Status.ConfigStatus.CatalogNamespace = r.Spec.CatalogNamespace
361361

362362
r.Status.ConfigStatus.OperatorDeployed = true
@@ -386,7 +386,10 @@ func (r *CommonService) SetPendingCondition(name string, ct ConditionType, cs co
386386

387387
// SetReadyCondition creates a Condition to claim Ready.
388388
func (r *CommonService) SetReadyCondition(name string, ct ConditionType, cs corev1.ConditionStatus) {
389-
r.UpdateConditionList(corev1.ConditionFalse)
389+
r.RemoveCondition(ConditionTypePending)
390+
r.RemoveCondition(ConditionTypeReconciling)
391+
r.RemoveCondition(ConditionTypeBlocked)
392+
r.RemoveCondition(ConditionTypeError)
390393
c := newCondition(ConditionTypeReady, cs, ConditionReasonReady, ConditionMessageReady)
391394
r.setCondition(*c)
392395
}
@@ -414,6 +417,31 @@ func (r *CommonService) UpdateConditionList(ct corev1.ConditionStatus) {
414417
}
415418
}
416419

420+
// RemoveCondition removes a condition or multiple condition from the CommonService CR
421+
func (r *CommonService) RemoveCondition(condType ConditionType, msg ...string) {
422+
if len(msg) == 0 {
423+
// If no messages provided, remove all conditions of the specified type
424+
newConditions := []CommonServiceCondition{}
425+
for _, cond := range r.Status.Conditions {
426+
if cond.Type != condType {
427+
newConditions = append(newConditions, cond)
428+
}
429+
}
430+
r.Status.Conditions = newConditions
431+
} else {
432+
// If messages provided, remove conditions that match the type and one of the messages
433+
for _, message := range msg {
434+
newConditions := []CommonServiceCondition{}
435+
for _, cond := range r.Status.Conditions {
436+
if cond.Type != condType || cond.Message != message {
437+
newConditions = append(newConditions, cond)
438+
}
439+
}
440+
r.Status.Conditions = newConditions
441+
}
442+
}
443+
}
444+
417445
// NewCondition Returns a new condition with the given values for CommonService
418446
func newCondition(condType ConditionType, status corev1.ConditionStatus, reason, message string) *CommonServiceCondition {
419447
now := time.Now().Format(time.RFC3339)

internal/controller/bootstrap/init.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ func (b *Bootstrap) CheckWarningCondition(instance *apiv3.CommonService) error {
316316
// check if there is no storageClass declared under spec section and the default count is not 1
317317
if instance.Spec.StorageClass == "" && defaultCount != 1 {
318318
instance.SetWarningCondition(constant.MasterCR, apiv3.ConditionTypeWarning, corev1.ConditionTrue, apiv3.ConditionReasonWarning, apiv3.ConditionMessageMissSC)
319+
} else {
320+
// remove the warning condition if storageClass is configured
321+
instance.RemoveCondition(apiv3.ConditionTypeWarning, apiv3.ConditionMessageMissSC)
322+
}
323+
324+
if instance.Spec.CatalogName != "" || instance.Spec.CatalogNamespace != "" {
325+
instance.SetWarningCondition(constant.MasterCR, apiv3.ConditionTypeWarning, corev1.ConditionTrue, apiv3.ConditionReasonWarning, apiv3.ConditionMessageCatalogNotSupported)
326+
} else {
327+
// remove the warning condition if catalogSource is not configured
328+
instance.RemoveCondition(apiv3.ConditionTypeWarning, apiv3.ConditionMessageCatalogNotSupported)
319329
}
320330
return nil
321331
}

0 commit comments

Comments
 (0)