From 6bbdbe32fb7388a74d89aaef5cd8ae5c7961008e Mon Sep 17 00:00:00 2001 From: Nasar Khan Date: Mon, 29 Jan 2024 17:09:56 -0500 Subject: [PATCH] error handling for findcatalogsource function --- manageiq-operator/api/v1alpha1/miqutils/find.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/manageiq-operator/api/v1alpha1/miqutils/find.go b/manageiq-operator/api/v1alpha1/miqutils/find.go index 6333ecbe..fb48c092 100644 --- a/manageiq-operator/api/v1alpha1/miqutils/find.go +++ b/manageiq-operator/api/v1alpha1/miqutils/find.go @@ -5,11 +5,13 @@ import ( olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + "strings" ) func FindPodByName(client client.Client, namespace string, name string) *corev1.Pod { @@ -60,7 +62,11 @@ func FindKafka(client client.Client, scheme *runtime.Scheme, namespace string, n func FindCatalogSourceByName(client client.Client, namespace string, name string) *olmv1alpha1.CatalogSource { catalogSourceKey := types.NamespacedName{Namespace: namespace, Name: name} catalogSource := &olmv1alpha1.CatalogSource{} - client.Get(context.TODO(), catalogSourceKey, catalogSource) + if err := client.Get(context.TODO(), catalogSourceKey, catalogSource); err != nil { + if strings.Contains(err.Error(), "no matches for kind") || errors.IsNotFound(err) { + return nil + } + } return catalogSource }