-
Notifications
You must be signed in to change notification settings - Fork 207
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
improve tests #1021
Open
evrardjp
wants to merge
7
commits into
kubereboot:main
Choose a base branch
from
evrardjp:improve_tests
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
improve tests #1021
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a02626
Add e2e test concurrency w/ signal
evrardjp 27c9c5d
Add podblocker test
evrardjp 0a1750d
Rename "version" with "variant" in tests
evrardjp 6170770
Fix Staticcheck's SA1024 (subset with dupe chars)
evrardjp ca73c4a
Fix Staticcheck's ST1005
evrardjp 3cb82a0
Fix incorrect string prints
evrardjp 76765f5
Add staticcheck in make tests
evrardjp 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
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
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
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 |
---|---|---|
|
@@ -152,7 +152,7 @@ func TestE2EWithCommand(t *testing.T) { | |
t.Run(version, func(t *testing.T) { | ||
t.Parallel() // Allow tests to run in parallel | ||
|
||
randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) | ||
randomInt := strconv.Itoa(rand.Intn(100)) | ||
kindClusterName := fmt.Sprintf("kured-e2e-command-%v-%v", version, randomInt) | ||
kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) | ||
kindContext := fmt.Sprintf("kind-%v", kindClusterName) | ||
|
@@ -202,7 +202,7 @@ func TestE2EWithSignal(t *testing.T) { | |
t.Run(version, func(t *testing.T) { | ||
t.Parallel() // Allow tests to run in parallel | ||
|
||
randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) | ||
randomInt := strconv.Itoa(rand.Intn(100)) | ||
kindClusterName := fmt.Sprintf("kured-e2e-signal-%v-%v", version, randomInt) | ||
kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) | ||
kindContext := fmt.Sprintf("kind-%v", kindClusterName) | ||
|
@@ -252,12 +252,12 @@ func TestE2EConcurrentWithCommand(t *testing.T) { | |
t.Run(version, func(t *testing.T) { | ||
t.Parallel() // Allow tests to run in parallel | ||
|
||
randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) | ||
randomInt := strconv.Itoa(rand.Intn(100)) | ||
kindClusterName := fmt.Sprintf("kured-e2e-concurrentcommand-%v-%v", version, randomInt) | ||
kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) | ||
kindContext := fmt.Sprintf("kind-%v", kindClusterName) | ||
|
||
k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent.yaml")) | ||
k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent-command.yaml")) | ||
defer k.FlushLog() | ||
|
||
err := k.Create() | ||
|
@@ -284,15 +284,16 @@ func TestE2EConcurrentWithCommand(t *testing.T) { | |
} | ||
} | ||
|
||
func TestCordonningIsKept(t *testing.T) { | ||
func TestE2EConcurrentWithSignal(t *testing.T) { | ||
t.Parallel() | ||
if testing.Short() { | ||
t.Skip("skipping test in short mode.") | ||
} | ||
|
||
var kindClusterConfigs = []string{ | ||
"concurrency1", | ||
"concurrency2", | ||
"previous", | ||
"current", | ||
"next", | ||
} | ||
// Iterate over each Kubernetes version | ||
for _, version := range kindClusterConfigs { | ||
|
@@ -301,16 +302,65 @@ func TestCordonningIsKept(t *testing.T) { | |
t.Run(version, func(t *testing.T) { | ||
t.Parallel() // Allow tests to run in parallel | ||
|
||
randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) | ||
kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", version, randomInt) | ||
kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-next.yaml") | ||
randomInt := strconv.Itoa(rand.Intn(100)) | ||
kindClusterName := fmt.Sprintf("kured-e2e-concurrentsignal-%v-%v", version, randomInt) | ||
kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) | ||
kindContext := fmt.Sprintf("kind-%v", kindClusterName) | ||
|
||
k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent-signal.yaml")) | ||
defer k.FlushLog() | ||
|
||
err := k.Create() | ||
if err != nil { | ||
t.Fatalf("Error creating cluster %v", err) | ||
} | ||
defer func(k *KindTest) { | ||
err := k.Destroy() | ||
if err != nil { | ||
t.Fatalf("Error destroying cluster %v", err) | ||
} | ||
}(k) | ||
|
||
k.Write([]byte("Now running e2e tests")) | ||
|
||
if err := k.RunCmd("bash", "testfiles/create-reboot-sentinels.sh", kindContext); err != nil { | ||
t.Fatalf("failed to create sentinels: %v", err) | ||
} | ||
|
||
if err := k.RunCmd("bash", "testfiles/follow-coordinated-reboot.sh", kindContext); err != nil { | ||
t.Fatalf("failed to follow reboot: %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCordonningIsKept(t *testing.T) { | ||
t.Parallel() | ||
if testing.Short() { | ||
t.Skip("skipping test in short mode.") | ||
} | ||
|
||
var kindClusterConfigs = []string{ | ||
"concurrency1", | ||
"concurrency2", | ||
} | ||
// Iterate over each test variant | ||
for _, variant := range kindClusterConfigs { | ||
variant := variant | ||
// Define a subtest for each combination | ||
t.Run(variant, func(t *testing.T) { | ||
t.Parallel() // Allow tests to run in parallel | ||
|
||
randomInt := strconv.Itoa(rand.Intn(100)) | ||
kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", variant, randomInt) | ||
kindClusterConfigFile := "../../.github/kind-cluster-next.yaml" | ||
kindContext := fmt.Sprintf("kind-%v", kindClusterName) | ||
|
||
var manifest string | ||
if version == "concurrency1" { | ||
manifest = fmt.Sprintf("testfiles/kured-ds.yaml") | ||
if variant == "concurrency1" { | ||
manifest = "testfiles/kured-ds-signal.yaml" | ||
} else { | ||
manifest = fmt.Sprintf("testfiles/kured-ds-concurrent.yaml") | ||
manifest = "testfiles/kured-ds-concurrent-signal.yaml" | ||
} | ||
k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(manifest)) | ||
defer k.FlushLog() | ||
|
@@ -334,3 +384,46 @@ func TestCordonningIsKept(t *testing.T) { | |
}) | ||
} | ||
} | ||
func TestE2EBlocker(t *testing.T) { | ||
t.Parallel() | ||
if testing.Short() { | ||
t.Skip("skipping test in short mode.") | ||
} | ||
|
||
var kindClusterConfigs = []string{ | ||
"podblocker", | ||
} | ||
// Iterate over each variant of the test | ||
for _, variant := range kindClusterConfigs { | ||
variant := variant | ||
// Define a subtest for each combination | ||
t.Run(variant, func(t *testing.T) { | ||
t.Parallel() // Allow tests to run in parallel | ||
|
||
randomInt := strconv.Itoa(rand.Intn(100)) | ||
kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", variant, randomInt) | ||
kindClusterConfigFile := "../../.github/kind-cluster-next.yaml" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto above comment |
||
kindContext := fmt.Sprintf("kind-%v", kindClusterName) | ||
|
||
k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", variant))) | ||
defer k.FlushLog() | ||
|
||
err := k.Create() | ||
if err != nil { | ||
t.Fatalf("Error creating cluster %v", err) | ||
} | ||
defer func(k *KindTest) { | ||
err := k.Destroy() | ||
if err != nil { | ||
t.Fatalf("Error destroying cluster %v", err) | ||
} | ||
}(k) | ||
|
||
k.Write([]byte("Now running e2e tests")) | ||
|
||
if err := k.RunCmd("bash", fmt.Sprintf("testfiles/%v.sh", variant), kindContext); err != nil { | ||
t.Fatalf("node blocker test did not succeed: %v", err) | ||
} | ||
}) | ||
} | ||
} |
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,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
kubectl_flags=( ) | ||
[[ "$1" != "" ]] && kubectl_flags=("${kubectl_flags[@]}" --context "$1") | ||
|
||
function gather_logs_and_cleanup { | ||
for id in $(docker ps -q); do | ||
echo "############################################################" | ||
echo "docker logs for container $id:" | ||
docker logs "$id" | ||
done | ||
${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" logs ds/kured --all-pods -n kube-system | ||
} | ||
trap gather_logs_and_cleanup EXIT | ||
|
||
set +o errexit | ||
worker=$(${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" get nodes -o custom-columns=name:metadata.name --no-headers | grep worker | head -n 1) | ||
|
||
${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" label nodes "$worker" blocked-host=yes | ||
|
||
${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" apply -f - << EOF | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: blocker | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
imagePullPolicy: IfNotPresent | ||
nodeSelector: | ||
blocked-host: "yes" | ||
EOF | ||
|
||
docker exec "$worker" touch "${SENTINEL_FILE:-/var/run/reboot-required}" | ||
|
||
set -o errexit | ||
max_attempts="100" | ||
attempt_num=1 | ||
sleep_time=5 | ||
|
||
until ${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" logs ds/kured --all-pods -n kube-system | grep -i -e "Reboot.*blocked" | ||
do | ||
if (( attempt_num == max_attempts )); then | ||
echo "Attempt $attempt_num failed and there are no more attempts left!" | ||
exit 1 | ||
else | ||
echo "Did not find 'reboot blocked' in the log, retrying in $sleep_time seconds (Attempt #$attempt_num)" | ||
sleep "$sleep_time" | ||
fi | ||
(( attempt_num++ )) | ||
done |
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.
wonder why we're not iterating over all k8s versions for this test?
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.
Wasted CPU? I am not expecting the behaviour to change across different versions of kubernetes. Hence testing the latest version sounds enough. That reasoning can be applied in most of the tests...
Do you feel we should simplify this?
Here is what I find necessary:
WDYT?