Skip to content

Commit 6999157

Browse files
authored
check for status.services, im service status (#916)
* check for status.services, im service status Signed-off-by: Ben Luzarraga <[email protected]> * alter check for im operator status Signed-off-by: Ben Luzarraga <[email protected]> * export function Signed-off-by: Ben Luzarraga <[email protected]> * account for opreq that do not request im Signed-off-by: Ben Luzarraga <[email protected]> * typo Signed-off-by: Ben Luzarraga <[email protected]> * clean up implementation Signed-off-by: Ben Luzarraga <[email protected]> * linter changes Signed-off-by: Ben Luzarraga <[email protected]> * service.operatorName value from managedBy to requested name Signed-off-by: Ben Luzarraga <[email protected]> * change common ui operator name to look for Signed-off-by: Ben Luzarraga <[email protected]> --------- Signed-off-by: Ben Luzarraga <[email protected]> Co-authored-by: Ben Luzarraga <[email protected]>
1 parent e9839ec commit 6999157

File tree

3 files changed

+62
-44
lines changed

3 files changed

+62
-44
lines changed

api/v1alpha1/operandrequest_types.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
runtime "k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/types"
32+
"k8s.io/klog"
3233
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3334
)
3435

@@ -650,6 +651,58 @@ func (r *OperandRequest) UpdateLabels() bool {
650651
return isUpdated
651652
}
652653

654+
func (r *OperandRequest) CheckServiceStatus() bool {
655+
requeue := false
656+
monitoredServices := []string{"ibm-iam-operator", "ibm-idp-config-ui-operator", "ibm-mongodb-operator", "ibm-im-operator"}
657+
servicesRequested := false
658+
for _, serviceName := range monitoredServices {
659+
if foundOperand(r.Spec.Requests, serviceName) {
660+
servicesRequested = true
661+
break
662+
}
663+
}
664+
if servicesRequested {
665+
if len(r.Status.Services) == 0 {
666+
klog.Info("Waiting for status.services to be instantiated ...")
667+
requeue = true
668+
return requeue
669+
}
670+
// var IMOrIAM string
671+
exists := false
672+
if foundOperand(r.Spec.Requests, "ibm-iam-operator") {
673+
// IMOrIAM = "ibm-iam-operator"
674+
exists = true
675+
} else if foundOperand(r.Spec.Requests, "ibm-im-operator") {
676+
// IMOrIAM = "ibm-im-operator"
677+
exists = true
678+
}
679+
680+
if exists {
681+
var imIndex int
682+
found := false
683+
for i, s := range r.Status.Services {
684+
if "ibm-iam-operator" == s.OperatorName { //eventually this should be changed to the variable but the operator name is still listed as iam in practice even when im is requested
685+
found = true
686+
imIndex = i
687+
break
688+
}
689+
}
690+
if found {
691+
if r.Status.Services[imIndex].Status != "Ready" {
692+
klog.Info("Waiting for IM service to be Ready ...")
693+
requeue = true
694+
return requeue
695+
}
696+
} else {
697+
klog.Info("Waiting for IM service status ...")
698+
requeue = true
699+
return requeue
700+
}
701+
}
702+
}
703+
return requeue
704+
}
705+
653706
// GetAllRegistryReconcileRequest gets all the Registry ReconcileRequest.
654707
func (r *OperandRequest) GetAllRegistryReconcileRequest() []reconcile.Request {
655708
rrs := []reconcile.Request{}

controllers/operandrequest/operandrequest_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
153153
return ctrl.Result{RequeueAfter: constant.DefaultRequeueDuration}, nil
154154
}
155155

156+
//check if status.services is present (if a relevant service was requested), requeue again is im/iam is not ready yet
157+
if requestInstance.CheckServiceStatus() {
158+
return ctrl.Result{RequeueAfter: constant.DefaultRequeueDuration}, nil
159+
}
160+
156161
klog.V(1).Infof("Finished reconciling OperandRequest: %s", req.NamespacedName)
157162
return ctrl.Result{RequeueAfter: constant.DefaultSyncPeriod}, nil
158163
}

controllers/operandrequest/reconcile_operand.go

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper
183183
klog.V(2).Infof("There is no service: %s from the OperandConfig instance: %s/%s, Skip reconciling Operands", operand.Name, registryKey.Namespace, req.Registry)
184184
continue
185185
}
186-
err = r.reconcileCRwithConfig(ctx, opdConfig, configInstance.Namespace, csv, requestInstance, sub.Namespace, &r.Mutex)
186+
err = r.reconcileCRwithConfig(ctx, opdConfig, configInstance.Namespace, csv, requestInstance, operand.Name, sub.Namespace, &r.Mutex)
187187
if err != nil {
188188
merr.Add(err)
189189
requestInstance.SetMemberStatus(operand.Name, "", operatorv1alpha1.ServiceFailed, &r.Mutex)
@@ -215,7 +215,7 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper
215215
}
216216

