From cc665ea4f3f279c30c7dd7996786e6bdce88acc8 Mon Sep 17 00:00:00 2001 From: Clever Hu Date: Sun, 20 Aug 2023 03:52:46 +0800 Subject: [PATCH] fix: optimize analyze service (#461) Signed-off-by: cleverhu Signed-off-by: cleverhu Signed-off-by: Alex Jones Co-authored-by: cleverhu Co-authored-by: Alex Jones --- pkg/analyzer/service.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/analyzer/service.go b/pkg/analyzer/service.go index 9293a8d9de..9f67234297 100644 --- a/pkg/analyzer/service.go +++ b/pkg/analyzer/service.go @@ -17,10 +17,12 @@ import ( "fmt" "github.com/fatih/color" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/tools/leaderelection/resourcelock" + "github.com/k8sgpt-ai/k8sgpt/pkg/common" "github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" "github.com/k8sgpt-ai/k8sgpt/pkg/util" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -55,6 +57,10 @@ func (ServiceAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { // Check for empty service if len(ep.Subsets) == 0 { + if _, ok := ep.Annotations[resourcelock.LeaderElectionRecordAnnotationKey]; ok { + continue + } + svc, err := a.Client.GetClient().CoreV1().Services(ep.Namespace).Get(a.Context, ep.Name, metav1.GetOptions{}) if err != nil { color.Yellow("Service %s/%s does not exist", ep.Namespace, ep.Name)