Skip to content

Commit

Permalink
fix: optimize analyze service
Browse files Browse the repository at this point in the history
Signed-off-by: cleverhu <shouping.hu@daocloud.io>
Signed-off-by: cleverhu <zhubai.hsp@xuelanyun.com>
  • Loading branch information
cleverhu authored and cleverhu committed May 29, 2023
1 parent a236cc4 commit a6a9644
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/analyzer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ 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/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type ServiceAnalyzer struct{}
Expand All @@ -45,6 +47,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)
Expand Down

0 comments on commit a6a9644

Please sign in to comment.