mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-19 01:12:46 +00:00
fix: optimize analyze service (#461)
Signed-off-by: cleverhu <shouping.hu@daocloud.io> Signed-off-by: cleverhu <zhubai.hsp@xuelanyun.com> Signed-off-by: Alex Jones <alexsimonjones@gmail.com> Co-authored-by: cleverhu <shouping.hu@daocloud.io> Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user