From f200a14195be49b829e0e50e406a3fbfb3ea132f Mon Sep 17 00:00:00 2001 From: airycanon Date: Fri, 1 Dec 2023 15:17:51 +0800 Subject: [PATCH] get plugin service from cluster --- testing/framework/cluster/service.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 testing/framework/cluster/service.go diff --git a/testing/framework/cluster/service.go b/testing/framework/cluster/service.go new file mode 100644 index 00000000..d2e202ce --- /dev/null +++ b/testing/framework/cluster/service.go @@ -0,0 +1,20 @@ +package cluster + +import ( + "context" + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +func Service(ctx context.Context, clt client.Client, name string) (*corev1.Service, error) { + services := &corev1.ServiceList{} + + if err := clt.List(ctx, services, client.MatchingLabels{"plugin": name}); err != nil { + return nil, err + } + + if len(services.Items) > 0 { + return &services.Items[0], nil + } + return nil, nil +}