Skip to content

Commit c21dd5b

Browse files
committed
unify cmdinit e2e and ci
Signed-off-by: zhzhuang-zju <[email protected]>
1 parent e2c4b59 commit c21dd5b

File tree

8 files changed

+350
-232
lines changed

8 files changed

+350
-232
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -162,61 +162,3 @@ jobs:
162162
with:
163163
name: karmada_kind_log_${{ matrix.k8s }}
164164
path: /tmp/karmada/
165-
166-
e2e-init:
167-
name: init e2e test
168-
needs: build
169-
runs-on: ubuntu-22.04
170-
strategy:
171-
fail-fast: false
172-
matrix:
173-
# Here support the latest three minor releases of Kubernetes, this can be considered to be roughly
174-
# the same as the End of Life of the Kubernetes release: https://kubernetes.io/releases/
175-
# Please remember to update the CI Schedule Workflow when we add a new version.
176-
k8s: [ v1.31.0, v1.32.0, v1.33.0 ]
177-
steps:
178-
# Free up disk space on Ubuntu
179-
- name: Free Disk Space (Ubuntu)
180-
uses: jlumbroso/free-disk-space@main
181-
with:
182-
# this might remove tools that are actually needed, if set to "true" but frees about 6 GB
183-
tool-cache: false
184-
# all of these default to true, but feel free to set to "false" if necessary for your workflow
185-
android: true
186-
dotnet: true
187-
haskell: true
188-
large-packages: false
189-
docker-images: false
190-
swap-storage: false
191-
- name: checkout code
192-
uses: actions/checkout@v5
193-
with:
194-
# Number of commits to fetch. 0 indicates all history for all branches and tags.
195-
# We need to guess version via git tags.
196-
fetch-depth: 0
197-
- name: install Go
198-
uses: actions/setup-go@v6
199-
with:
200-
go-version-file: go.mod
201-
- name: setup init e2e test environment
202-
run: |
203-
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
204-
hack/init-e2e-environment.sh
205-
- name: run e2e
206-
run: |
207-
export ARTIFACTS_PATH=${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
208-
export REGISTRY="docker.io/karmada"
209-
export VERSION="latest"
210-
hack/run-e2e-init.sh
211-
- name: upload logs
212-
if: always()
213-
uses: actions/upload-artifact@v5
214-
with:
215-
name: karmada_init_e2e_log_${{ matrix.k8s }}
216-
path: ${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
217-
- name: upload kind logs
218-
if: always()
219-
uses: actions/upload-artifact@v5
220-
with:
221-
name: karmada_init_kind_log_${{ matrix.k8s }}
222-
path: /tmp/karmada/

.github/workflows/installation-cli.yaml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ jobs:
2626
# Please remember to update the CI Schedule Workflow when we add a new version.
2727
k8s: [ v1.31.0, v1.32.0, v1.33.0 ]
2828
steps:
29+
# Free up disk space on Ubuntu
30+
- name: Free Disk Space (Ubuntu)
31+
uses: jlumbroso/free-disk-space@main
32+
with:
33+
# this might remove tools that are actually needed, if set to "true" but frees about 6 GB
34+
tool-cache: false
35+
# all of these default to true, but feel free to set to "false" if necessary for your workflow
36+
android: true
37+
dotnet: true
38+
haskell: true
39+
large-packages: false
40+
docker-images: false
41+
swap-storage: false
2942
- name: checkout code
3043
uses: actions/checkout@v5
3144
with:
@@ -36,32 +49,28 @@ jobs:
3649
uses: actions/setup-go@v6
3750
with:
3851
go-version-file: go.mod
39-
- name: run karmadactl init test
52+
- name: setup init e2e test environment
4053
run: |
4154
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
42-
43-
# init e2e environment
44-
hack/cli-testing-environment.sh
45-
46-
# run a single e2e
47-
export PULL_BASED_CLUSTERS="member1:${HOME}/.kube/member1.config"
48-
export KUBECONFIG=${HOME}/.kube/karmada-host.config:${HOME}/karmada/karmada-apiserver.config
49-
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
50-
ginkgo -v --race --trace -p --focus="[BasicPropagation] propagation testing deployment propagation testing" ./test/e2e/suites/base
51-
- name: export logs
52-
if: always()
55+
hack/init-e2e-environment.sh
56+
- name: run e2e
5357
run: |
54-
export ARTIFACTS_PATH=${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/
55-
mkdir -p $ARTIFACTS_PATH
56-
57-
mkdir -p $ARTIFACTS_PATH/karmada-host
58-
kind export logs --name=karmada-host $ARTIFACTS_PATH/karmada-host
58+
export ARTIFACTS_PATH=${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
59+
export REGISTRY="docker.io/karmada"
60+
export VERSION="latest"
61+
hack/run-e2e-init.sh
5962
- name: upload logs
6063
if: always()
6164
uses: actions/upload-artifact@v5
6265
with:
63-
name: karmadactl_test_logs_${{ matrix.k8s }}
64-
path: ${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/
66+
name: karmada_init_e2e_log_${{ matrix.k8s }}
67+
path: ${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
68+
- name: upload kind logs
69+
if: always()
70+
uses: actions/upload-artifact@v5
71+
with:
72+
name: karmada_init_kind_log_${{ matrix.k8s }}
73+
path: /tmp/karmada/
6574

6675
init-config:
6776
name: init with config file

hack/init-e2e-environment.sh

Lines changed: 12 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ set -o errexit
1717
set -o nounset
1818
set -o pipefail
1919

20-
# This script is used to create a blank cluster for karmadactl init e2e testing.
20+
# This script is used in workflow to set up a local karmadactl init e2e testing environment.
2121
# It creates a host cluster and build the relevant images, CRDs, Karmadactl, etc. for the subsequent e2e testing..
2222
# 1. Used by developers to test karmadactl init with custom control plane setup
2323

2424
function usage() {
25-
echo "This script is used to create a blank cluster for karmadactl init e2e testing."
25+
echo "This script is used in workflow to set up a local karmadactl init e2e testing environment."
2626
echo "It creates a host cluster and build the relevant images, CRDs, Karmadactl, etc. for the subsequent e2e testing.."
2727
echo "Used by developers to test karmadactl init with custom control plane setup"
2828
echo "Usage:"
@@ -45,129 +45,24 @@ done
4545

4646
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
4747
source "${REPO_ROOT}"/hack/util.sh
48+
KARMADA_SYSTEM_NAMESPACE="karmada-system"
4849

4950
# variable define
50-
KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
51-
MAIN_KUBECONFIG=${MAIN_KUBECONFIG:-"${KUBECONFIG_PATH}/karmada-init.config"}
52-
HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-init"}
53-
HOST_IPADDRESS=${HOST_IPADDRESS:-}
54-
BUILD_FROM_SOURCE=${BUILD_FROM_SOURCE:-"true"}
55-
EXTRA_IMAGES_LOAD_TO_HOST_CLUSTER=${EXTRA_IMAGES_LOAD_TO_HOST_CLUSTER:-""}
51+
export KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
52+
export MAIN_KUBECONFIG=${MAIN_KUBECONFIG:-"${KUBECONFIG_PATH}/karmada.config"}
53+
export HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"}
5654

57-
CLUSTER_VERSION=${CLUSTER_VERSION:-"${DEFAULT_CLUSTER_VERSION}"}
58-
KIND_LOG_FILE=${KIND_LOG_FILE:-"/tmp/karmada"}
55+
# step1. set up a base development environment
56+
"${REPO_ROOT}"/hack/setup-dev-base.sh
57+
export KUBECONFIG="${MAIN_KUBECONFIG}"
5958

60-
#step0: prepare
61-
# proxy setting in China mainland
62-
if [[ -n ${CHINA_MAINLAND:-} ]]; then
63-
util::set_mirror_registry_for_china_mainland ${REPO_ROOT}
64-
fi
65-
66-
# make sure go exists and the go version is a viable version.
67-
util::cmd_must_exist "go"
68-
util::verify_go_version
69-
70-
# make sure docker exists
71-
util::cmd_must_exist "docker"
72-
73-
# install kind and kubectl
74-
echo -n "Preparing: 'kind' existence check - "
75-
if util::cmd_exist kind; then
76-
echo "passed"
77-
else
78-
echo "not pass"
79-
# Install kind using the version defined in util.sh
80-
util::install_tools "sigs.k8s.io/kind" "${KIND_VERSION}"
81-
fi
82-
83-
BS_ARCH=$(go env GOARCH)
84-
BS_OS=$(go env GOOS)
85-
# check arch and os name before installing
86-
util::install_environment_check "${BS_ARCH}" "${BS_OS}"
87-
echo -n "Preparing: 'kubectl' existence check - "
88-
if util::cmd_exist kubectl; then
89-
echo "passed"
90-
else
91-
echo "not pass"
92-
util::install_kubectl "" "${BS_ARCH}" "${BS_OS}"
93-
fi
94-
95-
#step1. create host cluster
96-
# host IP address: script parameter ahead of WSL2 or macOS IP
97-
if [[ -z "${HOST_IPADDRESS}" ]]; then
98-
if util::is_wsl2; then
99-
util::get_wsl2_ipaddress # adapt for WSL2
100-
HOST_IPADDRESS=${WSL2_HOST_IP_ADDRESS:-}
101-
else
102-
util::get_macos_ipaddress # Adapt for macOS
103-
HOST_IPADDRESS=${MAC_NIC_IPADDRESS:-}
104-
fi
105-
fi
106-
107-
#prepare for kindClusterConfig
108-
TEMP_PATH=$(mktemp -d)
109-
trap '{ rm -rf ${TEMP_PATH}; }' EXIT
110-
echo -e "Preparing kindClusterConfig in path: ${TEMP_PATH}"
111-
112-
util::delete_necessary_resources "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "${KIND_LOG_FILE}"
113-
114-
if [[ -n "${HOST_IPADDRESS}" ]]; then # If bind the port of clusters(karmada-host) to the host IP
115-
util::verify_ip_address "${HOST_IPADDRESS}"
116-
cp -rf "${REPO_ROOT}"/artifacts/kindClusterConfig/karmada-host.yaml "${TEMP_PATH}"/karmada-host.yaml
117-
sed -i'' -e "s/{{host_ipaddress}}/${HOST_IPADDRESS}/g" "${TEMP_PATH}"/karmada-host.yaml
118-
util::create_cluster "${HOST_CLUSTER_NAME}" "${MAIN_KUBECONFIG}" "${CLUSTER_VERSION}" "${KIND_LOG_FILE}" "${TEMP_PATH}"/karmada-host.yaml
119-
else
120-
util::create_cluster "${HOST_CLUSTER_NAME}" "${MAIN_KUBECONFIG}" "${CLUSTER_VERSION}" "${KIND_LOG_FILE}"
121-
fi
122-
123-
#step2. make images and get karmadactl
124-
export VERSION=${VERSION:-"latest"}
125-
export REGISTRY=${REGISTRY:-"docker.io/karmada"}
126-
if [[ "${BUILD_FROM_SOURCE}" == "true" ]]; then
127-
export KARMADA_IMAGE_LABEL_VALUE="May_be_pruned_in_local_up_environment"
128-
export DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS:-} --label=image.karmada.io=${KARMADA_IMAGE_LABEL_VALUE}"
129-
make images GOOS="linux" --directory="${REPO_ROOT}"
130-
#clean up dangling images
131-
docker image prune --force --filter "label=image.karmada.io=${KARMADA_IMAGE_LABEL_VALUE}"
132-
fi
133-
GO111MODULE=on go install "github.com/karmada-io/karmada/cmd/karmadactl"
134-
135-
#step3. wait until clusters ready
136-
echo "Waiting for the clusters to be ready..."
137-
util::check_clusters_ready "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}"
138-
139-
140-
#step4. load components images to kind cluster
141-
if [[ "${BUILD_FROM_SOURCE}" == "true" ]]; then
142-
# host cluster
143-
kind load docker-image "${REGISTRY}/karmada-controller-manager:${VERSION}" --name="${HOST_CLUSTER_NAME}"
144-
kind load docker-image "${REGISTRY}/karmada-scheduler:${VERSION}" --name="${HOST_CLUSTER_NAME}"
145-
kind load docker-image "${REGISTRY}/karmada-descheduler:${VERSION}" --name="${HOST_CLUSTER_NAME}"
146-
kind load docker-image "${REGISTRY}/karmada-webhook:${VERSION}" --name="${HOST_CLUSTER_NAME}"
147-
kind load docker-image "${REGISTRY}/karmada-scheduler-estimator:${VERSION}" --name="${HOST_CLUSTER_NAME}"
148-
kind load docker-image "${REGISTRY}/karmada-aggregated-apiserver:${VERSION}" --name="${HOST_CLUSTER_NAME}"
149-
kind load docker-image "${REGISTRY}/karmada-search:${VERSION}" --name="${HOST_CLUSTER_NAME}"
150-
kind load docker-image "${REGISTRY}/karmada-metrics-adapter:${VERSION}" --name="${HOST_CLUSTER_NAME}"
151-
for img in ${EXTRA_IMAGES_LOAD_TO_HOST_CLUSTER//,/ }; do
152-
kind load docker-image "$img" --name="${HOST_CLUSTER_NAME}"
153-
done
154-
fi
155-
156-
# step5: prepare and copy the newest crds for karmadactl init
157-
# step5.1: prepare the newest crds for karmadactl init
158-
echo "Prepare the newest crds for karmadactl init"
159-
cd charts/karmada/
59+
# step2 prepare the local crds
60+
echo "Prepare the local crds"
61+
cd ${REPO_ROOT}/charts/karmada/
16062
cp -r _crds crds
16163
tar -zcvf ../../crds.tar.gz crds
16264
cd -
16365

164-
# step5.2: Verify CRDs package is created successfully
165-
if [ ! -f "./crds.tar.gz" ]; then
166-
echo "ERROR: Failed to create CRDs package at ./crds.tar.gz"
167-
exit 1
168-
fi
169-
echo "CRDs package created successfully: ./crds.tar.gz"
170-
17166
# step5.3: Copy the local crds.tar.gz file to the specified path
17267
DATA_DIR="${HOME}/karmada-data"
17368
mkdir -p "${DATA_DIR}"

hack/run-e2e-init.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# Copyright 2020 The Karmada Authors.
2+
# Copyright 2025 The Karmada Authors.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -19,24 +19,22 @@ set -o pipefail
1919

2020
# This script runs init e2e test against a blank cluster to test karmadactl init functionality.
2121
# You should prepare your environment in advance and following environment may be you need to set or use default one.
22-
# - HOST_CLUSTER_KUBECONFIG: absolute path of host cluster KUBECONFIG file.
22+
# - HOST_KUBECONFIG: absolute path of host cluster KUBECONFIG file.
2323
#
2424
# Usage: hack/run-e2e-init.sh
2525
# Example 1: hack/run-e2e-init.sh (run init e2e with default config)
26-
# Example 2: export HOST_CLUSTER_KUBECONFIG=<KUBECONFIG PATH> hack/run-e2e-init.sh (run init e2e with your KUBECONFIG)
27-
26+
# Example 2: export HOST_KUBECONFIG=<KUBECONFIG PATH> hack/run-e2e-init.sh (run init e2e with your KUBECONFIG)
2827

2928
KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
30-
HOST_CLUSTER_KUBECONFIG=${HOST_CLUSTER_KUBECONFIG:-"$KUBECONFIG_PATH/karmada-init.config"}
29+
HOST_KUBECONFIG=${HOST_KUBECONFIG:-"$KUBECONFIG_PATH/karmada.config"}
3130
DATA_DIR=${DATA_DIR:-"${HOME}/karmada-data"}
3231

33-
3432
# KARMADA_RUNNING_ON_KIND indicates if current testing against on karmada that installed on a kind cluster.
3533
# Defaults to true.
3634
# For kind cluster, the kind related logs will be collected after the testing.
3735
KARMADA_RUNNING_ON_KIND=${KARMADA_RUNNING_ON_KIND:-true}
3836

39-
KARMADA_HOST_CLUSTER_NAME=${KARMADA_HOST_CLUSTER_NAME:-"karmada-init"}
37+
HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"}
4038

4139
ARTIFACTS_PATH=${ARTIFACTS_PATH:-"${HOME}/karmada-e2e-init-logs"}
4240
mkdir -p "$ARTIFACTS_PATH"
@@ -45,20 +43,25 @@ mkdir -p "$ARTIFACTS_PATH"
4543
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
4644

4745
# Run init e2e
48-
export KUBECONFIG=${HOST_CLUSTER_KUBECONFIG}
46+
export KUBECONFIG=${HOST_KUBECONFIG}
47+
export PUSH_MODE_CLUSTER_NAME=${MEMBER_CLUSTER_1_NAME:-"member1"}
48+
export PUSH_MODE_KUBECONFIG_PATH=${PUSH_MODE_KUBECONFIG_PATH:-"$KUBECONFIG_PATH/members.config"}
49+
export PULL_MODE_CLUSTER_NAME=${PULL_MODE_CLUSTER_NAME:-"member3"}
50+
export PULL_MODE_KUBECONFIG_PATH=${PULL_MODE_KUBECONFIG_PATH:-"$KUBECONFIG_PATH/members.config"}
4951
export CRDs_PATH=${CRDs_PATH:-"${DATA_DIR}/crds.tar.gz"}
52+
5053
set +e
51-
ginkgo -v --race --trace --fail-fast -p --randomize-all ./test/e2e/suites/init -- --host-context=${KARMADA_HOST_CLUSTER_NAME}
54+
ginkgo -v --race --trace --fail-fast -p --randomize-all ./test/e2e/suites/init -- --host-context=${HOST_CLUSTER_NAME}
5255
TESTING_RESULT=$?
5356

5457
# Collect logs
5558
echo "Collect logs to $ARTIFACTS_PATH..."
56-
cp "$HOST_CLUSTER_KUBECONFIG" "$ARTIFACTS_PATH"
59+
cp "$HOST_KUBECONFIG" "$ARTIFACTS_PATH"
5760

5861
if [ "$KARMADA_RUNNING_ON_KIND" = true ]; then
59-
echo "Collecting $KARMADA_HOST_CLUSTER_NAME logs..."
60-
mkdir -p "$ARTIFACTS_PATH/$KARMADA_HOST_CLUSTER_NAME"
61-
kind export logs --name="$KARMADA_HOST_CLUSTER_NAME" "$ARTIFACTS_PATH/$KARMADA_HOST_CLUSTER_NAME"
62+
echo "Collecting $HOST_CLUSTER_NAME logs..."
63+
mkdir -p "$ARTIFACTS_PATH/$HOST_CLUSTER_NAME"
64+
kind export logs --name="$HOST_CLUSTER_NAME" "$ARTIFACTS_PATH/$HOST_CLUSTER_NAME"
6265
fi
6366

6467
echo "Collected logs at $ARTIFACTS_PATH:"

test/e2e/suites/init/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Init E2E Test Suite
2+
3+
This directory contains end-to-end (E2E) tests for the functionality of `karmadactl init`. These tests ensure that the
4+
initialization process of Karmada clusters works as expected.
5+
6+
It contains two categories of tests:
7+
- Basic Tests: These tests create a simple Karmada control plane and make a propagation test to verify that the initialization
8+
process is functioning correctly.
9+
path: test/e2e/suites/init/base_test.go
10+
- Custom Tests: These tests create a Karmada control plane with custom configurations to validate that the custom
11+
initialization settings are applied correctly.
12+
13+
## Guide for Writing Tests
14+
15+
1. **Namespace Isolation**: Use the variable `testNamespace` to isolate the Karmada instance.
16+
17+
2. **Path Isolation**: Use the variable `karmadaDataPath` to isolate the data directory of the Karmada instance. When running the `init` command, specify the data paths using the following flags:
18+
```go
19+
"--karmada-data", karmadaDataPath,
20+
"--karmada-pki", filepath.Join(karmadaDataPath, "pki"),
21+
"--etcd-data", filepath.Join(karmadaDataPath, "etcd-data"),
22+
```
23+
24+
3. **Port Isolation**: Use the variable `karmadaAPIServerNodePort` to isolate the API server port. When running the `init` command, specify the port using the following flag:
25+
```go
26+
"--port", karmadaAPIServerNodePort,
27+
```

0 commit comments

Comments
 (0)