Skip to content
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

scripts: refresh e2e-presubmit test script #1758

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 11 additions & 45 deletions scripts/test-infra/test-e2e-presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,32 @@
set -o pipefail

# Configure environment
KIND_IMAGE="kindest/node:v1.25.3"
export IMAGE_REGISTRY="localhost:5001"
export CLUSTER_NAME=$(git describe --tags --dirty --always)
export KIND_VERSION="v0.23.0"
export KIND_NODE_IMAGE="kindest/node:v1.30.2"
export CLUSTER_NAME="nfd-e2e"
export KUBECONFIG="/tmp/kubeconfig_$CLUSTER_NAME"
export IMAGE_REPO="registry.local/node-feature-discovery"
export IMAGE_TAG_NAME=$(git describe --tags --dirty --always)

# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5001'
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
# Install kind
go install sigs.k8s.io/kind@$KIND_VERSION

# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --kubeconfig $KUBECONFIG --config=-
cat <<EOF | kind create cluster --kubeconfig $KUBECONFIG --image $KIND_NODE_IMAGE --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: $CLUSTER_NAME
nodes:
- role: control-plane
image: $KIND_IMAGE
- role: worker
image: $KIND_IMAGE
- role: worker
image: $KIND_IMAGE
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:5000"]
EOF

# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

# build the local image
make image
make image IMAGE_REPO=$IMAGE_REPO IMAGE_TAG_NAME=$IMAGE_TAG_NAME

# push the image to the local registry
make push
kind load docker-image $IMAGE_REPO:$IMAGE_TAG_NAME --name $CLUSTER_NAME

# run the tests
make e2e-test || rc=$?

# clean up the environment
kind delete cluster --kubeconfig $KUBECONFIG --name $CLUSTER_NAME
echo "Deleting ${reg_name} container ..."
docker rm -f "${reg_name}"
exit $rc
make e2e-test IMAGE_REPO=$IMAGE_REPO IMAGE_TAG_NAME=$IMAGE_TAG_NAME E2E_PULL_IF_NOT_PRESENT=true