Skip to content

Commit

Permalink
Skip catalog discover when operator is not found in OperandRegistry
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Fan <fanyuchensx@gmail.com>
  • Loading branch information
Daniel-Fan committed Jun 3, 2024
1 parent 287eafa commit d3121f1
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3121f1

Please sign in to comment.