-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add KaaS robustness feature tests #714
Open
cah-patrickthiem
wants to merge
7
commits into
main
Choose a base branch
from
549-testing-kaas-robustness-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c2aaba
Added the first robustness feature test called maxRequestInflight.
cah-patrickthiem 4d11602
Added two more tests regarding the robustness K8s standard, namely "m…
cah-patrickthiem 7013a9d
add results path to .gitignore
cah-patrickthiem 9f4ec85
Added remaining robustness tests.
cah-patrickthiem cbcca65
added/adjusted the remaining tests
cah-patrickthiem cb8e7a3
Addressed review commands.
cah-patrickthiem 363d62a
Merge branch 'main' into 549-testing-kaas-robustness-features
cah-patrickthiem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ nodes: | |
- role: control-plane | ||
- role: worker | ||
- role: worker | ||
- role: worker | ||
- role: worker |
208 changes: 208 additions & 0 deletions
208
...aas/kaas-sonobuoy-tests/scs_k8s_conformance_tests/scs_0215_v1_robustness_features_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
package scs_k8s_tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
// ==================== Helper Functions ==================== | ||
|
||
// setupClientset creates a Kubernetes clientset | ||
func setupClientset() (*kubernetes.Clientset, error) { | ||
config, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load in-cluster config: %v", err) | ||
} | ||
return kubernetes.NewForConfig(config) | ||
} | ||
|
||
// ==================== Test Cases ==================== | ||
|
||
func Test_scs_0215_requestLimits(t *testing.T) { | ||
clientset, err := setupClientset() | ||
if err != nil { | ||
t.Fatalf("Failed to setup clientset: %v", err) | ||
} | ||
|
||
t.Run("Check_Request_Limit_Configuration", func(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", | ||
}) | ||
if err != nil || len(pods.Items) == 0 { | ||
t.Fatalf("Failed to find kube-apiserver pod: %v", err) | ||
} | ||
|
||
apiServer := pods.Items[0] | ||
var foundSettings = make(map[string]bool) | ||
requiredSettings := []string{ | ||
"max-requests-inflight", | ||
"max-mutating-requests-inflight", | ||
"min-request-timeout", | ||
"EventRateLimit", | ||
} | ||
|
||
for _, container := range apiServer.Spec.Containers { | ||
for _, arg := range container.Command { | ||
for _, setting := range requiredSettings { | ||
if strings.Contains(arg, setting) { | ||
foundSettings[setting] = true | ||
} | ||
} | ||
if strings.Contains(arg, "enable-admission-plugins") && | ||
strings.Contains(arg, "EventRateLimit") { | ||
foundSettings["EventRateLimit"] = true | ||
} | ||
} | ||
} | ||
|
||
for _, setting := range requiredSettings { | ||
if !foundSettings[setting] { | ||
t.Errorf("Required setting %s not found in API server configuration", setting) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func Test_scs_0215_minRequestTimeout(t *testing.T) { | ||
clientset, err := setupClientset() | ||
if err != nil { | ||
t.Fatalf("Failed to setup clientset: %v", err) | ||
} | ||
|
||
t.Run("Check_minRequestTimeout_Configuration", func(t *testing.T) { | ||
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) | ||
} | ||
|
||
found := false | ||
for _, container := range pods.Items[0].Spec.Containers { | ||
for _, arg := range container.Command { | ||
if strings.Contains(arg, "--min-request-timeout=") { | ||
found = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
if !found { | ||
t.Error("min-request-timeout not configured for API server") | ||
} | ||
}) | ||
} | ||
|
||
func Test_scs_0215_eventRateLimit(t *testing.T) { | ||
clientset, err := setupClientset() | ||
if err != nil { | ||
t.Fatalf("Failed to setup clientset: %v", err) | ||
} | ||
|
||
t.Run("Check_EventRateLimit_Configuration", func(t *testing.T) { | ||
configLocations := []struct { | ||
name string | ||
namespace string | ||
key string | ||
}{ | ||
{"admission-configuration", "kube-system", "eventratelimit.yaml"}, | ||
{"kube-apiserver", "kube-system", "config.yaml"}, | ||
} | ||
|
||
for _, loc := range configLocations { | ||
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") { | ||
t.Logf("Found EventRateLimit configuration in %s/%s", loc.namespace, loc.name) | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
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) | ||
return | ||
} | ||
} | ||
|
||
t.Error("No EventRateLimit configuration found in production cluster") | ||
}) | ||
} | ||
|
||
func Test_scs_0215_apiPriorityAndFairness(t *testing.T) { | ||
clientset, err := setupClientset() | ||
if err != nil { | ||
t.Fatalf("Failed to setup clientset: %v", err) | ||
} | ||
|
||
t.Run("Check_APF_Configuration", func(t *testing.T) { | ||
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") | ||
} | ||
|
||
for _, container := range pods.Items[0].Spec.Containers { | ||
for _, arg := range container.Command { | ||
if strings.Contains(arg, "--enable-priority-and-fairness=true") { | ||
t.Log("APF enabled via Command Line Flags") | ||
return | ||
} | ||
} | ||
} | ||
|
||
t.Error("API Priority and Fairness not enabled") | ||
}) | ||
} | ||
|
||
func Test_scs_0215_etcdBackup(t *testing.T) { | ||
clientset, err := setupClientset() | ||
if err != nil { | ||
t.Fatalf("Failed to setup clientset: %v", err) | ||
} | ||
|
||
t.Run("Check_Etcd_Backup_Configuration", func(t *testing.T) { | ||
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") && | ||
strings.Contains(strings.ToLower(job.Name), "backup") { | ||
t.Log("Found etcd backup solution: CronJob") | ||
return | ||
} | ||
} | ||
} | ||
t.Error("No etcd backup solution found") | ||
}) | ||
} | ||
|
||
func Test_scs_0215_certificateRotation(t *testing.T) { | ||
clientset, err := setupClientset() | ||
if err != nil { | ||
t.Skip("Failed to setup clientset") | ||
} | ||
|
||
t.Run("Check_Certificate_Controller", func(t *testing.T) { | ||
_, 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 { | ||
t.Log("Found active certificate controller: cert-manager") | ||
} | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different from the test in
Test_scs_0215_requestLimits()
Isn't this check already handled on this line L67
On second though, if this does the same check, I think it would be better to only handle it here in
Test_scs_0215_minRequestTimeout()
, as this is the testfunction related to "EventRateLimit"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, these are different tests. The first test checks if the EventRateLimit is enabled in the API server command line flags, while the second test specifically looks for EventRateLimit configuration in ConfigMaps. The second test is more thorough as it searches multiple locations for the actual configuration details.
The first test only verifies the admission plugin is enabled, while the second test verifies the configuration exists and is properly set up.