From d3121f1738fe0ec9b200912c282a5604d73f10b4 Mon Sep 17 00:00:00 2001 From: Daniel Fan Date: Mon, 3 Jun 2024 11:04:55 -0700 Subject: [PATCH] Skip catalog discover when operator is not found in OperandRegistry Signed-off-by: Daniel Fan --- controllers/operator/manager.go | 62 +++++++++++++++++---------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/controllers/operator/manager.go b/controllers/operator/manager.go index 3bc13d69..b5d8f9ea 100644 --- a/controllers/operator/manager.go +++ b/controllers/operator/manager.go @@ -402,38 +402,40 @@ func (m *ODLMOperator) GetOperatorNamespace(installMode, namespace string) strin // GetOperandFromRegistry gets the Operand from the OperandRegistry func (m *ODLMOperator) GetOperandFromRegistry(ctx context.Context, reg *apiv1alpha1.OperandRegistry, operandName string) (*apiv1alpha1.Operator, error) { opt := reg.GetOperator(operandName) - // Get excluded CatalogSource from annotation - // excluded-catalogsource: catalogsource1, catalogsource2 - var excludedCatalogSources []string - if reg.Annotations != nil && reg.Annotations["excluded-catalogsource"] != "" { - excludedCatalogSources = strings.Split(reg.Annotations["excluded-catalogsource"], ",") - } - // Get catalog used by ODLM itself by check its own subscription - opts := []client.ListOption{ - client.MatchingLabels{fmt.Sprintf("operators.coreos.com/ibm-odlm.%s", util.GetOperatorNamespace()): ""}, - client.InNamespace(util.GetOperatorNamespace()), - } - odlmCatalog := "" - odlmCatalogNs := "" - odlmSubList := &olmv1alpha1.SubscriptionList{} - if err := m.Reader.List(ctx, odlmSubList, opts...); err != nil || len(odlmSubList.Items) == 0 { - klog.Warningf("No Subscription found for ibm-odlm in the namespace %s", util.GetOperatorNamespace()) - } else { - odlmCatalog = odlmSubList.Items[0].Spec.CatalogSource - odlmCatalogNs = odlmSubList.Items[0].Spec.CatalogSourceNamespace - } - - if opt.SourceName == "" || opt.SourceNamespace == "" { - catalogSourceName, catalogSourceNs, err := m.GetCatalogSourceFromPackage(ctx, opt.PackageName, opt.Namespace, opt.Channel, reg.Namespace, odlmCatalog, odlmCatalogNs, excludedCatalogSources) - if err != nil { - return nil, err - } + if opt != nil { + // Get excluded CatalogSource from annotation + // excluded-catalogsource: catalogsource1, catalogsource2 + var excludedCatalogSources []string + if reg.Annotations != nil && reg.Annotations["excluded-catalogsource"] != "" { + excludedCatalogSources = strings.Split(reg.Annotations["excluded-catalogsource"], ",") + } + // Get catalog used by ODLM itself by check its own subscription + opts := []client.ListOption{ + client.MatchingLabels{fmt.Sprintf("operators.coreos.com/ibm-odlm.%s", util.GetOperatorNamespace()): ""}, + client.InNamespace(util.GetOperatorNamespace()), + } + odlmCatalog := "" + odlmCatalogNs := "" + odlmSubList := &olmv1alpha1.SubscriptionList{} + if err := m.Reader.List(ctx, odlmSubList, opts...); err != nil || len(odlmSubList.Items) == 0 { + klog.Warningf("No Subscription found for ibm-odlm in the namespace %s", util.GetOperatorNamespace()) + } else { + odlmCatalog = odlmSubList.Items[0].Spec.CatalogSource + odlmCatalogNs = odlmSubList.Items[0].Spec.CatalogSourceNamespace + } + + if opt.SourceName == "" || opt.SourceNamespace == "" { + catalogSourceName, catalogSourceNs, err := m.GetCatalogSourceFromPackage(ctx, opt.PackageName, opt.Namespace, opt.Channel, reg.Namespace, odlmCatalog, odlmCatalogNs, excludedCatalogSources) + if err != nil { + return nil, err + } - if catalogSourceName == "" || catalogSourceNs == "" { - klog.V(2).Infof("no catalogsource found for %v", opt.PackageName) - } + if catalogSourceName == "" || catalogSourceNs == "" { + klog.V(2).Infof("no catalogsource found for %v", opt.PackageName) + } - opt.SourceName, opt.SourceNamespace = catalogSourceName, catalogSourceNs + opt.SourceName, opt.SourceNamespace = catalogSourceName, catalogSourceNs + } } return opt, nil