217217
// reconcileCRwithConfig merge and create custom resource base on OperandConfig and CSV alm-examples
218-
func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operatorv1alpha1.ConfigService, namespace string, csv *olmv1alpha1.ClusterServiceVersion, requestInstance *operatorv1alpha1.OperandRequest, operatorNamespace string, mu sync.Locker) error {
218+
func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operatorv1alpha1.ConfigService, namespace string, csv *olmv1alpha1.ClusterServiceVersion, requestInstance *operatorv1alpha1.OperandRequest, operandName string, operatorNamespace string, mu sync.Locker) error {
219219
merr := &util.MultiErr{}
220220

221221
// Create k8s resources required by service
@@ -337,10 +337,6 @@ func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operato
337337
merr.Add(err)
338338
continue
339339
}
340-
managedBy, err := r.getManagedBy(crFromALM)
341-
if err != nil {
342-
return err
343-
}
344340
statusSpec, err := r.getOperandStatus(crFromALM)
345341
if err != nil {
346342
return err
@@ -349,7 +345,7 @@ func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operato
349345
if serviceKind != "OperandRequest" && statusSpec.ObjectName != "" {
350346
var resources []operatorv1alpha1.OperandStatus
351347
resources = append(resources, statusSpec)
352-
serviceSpec := newServiceStatus(managedBy, operatorNamespace, resources)
348+
serviceSpec := newServiceStatus(operandName, operatorNamespace, resources)
353349
seterr := requestInstance.SetServiceStatus(ctx, serviceSpec, r.Client, mu)
354350
if seterr != nil {
355351
return seterr
@@ -421,18 +417,14 @@ func (r *Reconciler) reconcileCRwithRequest(ctx context.Context, requestInstance
421417
if err := r.updateCustomResource(ctx, crFromRequest, requestKey.Namespace, operand.Kind, operand.Spec.Raw, map[string]interface{}{}); err != nil {
422418
return err
423419
}
424-
managedBy, err := r.getManagedBy(crFromRequest)
425-
if err != nil {
426-
return err
427-
}
428420
statusSpec, err := r.getOperandStatus(crFromRequest)
429421
if err != nil {
430422
return err
431423
}
432424
if operand.Kind != "OperandRequest" && statusSpec.ObjectName != "" {
433425
var resources []operatorv1alpha1.OperandStatus
434426
resources = append(resources, statusSpec)
435-
serviceSpec := newServiceStatus(managedBy, operatorNamespace, resources)
427+
serviceSpec := newServiceStatus(operand.Name, operatorNamespace, resources)
436428
seterr := requestInstance.SetServiceStatus(ctx, serviceSpec, r.Client, mu)
437429
if seterr != nil {
438430
return seterr
@@ -449,38 +441,6 @@ func (r *Reconciler) reconcileCRwithRequest(ctx context.Context, requestInstance
449441
return nil
450442
}
451443

452-
func (r *Reconciler) getManagedBy(existingCR unstructured.Unstructured) (string, error) {
453-
byteMetadata, err := json.Marshal(existingCR.Object["metadata"])
454-
if err != nil {
455-
klog.Error(err)
456-
return "", err
457-
}
458-
var rawMetadata map[string]interface{}
459-
err = json.Unmarshal(byteMetadata, &rawMetadata)
460-
if err != nil {
461-
klog.Error(err)
462-
return "", err
463-
}
464-
byteLabels, err := json.Marshal(rawMetadata["labels"])
465-
if err != nil {
466-
klog.Error(err)
467-
return "", err
468-
}
469-
var parsedLabels map[string]string
470-
err = json.Unmarshal(byteLabels, &parsedLabels)
471-
if err != nil {
472-
klog.Error(err)
473-
return "", err
474-
}
475-
var managedBy string
476-
for key, value := range parsedLabels {
477-
if key == "app.kubernetes.io/managed-by" {
478-
managedBy = value
479-
}
480-
}
481-
return managedBy, nil
482-
}
483-
484444
func (r *Reconciler) getOperandStatus(existingCR unstructured.Unstructured) (operatorv1alpha1.OperandStatus, error) {
485445
var emptyStatus operatorv1alpha1.OperandStatus
486446
byteStatus, err := json.Marshal(existingCR.Object["status"])

0 commit comments

Comments
 (0)