Skip to content

Commit

Permalink
Run gracefulshutdown test at the end
Browse files Browse the repository at this point in the history
- avoids conflicts with other tests
- change gracefulshutdown test to delete all gateway pods
  • Loading branch information
norbjd authored Apr 27, 2024
1 parent 44ff38c commit ba83fe9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 69 deletions.
102 changes: 51 additions & 51 deletions test/e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,57 +49,6 @@ go test -count=1 -short -timeout=20m -tags=e2e ./test/conformance/... ./test/e2e
--ingressClass=kourier.ingress.networking.knative.dev \
--cluster-suffix="$CLUSTER_SUFFIX"

echo ">> Change DRAIN_TIME_SECONDS and terminationGracePeriodSeconds for graceful shutdown tests"
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" patch deployment/3scale-kourier-gateway -p '{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "kourier-gateway",
"env": [
{
"name": "DRAIN_TIME_SECONDS",
"value": "30"
}
]
}
],
"terminationGracePeriodSeconds": 60
}
}
}
}'
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" rollout status deployment/3scale-kourier-gateway --timeout=300s

echo ">> Running graceful shutdown tests"
DRAIN_TIME_SECONDS=30 go test -race -count=1 -timeout=20m -tags=e2e ./test/gracefulshutdown \
--ingressendpoint="${IPS[0]}" \
--ingressClass=kourier.ingress.networking.knative.dev \
--cluster-suffix="$CLUSTER_SUFFIX"

kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" patch deployment/3scale-kourier-gateway -p '{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "kourier-gateway",
"env": [
{
"name": "DRAIN_TIME_SECONDS",
"value": "15"
}
]
}
],
"terminationGracePeriodSeconds": null
}
}
}
}'
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" rollout status deployment/3scale-kourier-gateway --timeout=300s

echo ">> Scale up components for HA tests"
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" scale deployment 3scale-kourier-gateway --replicas=2
kubectl -n "${KOURIER_CONTROL_NAMESPACE}" scale deployment net-kourier-controller --replicas=2
Expand Down Expand Up @@ -241,6 +190,57 @@ kubectl -n "${KOURIER_CONTROL_NAMESPACE}" patch configmap/config-kourier --type
kubectl delete -f test/config/tracing
unset TRACING_COLLECTOR_FULL_ENDPOINT

echo ">> Change DRAIN_TIME_SECONDS and terminationGracePeriodSeconds for graceful shutdown tests"
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" patch deployment/3scale-kourier-gateway -p '{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "kourier-gateway",
"env": [
{
"name": "DRAIN_TIME_SECONDS",
"value": "30"
}
]
}
],
"terminationGracePeriodSeconds": 60
}
}
}
}'
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" rollout status deployment/3scale-kourier-gateway --timeout=300s

echo ">> Running graceful shutdown tests"
DRAIN_TIME_SECONDS=30 go test -race -count=1 -timeout=20m -tags=e2e ./test/gracefulshutdown \
--ingressendpoint="${IPS[0]}" \
--ingressClass=kourier.ingress.networking.knative.dev \
--cluster-suffix="$CLUSTER_SUFFIX"

kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" patch deployment/3scale-kourier-gateway -p '{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "kourier-gateway",
"env": [
{
"name": "DRAIN_TIME_SECONDS",
"value": "15"
}
]
}
],
"terminationGracePeriodSeconds": null
}
}
}
}'
kubectl -n "${KOURIER_GATEWAY_NAMESPACE}" rollout status deployment/3scale-kourier-gateway --timeout=300s

echo ">> Set IdleTimeout to 50s"
kubectl -n "${KOURIER_CONTROL_NAMESPACE}" patch configmap/config-kourier --type merge -p '{"data":{"stream-idle-timeout":"50s"}}'

Expand Down
33 changes: 15 additions & 18 deletions test/gracefulshutdown/gracefulshutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,7 @@ func TestGracefulShutdown(t *testing.T) {

clients := test.Setup(t)
ctx := context.Background()

// Retrieve the gateway pod name
gatewayPods, err := clients.KubeClient.CoreV1().Pods(gatewayNs).List(ctx, metav1.ListOptions{
LabelSelector: kourierGatewayLabel,
})
if err != nil {
t.Fatal("Failed to get Gateway pods:", err)
}
if len(gatewayPods.Items) != 1 {
t.Fatal("This test expects exactly 1 gateway pod, found:", len(gatewayPods.Items))
}

gatewayPodName := gatewayPods.Items[0].Name


// Create a service and an ingress
name, port, _ := ingress.CreateTimeoutService(ctx, t, clients)
_, client, _ := ingress.CreateIngressReady(ctx, t, clients, v1alpha1.IngressSpec{
Expand Down Expand Up @@ -133,11 +120,21 @@ func TestGracefulShutdown(t *testing.T) {
})
}

// Once requests are in-flight, delete the gateway pod:
// the 1 second sleep before the deletion is here to ensure the requests have been sent by the goroutines above
// Ensures the requests sent by the goroutines above are in-flight
time.Sleep(1 * time.Second)
if err := clients.KubeClient.CoreV1().Pods(gatewayNs).Delete(ctx, gatewayPodName, metav1.DeleteOptions{}); err != nil {
t.Fatalf("Failed to delete pod %s: %v", gatewayPodName, err)

// Delete all gateway pods
gatewayPods, err := clients.KubeClient.CoreV1().Pods(gatewayNs).Delete(ctx, metav1.DeleteOptions{

Check failure on line 127 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

assignment mismatch: 2 variables but clients.KubeClient.CoreV1().Pods(gatewayNs).Delete returns 1 value

Check failure on line 127 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

not enough arguments in call to clients.KubeClient.CoreV1().Pods(gatewayNs).Delete

Check failure on line 127 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / build / Build

assignment mismatch: 2 variables but clients.KubeClient.CoreV1().Pods(gatewayNs).Delete returns 1 value

Check failure on line 127 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / build / Build

not enough arguments in call to clients.KubeClient.CoreV1().Pods(gatewayNs).Delete
LabelSelector: kourierGatewayLabel,

Check failure on line 128 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

unknown field LabelSelector in struct literal of type "k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions (typecheck)

Check failure on line 128 in test/gracefulshutdown/gracefulshutdown_test.go

View workflow job for this annotation

GitHub Actions / build / Build

unknown field LabelSelector in struct literal of type "k8s.io/apimachinery/pkg/apis/meta/v1".DeleteOptions
})
if err != nil {
t.Fatal("Failed to get Gateway pods:", err)
}

for _, gatewayPod := range gatewayPods.Items {
if err := clients.KubeClient.CoreV1().Pods(gatewayNs).Delete(ctx, gatewayPod.Name, metav1.DeleteOptions{}); err != nil {
t.Fatalf("Failed to delete pod %s: %v", gatewayPod.Name, err)
}
}

// Wait until we get responses from the asynchronous requests
Expand Down

0 comments on commit ba83fe9

Please sign in to comment.