Skip to content

Commit

Permalink
Add e2e test for SupportBundleCollection for K8s Nodes (#6866)
Browse files Browse the repository at this point in the history
The SupportBundleCollection CRD can be used to collect support bundle
files and upload them to a file server. It supports both K8s Nodes and
VMs (External Nodes). Prior to this change, we would only test the VM
case. The SupportBundleCollection e2e test for VMs cannot easily be run
locally on a Kind cluster, which makes it impractical for
development. The corresponding CI job (which runs the e2e test) also has
to be triggered manually, which means it is not always run for all PRs,
which can cause breakage.

This change introduces a new SupportBundleCollection e2e test, which
only collects bundles from K8s Nodes. The test can be run locally on a
Kind cluster, as long as Antrea is installed with the
SupportBundleCollection Feature Gate enabled.

We also use a uniform mechanism to deploy an SFTP server for e2e
tests. hack/externalnode/sftp-deployment.yml is no longer used for e2e
tests, and the necessary Deployment / Service are created
programmatically, using the same mechanism as for existing PacketCapture
tests.

Finally, we add a new e2e test case for the PacketCapture feature, to
test the case where an unexpected public host key is provided in the
PacketCapture CR (the key does not match any of the server's keys).

Note that as part of this change, the toolbox image is updated to 1.5-0,
as the curl command included with ubuntu 22.04 seems to have issues with
SFTP (the 1.5 version of the image is based on ubuntu 24.04).

Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored Dec 21, 2024
1 parent b5f3713 commit 2773cfd
Show file tree
Hide file tree
Showing 10 changed files with 771 additions and 426 deletions.
1 change: 0 additions & 1 deletion ci/jenkins/test-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ function configure_vm_agent {
cp ./build/yamls/externalnode/support-bundle-collection-rbac.yml ${WORKDIR}/support-bundle-collection-rbac.yml
echo "Applying support-bundle-collection rbac yaml"
kubectl apply -f ${WORKDIR}/support-bundle-collection-rbac.yml -n $TEST_NAMESPACE
cp ./hack/externalnode/sftp-deployment.yml ${WORKDIR}/sftp-deployment.yml
cp ./hack/externalnode/install-vm.sh ${WORKDIR}/install-vm.sh
cp ./hack/externalnode/install-vm.ps1 ${WORKDIR}/install-vm.ps1
create_kubeconfig_files
Expand Down
2 changes: 1 addition & 1 deletion ci/jenkins/test-vmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ function deliver_antrea {
${SCP_WITH_ANTREA_CI_KEY} $GIT_CHECKOUT_DIR/build/yamls/*.yml capv@${control_plane_ip}:~

IPs=($(kubectl get nodes -o wide --no-headers=true | awk '{print $6}' | xargs))
antrea_images=("registry.k8s.io/e2e-test-images/agnhost:2.40" "antrea/nginx:1.21.6-alpine" "antrea/sonobuoy:v0.56.16" "antrea/toolbox:1.3-0" "antrea/systemd-logs:v0.4")
antrea_images=("registry.k8s.io/e2e-test-images/agnhost:2.40" "antrea/nginx:1.21.6-alpine" "antrea/sonobuoy:v0.56.16" "antrea/toolbox:1.5-1" "antrea/systemd-logs:v0.4")
k8s_images=("registry.k8s.io/e2e-test-images/agnhost:2.45" "registry.k8s.io/e2e-test-images/jessie-dnsutils:1.5" "registry.k8s.io/e2e-test-images/nginx:1.14-2")
e2e_images=("k8sprow.azurecr.io/kubernetes-e2e-test-images/agnhost:2.45" "k8sprow.azurecr.io/kubernetes-e2e-test-images/jessie-dnsutils:1.5" "k8sprow.azurecr.io/kubernetes-e2e-test-images/nginx:1.14-2")
for image in "${antrea_images[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion ci/kind/test-e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fi

COMMON_IMAGES_LIST=("registry.k8s.io/e2e-test-images/agnhost:2.40" \
"antrea/nginx:1.21.6-alpine" \
"antrea/toolbox:1.3-0")
"antrea/toolbox:1.5-1")

FLOW_VISIBILITY_IMAGE_LIST=("antrea/ipfix-collector:v0.11.0" \
"antrea/clickhouse-operator:0.21.0" \
Expand Down
2 changes: 1 addition & 1 deletion ci/kind/test-secondary-network-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fi

trap "quit" INT EXIT

IMAGE_LIST=("antrea/toolbox:1.3-0" \
IMAGE_LIST=("antrea/toolbox:1.5-1" \
"antrea/antrea-agent-ubuntu:latest" \
"antrea/antrea-controller-ubuntu:latest")

Expand Down
32 changes: 31 additions & 1 deletion test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"regexp"
"strconv"
"strings"
"testing"
"time"

"github.com/containernetworking/plugins/pkg/ip"
Expand All @@ -40,6 +41,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -121,7 +123,7 @@ const (
flowAggregatorConfName = "flow-aggregator.conf"

agnhostImage = "registry.k8s.io/e2e-test-images/agnhost:2.40"
ToolboxImage = "antrea/toolbox:1.3-0"
ToolboxImage = "antrea/toolbox:1.5-1"
mcjoinImage = "antrea/mcjoin:v2.9"
nginxImage = "antrea/nginx:1.21.6-alpine"
iisImage = "mcr.microsoft.com/windows/servercore/iis"
Expand Down Expand Up @@ -3300,3 +3302,31 @@ func (data *TestData) setPodAnnotation(namespace, podName, annotationKey string,
log.Infof("Successfully patched Pod %s in Namespace %s", podName, namespace)
return nil
}

func (data *TestData) waitForDeploymentReady(t *testing.T, namespace string, name string, timeout time.Duration) error {
t.Logf("Waiting for Deployment '%s/%s' to be ready", namespace, name)
var labelSelector *metav1.LabelSelector
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeout, false, func(ctx context.Context) (bool, error) {
dp, err := data.clientset.AppsV1().Deployments(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
return false, err
}
labelSelector = dp.Spec.Selector
return dp.Status.ObservedGeneration == dp.Generation && dp.Status.ReadyReplicas == *dp.Spec.Replicas, nil
})
if wait.Interrupted(err) {
labelMap, err := metav1.LabelSelectorAsMap(labelSelector)
var stdout string
if err != nil {
t.Logf("Cannot convert Selector for Deployment into kubectl label query: %v", err)
stdout = "<no debug output available>"
} else {
labelQuery := labels.SelectorFromSet(labelMap).String()
_, stdout, _, _ = data.provider.RunCommandOnNode(controlPlaneNodeName(), fmt.Sprintf("kubectl -n %s describe pod -l %s", namespace, labelQuery))
}
return fmt.Errorf("some replicas for Deployment '%s/%s' are not ready after %v:\n%s", namespace, name, timeout, stdout)
} else if err != nil {
return fmt.Errorf("error when waiting for Deployment '%s/%s' to be ready: %w", namespace, name, err)
}
return nil
}
Loading

0 comments on commit 2773cfd

Please sign in to comment.