Skip to content

Commit

Permalink
optimize analyze service
Browse files Browse the repository at this point in the history
Signed-off-by: cleverhu <shouping.hu@daocloud.io>
  • Loading branch information
cleverhu committed May 25, 2023
1 parent a236cc4 commit c1c2e90
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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,11 @@ 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 {
color.Green("Endpoint %s/%s is used as leaderElection", ep.Namespace, ep.Name)
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 c1c2e90

Please sign in to comment.