Skip to content

Commit 1197227

Browse files
!fixup
1 parent c9e8ced commit 1197227

File tree

1 file changed

+17
-50
lines changed

1 file changed

+17
-50
lines changed

Tests/kaas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0215_v1_robustness_features_test.go

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scs_k8s_tests
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76
"strings"
87
"testing"
98
"time"
@@ -29,17 +28,6 @@ func setupClientset() (*kubernetes.Clientset, error) {
2928
return kubernetes.NewForConfig(config)
3029
}
3130

32-
// hasEtcdBackup is a helper to check for etcd backup in various resources
33-
func hasEtcdBackup[T any](items []T, nameCheck func(string) bool) bool {
34-
for _, item := range items {
35-
name := reflect.ValueOf(item).FieldByName("Name").String()
36-
if nameCheck(name) {
37-
return true
38-
}
39-
}
40-
return false
41-
}
42-
4331
// ==================== Test Cases ====================
4432

4533
func Test_scs_0215_requestLimits(t *testing.T) {
@@ -52,12 +40,9 @@ func Test_scs_0215_requestLimits(t *testing.T) {
5240
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
5341
defer cancel()
5442

55-
pods, err := clientset.CoreV1().Pods("kube-system").List(
56-
ctx,
57-
metav1.ListOptions{
58-
LabelSelector: "component=kube-apiserver",
59-
},
60-
)
43+
pods, err := clientset.CoreV1().Pods("kube-system").List(ctx, metav1.ListOptions{
44+
LabelSelector: "component=kube-apiserver",
45+
})
6146
if err != nil || len(pods.Items) == 0 {
6247
t.Fatalf("Failed to find kube-apiserver pod: %v", err)
6348
}
@@ -102,13 +87,9 @@ func Test_scs_0215_minRequestTimeout(t *testing.T) {
10287
}
10388

10489
t.Run("Check_minRequestTimeout_Configuration", func(t *testing.T) {
105-
// List all pods in kube-system namespace
106-
pods, err := clientset.CoreV1().Pods("kube-system").List(
107-
context.TODO(),
108-
metav1.ListOptions{
109-
LabelSelector: "component=kube-apiserver",
110-
},
111-
)
90+
pods, err := clientset.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{
91+
LabelSelector: "component=kube-apiserver",
92+
})
11293
if err != nil || len(pods.Items) == 0 {
11394
t.Fatalf("Failed to find kube-apiserver pod: %v", err)
11495
}
@@ -150,11 +131,7 @@ func Test_scs_0215_eventRateLimit(t *testing.T) {
150131
}
151132

152133
for _, loc := range configLocations {
153-
config, err := clientset.CoreV1().ConfigMaps(loc.namespace).Get(
154-
context.TODO(),
155-
loc.name,
156-
metav1.GetOptions{},
157-
)
134+
config, err := clientset.CoreV1().ConfigMaps(loc.namespace).Get(context.Background(), loc.name, metav1.GetOptions{})
158135
if err == nil {
159136
if data, ok := config.Data[loc.key]; ok {
160137
if strings.Contains(data, "eventratelimit.admission.k8s.io") {
@@ -165,7 +142,7 @@ func Test_scs_0215_eventRateLimit(t *testing.T) {
165142
}
166143
}
167144

168-
configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.TODO(), metav1.ListOptions{})
145+
configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.Background(), metav1.ListOptions{})
169146
for _, cm := range configMaps.Items {
170147
if strings.Contains(cm.Name, "event-rate-limit") {
171148
t.Logf("Found standalone EventRateLimit configuration in ConfigMap: %s", cm.Name)
@@ -188,12 +165,9 @@ func Test_scs_0215_apiPriorityAndFairness(t *testing.T) {
188165
}
189166

190167
t.Run("Check_APF_Configuration", func(t *testing.T) {
191-
pods, err := clientset.CoreV1().Pods("kube-system").List(
192-
context.TODO(),
193-
metav1.ListOptions{
194-
LabelSelector: "component=kube-apiserver",
195-
},
196-
)
168+
pods, err := clientset.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{
169+
LabelSelector: "component=kube-apiserver",
170+
})
197171
if err != nil || len(pods.Items) == 0 {
198172
t.Fatal("Failed to find kube-apiserver pod")
199173
}
@@ -227,7 +201,7 @@ func Test_scs_0215_rateLimitValues(t *testing.T) {
227201
"burst": "20000",
228202
}
229203

230-
configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.TODO(), metav1.ListOptions{})
204+
configMaps, _ := clientset.CoreV1().ConfigMaps("kube-system").List(context.Background(), metav1.ListOptions{})
231205
for _, cm := range configMaps.Items {
232206
var config string
233207
switch {
@@ -268,12 +242,9 @@ func Test_scs_0215_etcdCompaction(t *testing.T) {
268242
}
269243

270244
t.Run("Check_Etcd_Compaction_Settings", func(t *testing.T) {
271-
pods, err := clientset.CoreV1().Pods("kube-system").List(
272-
context.TODO(),
273-
metav1.ListOptions{
274-
LabelSelector: "component=etcd",
275-
},
276-
)
245+
pods, err := clientset.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{
246+
LabelSelector: "component=etcd",
247+
})
277248
if err != nil || len(pods.Items) == 0 {
278249
t.Skip("No etcd pods found")
279250
return
@@ -317,7 +288,7 @@ func Test_scs_0215_etcdBackup(t *testing.T) {
317288
}
318289

319290
t.Run("Check_Etcd_Backup_Configuration", func(t *testing.T) {
320-
cronJobs, err := clientset.BatchV1().CronJobs("").List(context.TODO(), metav1.ListOptions{})
291+
cronJobs, err := clientset.BatchV1().CronJobs("").List(context.Background(), metav1.ListOptions{})
321292
if err == nil {
322293
for _, job := range cronJobs.Items {
323294
if strings.Contains(strings.ToLower(job.Name), "etcd") &&
@@ -338,11 +309,7 @@ func Test_scs_0215_certificateRotation(t *testing.T) {
338309
}
339310

340311
t.Run("Check_Certificate_Controller", func(t *testing.T) {
341-
_, err := clientset.AppsV1().Deployments("cert-manager").Get(
342-
context.TODO(),
343-
"cert-manager",
344-
metav1.GetOptions{},
345-
)
312+
_, err := clientset.AppsV1().Deployments("cert-manager").Get(context.Background(), "cert-manager", metav1.GetOptions{})
346313
if err != nil {
347314
t.Error("cert-manager not found - certificate controller required")
348315
} else {

0 commit comments

Comments
 (0)