Skip to content

Commit

Permalink
fix: optimize analyze service (#461)
Browse files Browse the repository at this point in the history
Signed-off-by: cleverhu <[email protected]>
Signed-off-by: cleverhu <[email protected]>
Signed-off-by: Alex Jones <[email protected]>
Co-authored-by: cleverhu <[email protected]>
Co-authored-by: Alex Jones <[email protected]>
  • Loading branch information
3 people authored Aug 19, 2023
1 parent aee83b7 commit cc665ea
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,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"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cc665ea

Please sign in to comment.