From 119722728c077867faa2cb41d29d7603e18bf0e9 Mon Sep 17 00:00:00 2001 From: cah-patrickthiem Date: Fri, 15 Nov 2024 12:25:37 +0100 Subject: [PATCH] !fixup --- .../scs_0215_v1_robustness_features_test.go | 67 +++++-------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0215_v1_robustness_features_test.go b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0215_v1_robustness_features_test.go index 0de9ce841..9c81874fb 100644 --- a/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0215_v1_robustness_features_test.go +++ b/Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0215_v1_robustness_features_test.go @@ -3,7 +3,6 @@ package scs_k8s_tests import ( "context" "fmt" - "reflect" "strings" "testing" "time" @@ -29,17 +28,6 @@ func setupClientset() (*kubernetes.Clientset, error) { return kubernetes.NewForConfig(config) } -// hasEtcdBackup is a helper to check for etcd backup in various resources -func hasEtcdBackup[T any](items []T, nameCheck func(string) bool) bool { - for _, item := range items { - name := reflect.ValueOf(item).FieldByName("Name").String() - if nameCheck(name) { - return true - } - } - return false -} - // ==================== Test Cases ==================== func Test_scs_0215_requestLimits(t *testing.T) { @@ -52,12 +40,9 @@ func Test_scs_0215_requestLimits(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - pods, err := clientset.CoreV1().Pods("kube-system").List( - ctx, - metav1.ListOptions{ - LabelSelector: "component=kube-apiserver", - }, - ) + pods, err := clientset.CoreV1().Pods("kube-system").List(ctx, metav1.ListOptions{ + LabelSelector: "component=kube-apiserver", + }) if err != nil || len(pods.Items) == 0 { t.Fatalf("Failed to find kube-apiserver pod: %v", err) } @@ -102,13 +87,9 @@ func Test_scs_0215_minRequestTimeout(t *testing.T) { } t.Run("Check_minRequestTimeout_Configuration", func(t *testing.T) { - // List all pods in kube-system namespace - pods, err := clientset.CoreV1().Pods("kube-system").List( - context.TODO(), - metav1.ListOptions{ - LabelSelector: "component=kube-apiserver", - }, - ) + pods, err := clientset.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{ + LabelSelector: "component=kube-apiserver", + }) if err != nil || len(pods.Items) == 0 { t.Fatalf("Failed to find kube-apiserver pod: %v", err) } @@ -150,11 +131,7 @@ func Test_scs_0215_eventRateLimit(t *testing.T) { } for _, loc := range configLocations { - config, err := clientset.CoreV1().ConfigMaps(loc.namespace).Get( - context.TODO(), - loc.name, - metav1.GetOptions{}, - ) + config, err := clientset.CoreV1().ConfigMaps(loc.namespace).Get(context.Background(), loc.name, metav1.GetOptions{}) if err == nil { if data, ok := config.Data[loc.key]; ok { if strings.Contains(data, "eventratelimit.admission.k8s.io") { @@ -165,7 +142,7 @@ func Test_scs_0215_eventRateLimit(t *testing.T) { } } - configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.TODO(), metav1.ListOptions{}) + configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.Background(), metav1.ListOptions{}) for _, cm := range configMaps.Items { if strings.Contains(cm.Name, "event-rate-limit") { t.Logf("Found standalone EventRateLimit configuration in ConfigMap: %s", cm.Name) @@ -188,12 +165,9 @@ func Test_scs_0215_apiPriorityAndFairness(t *testing.T) { } t.Run("Check_APF_Configuration", func(t *testing.T) { - pods, err := clientset.CoreV1().Pods("kube-system").List( - context.TODO(), - metav1.ListOptions{ - LabelSelector: "component=kube-apiserver", - }, - ) + pods, err := clientset.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{ + LabelSelector: "component=kube-apiserver", + }) if err != nil || len(pods.Items) == 0 { t.Fatal("Failed to find kube-apiserver pod") } @@ -227,7 +201,7 @@ func Test_scs_0215_rateLimitValues(t *testing.T) { "burst": "20000", } - configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.TODO(), metav1.ListOptions{}) + configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.Background(), metav1.ListOptions{}) for _, cm := range configMaps.Items { var config string switch { @@ -268,12 +242,9 @@ func Test_scs_0215_etcdCompaction(t *testing.T) { } t.Run("Check_Etcd_Compaction_Settings", func(t *testing.T) { - pods, err := clientset.CoreV1().Pods("kube-system").List( - context.TODO(), - metav1.ListOptions{ - LabelSelector: "component=etcd", - }, - ) + pods, err := clientset.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{ + LabelSelector: "component=etcd", + }) if err != nil || len(pods.Items) == 0 { t.Skip("No etcd pods found") return @@ -317,7 +288,7 @@ func Test_scs_0215_etcdBackup(t *testing.T) { } t.Run("Check_Etcd_Backup_Configuration", func(t *testing.T) { - cronJobs, err := clientset.BatchV1().CronJobs("").List(context.TODO(), metav1.ListOptions{}) + cronJobs, err := clientset.BatchV1().CronJobs("").List(context.Background(), metav1.ListOptions{}) if err == nil { for _, job := range cronJobs.Items { if strings.Contains(strings.ToLower(job.Name), "etcd") && @@ -338,11 +309,7 @@ func Test_scs_0215_certificateRotation(t *testing.T) { } t.Run("Check_Certificate_Controller", func(t *testing.T) { - _, err := clientset.AppsV1().Deployments("cert-manager").Get( - context.TODO(), - "cert-manager", - metav1.GetOptions{}, - ) + _, err := clientset.AppsV1().Deployments("cert-manager").Get(context.Background(), "cert-manager", metav1.GetOptions{}) if err != nil { t.Error("cert-manager not found - certificate controller required") } else {