Skip to content

Commit

Permalink
error handling for findcatalogsource function
Browse files Browse the repository at this point in the history
  • Loading branch information
nasark committed Jan 29, 2024
1 parent 99fcb20 commit 6bbdbe3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion manageiq-operator/api/v1alpha1/miqutils/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6bbdbe3

Please sign in to comment.