From 96eef73371829bda1ff542ae6806201280484f2b Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Thu, 20 Jun 2024 15:15:12 +0530 Subject: [PATCH 1/8] getting the error from status field for hpa analyzer Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpa.go | 13 ++++++++++++- pkg/common/types.go | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/analyzer/hpa.go b/pkg/analyzer/hpa.go index c70b93cc3a..48009e9cb9 100644 --- a/pkg/analyzer/hpa.go +++ b/pkg/analyzer/hpa.go @@ -43,7 +43,7 @@ func (HpaAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { "analyzer_name": kind, }) - list, err := a.Client.GetClient().AutoscalingV1().HorizontalPodAutoscalers(a.Namespace).List(a.Context, metav1.ListOptions{}) + list, err := a.Client.GetClient().AutoscalingV2().HorizontalPodAutoscalers(a.Namespace).List(a.Context, metav1.ListOptions{}) if err != nil { return nil, err } @@ -53,6 +53,17 @@ func (HpaAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { for _, hpa := range list.Items { var failures []common.Failure + //check the error from status field + conditions := hpa.Status.Conditions + for _, condition := range conditions { + if condition.Status != "True" { + failures = append(failures, common.Failure{ + Text: condition.Message, + Sensitive: []common.Sensitive{}, + }) + } + } + // check ScaleTargetRef exist scaleTargetRef := hpa.Spec.ScaleTargetRef var podInfo PodInfo diff --git a/pkg/common/types.go b/pkg/common/types.go index b0f82da339..334eb5badf 100644 --- a/pkg/common/types.go +++ b/pkg/common/types.go @@ -23,7 +23,7 @@ import ( keda "github.com/kedacore/keda/v2/apis/keda/v1alpha1" regv1 "k8s.io/api/admissionregistration/v1" appsv1 "k8s.io/api/apps/v1" - autov1 "k8s.io/api/autoscaling/v1" + autov2 "k8s.io/api/autoscaling/v2" v1 "k8s.io/api/core/v1" networkv1 "k8s.io/api/networking/v1" policyv1 "k8s.io/api/policy/v1" @@ -52,7 +52,7 @@ type PreAnalysis struct { PersistentVolumeClaim v1.PersistentVolumeClaim Endpoint v1.Endpoints Ingress networkv1.Ingress - HorizontalPodAutoscalers autov1.HorizontalPodAutoscaler + HorizontalPodAutoscalers autov2.HorizontalPodAutoscaler PodDisruptionBudget policyv1.PodDisruptionBudget StatefulSet appsv1.StatefulSet NetworkPolicy networkv1.NetworkPolicy From af1858ec75948a341e56beb27076d7dc1355740d Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Wed, 26 Jun 2024 11:23:51 +0530 Subject: [PATCH 2/8] Signed-off Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpa.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/analyzer/hpa.go b/pkg/analyzer/hpa.go index 48009e9cb9..d1469de94a 100644 --- a/pkg/analyzer/hpa.go +++ b/pkg/analyzer/hpa.go @@ -53,6 +53,7 @@ func (HpaAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { for _, hpa := range list.Items { var failures []common.Failure + //check the error from status field conditions := hpa.Status.Conditions for _, condition := range conditions { From 55e622b242146a61473f2c05cf0c70dd6a15687a Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Fri, 19 Jul 2024 15:17:45 +0530 Subject: [PATCH 3/8] Updated the hpaAnalyzer_test.go Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpaAnalyzer_test.go | 229 +++++++++++++++++++++++++++---- 1 file changed, 202 insertions(+), 27 deletions(-) diff --git a/pkg/analyzer/hpaAnalyzer_test.go b/pkg/analyzer/hpaAnalyzer_test.go index 68055e1432..cef9762e7e 100644 --- a/pkg/analyzer/hpaAnalyzer_test.go +++ b/pkg/analyzer/hpaAnalyzer_test.go @@ -22,7 +22,7 @@ import ( "github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" "github.com/magiconair/properties/assert" appsv1 "k8s.io/api/apps/v1" - autoscalingv1 "k8s.io/api/autoscaling/v1" + autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,7 +31,7 @@ import ( func TestHPAAnalyzer(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", @@ -55,14 +55,14 @@ func TestHPAAnalyzer(t *testing.T) { func TestHPAAnalyzerWithMultipleHPA(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, }, - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example-2", Namespace: "default", @@ -88,14 +88,14 @@ func TestHPAAnalyzerWithMultipleHPA(t *testing.T) { func TestHPAAnalyzerWithUnsuportedScaleTargetRef(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "unsupported", }, }, @@ -134,14 +134,14 @@ func TestHPAAnalyzerWithUnsuportedScaleTargetRef(t *testing.T) { func TestHPAAnalyzerWithNonExistentScaleTargetRef(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "Deployment", Name: "non-existent", }, @@ -181,14 +181,14 @@ func TestHPAAnalyzerWithNonExistentScaleTargetRef(t *testing.T) { func TestHPAAnalyzerWithExistingScaleTargetRefAsDeployment(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "Deployment", Name: "example", }, @@ -245,14 +245,14 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsDeployment(t *testing.T) { func TestHPAAnalyzerWithExistingScaleTargetRefAsReplicationController(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "ReplicationController", Name: "example", }, @@ -309,14 +309,14 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsReplicationController(t *testing func TestHPAAnalyzerWithExistingScaleTargetRefAsReplicaSet(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "ReplicaSet", Name: "example", }, @@ -373,14 +373,14 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsReplicaSet(t *testing.T) { func TestHPAAnalyzerWithExistingScaleTargetRefAsStatefulSet(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "StatefulSet", Name: "example", }, @@ -437,14 +437,14 @@ func TestHPAAnalyzerWithExistingScaleTargetRefAsStatefulSet(t *testing.T) { func TestHPAAnalyzerWithExistingScaleTargetRefWithoutSpecifyingResources(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, - Spec: autoscalingv1.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: autoscalingv1.CrossVersionObjectReference{ + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ Kind: "Deployment", Name: "example", }, @@ -503,14 +503,14 @@ func TestHPAAnalyzerWithExistingScaleTargetRefWithoutSpecifyingResources(t *test func TestHPAAnalyzerNamespaceFiltering(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", Annotations: map[string]string{}, }, }, - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "other-namespace", @@ -531,3 +531,178 @@ func TestHPAAnalyzerNamespaceFiltering(t *testing.T) { } assert.Equal(t, len(analysisResults), 1) } + +func TestHPAAnalyzerStatusFieldAbleToScale(t *testing.T) { + clientset := fake.NewSimpleClientset( + &autoscalingv2.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example", + Namespace: "default", + Annotations: map[string]string{}, + }, + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ + Kind: "Deployment", + Name: "example", + }, + }, + Status: autoscalingv2.HorizontalPodAutoscalerStatus{ + Conditions: []metav1.Condition{ + { + Type: "AbleToScale", + Status: "False", + Message: "test reason", + }, + }, + }, + }) + hpaAnalyzer := HpaAnalyzer{} + config := common.Analyzer{ + Client: &kubernetes.Client{ + Client: clientset, + }, + Context: context.Background(), + Namespace: "default", + } + analysisResults, err := hpaAnalyzer.Analyze(config) + if err != nil { + t.Error(err) + } + assert.Equal(t, len(analysisResults), 1) + +} + + +func TestHPAAnalyzerStatusFieldScalingActive(t *testing.T) { + clientset := fake.NewSimpleClientset( + &autoscalingv2.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example", + Namespace: "default", + Annotations: map[string]string{}, + }, + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ + Kind: "Deployment", + Name: "example", + }, + }, + Status: autoscalingv2.HorizontalPodAutoscalerStatus{ + Conditions: []metav1.Condition{ + { + Type: "ScalingActive", + Status: "False" + Message: "test reason", + }, + }, + }, + }) + hpaAnalyzer := HpaAnalyzer{} + config := common.Analyzer{ + Client: &kubernetes.Client{ + Client: clientset, + }, + Context: context.Background(), + Namespace: "default", + } + analysisResults, err := hpaAnalyzer.Analyze(config) + if err != nil { + t.Error(err) + } + assert.Equal(t, len(analysisResults), 1) + +} + + + +func TestHPAAnalyzerStatusFieldScalingLimited(t *testing.T) { + clientset := fake.NewSimpleClientset( + &autoscalingv2.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example", + Namespace: "default", + Annotations: map[string]string{}, + }, + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ + Kind: "Deployment", + Name: "example", + }, + }, + Status: autoscalingv2.HorizontalPodAutoscalerStatus{ + Conditions: []metav1.Condition{ + { + Type: "ScalingLimited", + Status: "False" + Message: "test reason", + }, + }, + }, + }) + hpaAnalyzer := HpaAnalyzer{} + config := common.Analyzer{ + Client: &kubernetes.Client{ + Client: clientset, + }, + Context: context.Background(), + Namespace: "default", + } + analysisResults, err := hpaAnalyzer.Analyze(config) + if err != nil { + t.Error(err) + } + assert.Equal(t, len(analysisResults), 1) + +} + + +func TestHPAAnalyzerStatusField(t *testing.T) { + clientset := fake.NewSimpleClientset( + &autoscalingv2.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example", + Namespace: "default", + Annotations: map[string]string{}, + }, + Spec: autoscalingv2.HorizontalPodAutoscalerSpec{ + ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{ + Kind: "Deployment", + Name: "example", + }, + }, + Status: autoscalingv2.HorizontalPodAutoscalerStatus{ + Conditions: []metav1.Condition{ + { + Type: "AbleToScale", + Status: "True" + Message: "recommended size matches current size", + }, + { + Type: "ScalingActive", + Status: "True" + Message: "the HPA was able to successfully calculate a replica count from cpu resource + utilization", + }, + { + Type: "ScalingLimited", + Status: "True" + Message: "the desired replica count is less than the minimum replica count", + }, + }, + }, + }) + hpaAnalyzer := HpaAnalyzer{} + config := common.Analyzer{ + Client: &kubernetes.Client{ + Client: clientset, + }, + Context: context.Background(), + Namespace: "default", + } + analysisResults, err := hpaAnalyzer.Analyze(config) + if err != nil { + t.Error(err) + } + assert.Equal(t, len(analysisResults), 0) + +} \ No newline at end of file From 01c2c8fd157ea17fe939afb58bf18405e5fed59f Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Fri, 19 Jul 2024 16:21:00 +0530 Subject: [PATCH 4/8] Updated hpa_test.go Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpaAnalyzer_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/analyzer/hpaAnalyzer_test.go b/pkg/analyzer/hpaAnalyzer_test.go index cef9762e7e..b7581f15ee 100644 --- a/pkg/analyzer/hpaAnalyzer_test.go +++ b/pkg/analyzer/hpaAnalyzer_test.go @@ -547,7 +547,7 @@ func TestHPAAnalyzerStatusFieldAbleToScale(t *testing.T) { }, }, Status: autoscalingv2.HorizontalPodAutoscalerStatus{ - Conditions: []metav1.Condition{ + Conditions: []autoscalingv2.HorizontalPodAutoscalerCondition{ { Type: "AbleToScale", Status: "False", @@ -588,10 +588,10 @@ func TestHPAAnalyzerStatusFieldScalingActive(t *testing.T) { }, }, Status: autoscalingv2.HorizontalPodAutoscalerStatus{ - Conditions: []metav1.Condition{ + Conditions: []autoscalingv2.HorizontalPodAutoscalerCondition{ { - Type: "ScalingActive", - Status: "False" + Type: autoscalingv2.ScalingActive, + Status: "False", Message: "test reason", }, }, @@ -630,10 +630,10 @@ func TestHPAAnalyzerStatusFieldScalingLimited(t *testing.T) { }, }, Status: autoscalingv2.HorizontalPodAutoscalerStatus{ - Conditions: []metav1.Condition{ + Conditions: []autoscalingv2.HorizontalPodAutoscalerCondition{ { - Type: "ScalingLimited", - Status: "False" + Type: autoscalingv2.ScalingLimited, + Status: "False", Message: "test reason", }, }, @@ -671,21 +671,20 @@ func TestHPAAnalyzerStatusField(t *testing.T) { }, }, Status: autoscalingv2.HorizontalPodAutoscalerStatus{ - Conditions: []metav1.Condition{ + Conditions: []autoscalingv2.HorizontalPodAutoscalerCondition{ { - Type: "AbleToScale", - Status: "True" + Type: autoscalingv2.AbleToScale, + Status: "True", Message: "recommended size matches current size", }, { - Type: "ScalingActive", - Status: "True" - Message: "the HPA was able to successfully calculate a replica count from cpu resource - utilization", + Type: autoscalingv2.ScalingActive, + Status: "True", + Message: "the HPA was able to successfully calculate a replica count", }, { - Type: "ScalingLimited", - Status: "True" + Type: autoscalingv2.ScalingLimited, + Status: "True", Message: "the desired replica count is less than the minimum replica count", }, }, From 0414ceb32ad5b5028daeda8b4328a1b0d78d2e23 Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Fri, 19 Jul 2024 17:16:55 +0530 Subject: [PATCH 5/8] Updated the hpa Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpa.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/analyzer/hpa.go b/pkg/analyzer/hpa.go index d1469de94a..1561b6dbae 100644 --- a/pkg/analyzer/hpa.go +++ b/pkg/analyzer/hpa.go @@ -43,7 +43,7 @@ func (HpaAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { "analyzer_name": kind, }) - list, err := a.Client.GetClient().AutoscalingV2().HorizontalPodAutoscalers(a.Namespace).List(a.Context, metav1.ListOptions{}) + list, err := a.Client.GetClient().AutoscalingV2().HorizontalPodAutoscalers(a.Namespace).List(a.Context, metav1.ListOptions{LabelSelector: a.LabelSelector}) if err != nil { return nil, err } From 4e3430246974ef97d6d05d40af53a32282f13ceb Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Fri, 19 Jul 2024 17:53:35 +0530 Subject: [PATCH 6/8] Updated the Conflicts Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpaAnalyzer_test.go | 68 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/pkg/analyzer/hpaAnalyzer_test.go b/pkg/analyzer/hpaAnalyzer_test.go index cf1a35cb0c..932caeb729 100644 --- a/pkg/analyzer/hpaAnalyzer_test.go +++ b/pkg/analyzer/hpaAnalyzer_test.go @@ -532,7 +532,41 @@ func TestHPAAnalyzerNamespaceFiltering(t *testing.T) { assert.Equal(t, len(analysisResults), 1) } -<<<<<<< HEAD +func TestHPAAnalyzerLabelSelectorFiltering(t *testing.T) { + clientset := fake.NewSimpleClientset( + &autoscalingv1.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example", + Namespace: "default", + Labels: map[string]string{ + "app": "hpa", + }, + }, + }, + &autoscalingv1.HorizontalPodAutoscaler{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example2", + Namespace: "default", + }, + }, + ) + hpaAnalyzer := HpaAnalyzer{} + config := common.Analyzer{ + Client: &kubernetes.Client{ + Client: clientset, + }, + Context: context.Background(), + Namespace: "default", + LabelSelector: "app=hpa", + } + analysisResults, err := hpaAnalyzer.Analyze(config) + if err != nil { + t.Error(err) + } + assert.Equal(t, len(analysisResults), 1) +} + + func TestHPAAnalyzerStatusFieldAbleToScale(t *testing.T) { clientset := fake.NewSimpleClientset( &autoscalingv2.HorizontalPodAutoscaler{ @@ -640,46 +674,19 @@ func TestHPAAnalyzerStatusFieldScalingLimited(t *testing.T) { }, }, }) -======= -func TestHPAAnalyzerLabelSelectorFiltering(t *testing.T) { - clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ - ObjectMeta: metav1.ObjectMeta{ - Name: "example", - Namespace: "default", - Labels: map[string]string{ - "app": "hpa", - }, - }, - }, - &autoscalingv1.HorizontalPodAutoscaler{ - ObjectMeta: metav1.ObjectMeta{ - Name: "example2", - Namespace: "default", - }, - }, - ) ->>>>>>> upstream/main hpaAnalyzer := HpaAnalyzer{} config := common.Analyzer{ Client: &kubernetes.Client{ Client: clientset, }, -<<<<<<< HEAD Context: context.Background(), Namespace: "default", -======= - Context: context.Background(), - Namespace: "default", - LabelSelector: "app=hpa", ->>>>>>> upstream/main } analysisResults, err := hpaAnalyzer.Analyze(config) if err != nil { t.Error(err) } assert.Equal(t, len(analysisResults), 1) -<<<<<<< HEAD } @@ -732,7 +739,4 @@ func TestHPAAnalyzerStatusField(t *testing.T) { } assert.Equal(t, len(analysisResults), 0) -} -======= -} ->>>>>>> upstream/main +} \ No newline at end of file From b2d91af812a6475c60dac9f3124515ef0d7b36ec Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Fri, 19 Jul 2024 18:02:13 +0530 Subject: [PATCH 7/8] Resolved all the conflicts Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpaAnalyzer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/analyzer/hpaAnalyzer_test.go b/pkg/analyzer/hpaAnalyzer_test.go index 932caeb729..905f2dba68 100644 --- a/pkg/analyzer/hpaAnalyzer_test.go +++ b/pkg/analyzer/hpaAnalyzer_test.go @@ -534,7 +534,7 @@ func TestHPAAnalyzerNamespaceFiltering(t *testing.T) { func TestHPAAnalyzerLabelSelectorFiltering(t *testing.T) { clientset := fake.NewSimpleClientset( - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: "default", @@ -543,7 +543,7 @@ func TestHPAAnalyzerLabelSelectorFiltering(t *testing.T) { }, }, }, - &autoscalingv1.HorizontalPodAutoscaler{ + &autoscalingv2.HorizontalPodAutoscaler{ ObjectMeta: metav1.ObjectMeta{ Name: "example2", Namespace: "default", From 91163d6132f5b2552ee46dd95d8b6848f6aee9bf Mon Sep 17 00:00:00 2001 From: naveenthangaraj03 Date: Sat, 20 Jul 2024 21:16:05 +0530 Subject: [PATCH 8/8] Updated the test case Signed-off-by: naveenthangaraj03 --- pkg/analyzer/hpaAnalyzer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/analyzer/hpaAnalyzer_test.go b/pkg/analyzer/hpaAnalyzer_test.go index 905f2dba68..a341a46a53 100644 --- a/pkg/analyzer/hpaAnalyzer_test.go +++ b/pkg/analyzer/hpaAnalyzer_test.go @@ -737,6 +737,6 @@ func TestHPAAnalyzerStatusField(t *testing.T) { if err != nil { t.Error(err) } - assert.Equal(t, len(analysisResults), 0) + assert.Equal(t, len(analysisResults), 1) } \ No newline at end of file