Skip to content
Open
Show file tree
Hide file tree
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
58 changes: 0 additions & 58 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,61 +162,3 @@ jobs:
with:
name: karmada_kind_log_${{ matrix.k8s }}
path: /tmp/karmada/

e2e-init:
name: init e2e test
needs: build
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
# Here support the latest three minor releases of Kubernetes, this can be considered to be roughly
# the same as the End of Life of the Kubernetes release: https://kubernetes.io/releases/
# Please remember to update the CI Schedule Workflow when we add a new version.
k8s: [ v1.31.0, v1.32.0, v1.33.0 ]
steps:
# Free up disk space on Ubuntu
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed, if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: false
swap-storage: false
- name: checkout code
uses: actions/checkout@v5
with:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# We need to guess version via git tags.
fetch-depth: 0
- name: install Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: setup init e2e test environment
run: |
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
hack/init-e2e-environment.sh
- name: run e2e
run: |
export ARTIFACTS_PATH=${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
export REGISTRY="docker.io/karmada"
export VERSION="latest"
hack/run-e2e-init.sh
- name: upload logs
if: always()
uses: actions/upload-artifact@v5
with:
name: karmada_init_e2e_log_${{ matrix.k8s }}
path: ${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
- name: upload kind logs
if: always()
uses: actions/upload-artifact@v5
with:
name: karmada_init_kind_log_${{ matrix.k8s }}
path: /tmp/karmada/
47 changes: 28 additions & 19 deletions .github/workflows/installation-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ jobs:
# Please remember to update the CI Schedule Workflow when we add a new version.
k8s: [ v1.31.0, v1.32.0, v1.33.0 ]
steps:
# Free up disk space on Ubuntu
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed, if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: false
swap-storage: false
- name: checkout code
uses: actions/checkout@v5
with:
Expand All @@ -36,32 +49,28 @@ jobs:
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: run karmadactl init test
- name: setup init e2e test environment
run: |
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}

# init e2e environment
hack/cli-testing-environment.sh

# run a single e2e
export PULL_BASED_CLUSTERS="member1:${HOME}/.kube/member1.config"
export KUBECONFIG=${HOME}/.kube/karmada-host.config:${HOME}/karmada/karmada-apiserver.config
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo -v --race --trace -p --focus="[BasicPropagation] propagation testing deployment propagation testing" ./test/e2e/suites/base
- name: export logs
if: always()
hack/init-e2e-environment.sh
- name: run e2e
run: |
export ARTIFACTS_PATH=${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/
mkdir -p $ARTIFACTS_PATH

mkdir -p $ARTIFACTS_PATH/karmada-host
kind export logs --name=karmada-host $ARTIFACTS_PATH/karmada-host
export ARTIFACTS_PATH=${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
export REGISTRY="docker.io/karmada"
export VERSION="latest"
hack/run-e2e-init.sh
- name: upload logs
if: always()
uses: actions/upload-artifact@v5
with:
name: karmadactl_test_logs_${{ matrix.k8s }}
path: ${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/
name: karmada_init_e2e_log_${{ matrix.k8s }}
path: ${{ github.workspace }}/karmada-init-e2e-logs/${{ matrix.k8s }}/
- name: upload kind logs
if: always()
uses: actions/upload-artifact@v5
with:
name: karmada_init_kind_log_${{ matrix.k8s }}
path: /tmp/karmada/

init-config:
name: init with config file
Expand Down
135 changes: 15 additions & 120 deletions hack/init-e2e-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ set -o errexit
set -o nounset
set -o pipefail

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

function usage() {
echo "This script is used to create a blank cluster for karmadactl init e2e testing."
echo "It creates a host cluster and build the relevant images, CRDs, Karmadactl, etc. for the subsequent e2e testing.."
echo "This script is used in workflow to set up a local karmadactl init e2e testing environment."
echo "It creates a host cluster, three member cluster and build the relevant images, CRDs, Karmadactl, etc. for the subsequent e2e testing."
echo "Used by developers to test karmadactl init with custom control plane setup"
echo "Usage:"
echo " hack/init-e2e-environment.sh [-h]"
Expand All @@ -45,130 +45,25 @@ done

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

# variable define
KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
MAIN_KUBECONFIG=${MAIN_KUBECONFIG:-"${KUBECONFIG_PATH}/karmada-init.config"}
HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-init"}
HOST_IPADDRESS=${HOST_IPADDRESS:-}
BUILD_FROM_SOURCE=${BUILD_FROM_SOURCE:-"true"}
EXTRA_IMAGES_LOAD_TO_HOST_CLUSTER=${EXTRA_IMAGES_LOAD_TO_HOST_CLUSTER:-""}
export KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
export MAIN_KUBECONFIG=${MAIN_KUBECONFIG:-"${KUBECONFIG_PATH}/karmada.config"}
export HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"}

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

#step0: prepare
# proxy setting in China mainland
if [[ -n ${CHINA_MAINLAND:-} ]]; then
util::set_mirror_registry_for_china_mainland ${REPO_ROOT}
fi

# make sure go exists and the go version is a viable version.
util::cmd_must_exist "go"
util::verify_go_version

# make sure docker exists
util::cmd_must_exist "docker"

# install kind and kubectl
echo -n "Preparing: 'kind' existence check - "
if util::cmd_exist kind; then
echo "passed"
else
echo "not pass"
# Install kind using the version defined in util.sh
util::install_tools "sigs.k8s.io/kind" "${KIND_VERSION}"
fi

BS_ARCH=$(go env GOARCH)
BS_OS=$(go env GOOS)
# check arch and os name before installing
util::install_environment_check "${BS_ARCH}" "${BS_OS}"
echo -n "Preparing: 'kubectl' existence check - "
if util::cmd_exist kubectl; then
echo "passed"
else
echo "not pass"
util::install_kubectl "" "${BS_ARCH}" "${BS_OS}"
fi

#step1. create host cluster
# host IP address: script parameter ahead of WSL2 or macOS IP
if [[ -z "${HOST_IPADDRESS}" ]]; then
if util::is_wsl2; then
util::get_wsl2_ipaddress # adapt for WSL2
HOST_IPADDRESS=${WSL2_HOST_IP_ADDRESS:-}
else
util::get_macos_ipaddress # Adapt for macOS
HOST_IPADDRESS=${MAC_NIC_IPADDRESS:-}
fi
fi

#prepare for kindClusterConfig
TEMP_PATH=$(mktemp -d)
trap '{ rm -rf ${TEMP_PATH}; }' EXIT
echo -e "Preparing kindClusterConfig in path: ${TEMP_PATH}"

util::delete_necessary_resources "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "${KIND_LOG_FILE}"

if [[ -n "${HOST_IPADDRESS}" ]]; then # If bind the port of clusters(karmada-host) to the host IP
util::verify_ip_address "${HOST_IPADDRESS}"
cp -rf "${REPO_ROOT}"/artifacts/kindClusterConfig/karmada-host.yaml "${TEMP_PATH}"/karmada-host.yaml
sed -i'' -e "s/{{host_ipaddress}}/${HOST_IPADDRESS}/g" "${TEMP_PATH}"/karmada-host.yaml
util::create_cluster "${HOST_CLUSTER_NAME}" "${MAIN_KUBECONFIG}" "${CLUSTER_VERSION}" "${KIND_LOG_FILE}" "${TEMP_PATH}"/karmada-host.yaml
else
util::create_cluster "${HOST_CLUSTER_NAME}" "${MAIN_KUBECONFIG}" "${CLUSTER_VERSION}" "${KIND_LOG_FILE}"
fi

#step2. make images and get karmadactl
export VERSION=${VERSION:-"latest"}
export REGISTRY=${REGISTRY:-"docker.io/karmada"}
if [[ "${BUILD_FROM_SOURCE}" == "true" ]]; then
export KARMADA_IMAGE_LABEL_VALUE="May_be_pruned_in_local_up_environment"
export DOCKER_BUILD_ARGS="${DOCKER_BUILD_ARGS:-} --label=image.karmada.io=${KARMADA_IMAGE_LABEL_VALUE}"
make images GOOS="linux" --directory="${REPO_ROOT}"
#clean up dangling images
docker image prune --force --filter "label=image.karmada.io=${KARMADA_IMAGE_LABEL_VALUE}"
fi
GO111MODULE=on go install "github.com/karmada-io/karmada/cmd/karmadactl"

#step3. wait until clusters ready
echo "Waiting for the clusters to be ready..."
util::check_clusters_ready "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}"


#step4. load components images to kind cluster
if [[ "${BUILD_FROM_SOURCE}" == "true" ]]; then
# host cluster
kind load docker-image "${REGISTRY}/karmada-controller-manager:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-scheduler:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-descheduler:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-webhook:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-scheduler-estimator:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-aggregated-apiserver:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-search:${VERSION}" --name="${HOST_CLUSTER_NAME}"
kind load docker-image "${REGISTRY}/karmada-metrics-adapter:${VERSION}" --name="${HOST_CLUSTER_NAME}"
for img in ${EXTRA_IMAGES_LOAD_TO_HOST_CLUSTER//,/ }; do
kind load docker-image "$img" --name="${HOST_CLUSTER_NAME}"
done
fi

# step5: prepare and copy the newest crds for karmadactl init
# step5.1: prepare the newest crds for karmadactl init
echo "Prepare the newest crds for karmadactl init"
cd charts/karmada/
# step2 prepare the local crds
echo "Prepare the local crds"
cd ${REPO_ROOT}/charts/karmada/
cp -r _crds crds
tar -zcvf ../../crds.tar.gz crds
cd -

# step5.2: Verify CRDs package is created successfully
if [ ! -f "./crds.tar.gz" ]; then
echo "ERROR: Failed to create CRDs package at ./crds.tar.gz"
exit 1
fi
echo "CRDs package created successfully: ./crds.tar.gz"

# step5.3: Copy the local crds.tar.gz file to the specified path
# step2.1: Copy the local crds.tar.gz file to the specified path
DATA_DIR="${HOME}/karmada-data"
mkdir -p "${DATA_DIR}"
cp ./crds.tar.gz "${DATA_DIR}/crds.tar.gz"
Expand Down
29 changes: 16 additions & 13 deletions hack/run-e2e-init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright 2020 The Karmada Authors.
# Copyright 2025 The Karmada Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,24 +19,22 @@ set -o pipefail

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

# Example 2: export HOST_KUBECONFIG=<KUBECONFIG PATH> hack/run-e2e-init.sh (run init e2e with your KUBECONFIG)

KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
HOST_CLUSTER_KUBECONFIG=${HOST_CLUSTER_KUBECONFIG:-"$KUBECONFIG_PATH/karmada-init.config"}
HOST_KUBECONFIG=${HOST_KUBECONFIG:-"$KUBECONFIG_PATH/karmada.config"}
DATA_DIR=${DATA_DIR:-"${HOME}/karmada-data"}


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

KARMADA_HOST_CLUSTER_NAME=${KARMADA_HOST_CLUSTER_NAME:-"karmada-init"}
HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"}

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

# Run init e2e
export KUBECONFIG=${HOST_CLUSTER_KUBECONFIG}
export KUBECONFIG=${HOST_KUBECONFIG}
export PUSH_MODE_CLUSTER_NAME=${MEMBER_CLUSTER_1_NAME:-"member1"}
export PUSH_MODE_KUBECONFIG_PATH=${PUSH_MODE_KUBECONFIG_PATH:-"$KUBECONFIG_PATH/members.config"}
export PULL_MODE_CLUSTER_NAME=${PULL_MODE_CLUSTER_NAME:-"member3"}
export PULL_MODE_KUBECONFIG_PATH=${PULL_MODE_KUBECONFIG_PATH:-"$KUBECONFIG_PATH/members.config"}
export CRDs_PATH=${CRDs_PATH:-"${DATA_DIR}/crds.tar.gz"}

set +e
ginkgo -v --race --trace --fail-fast -p --randomize-all ./test/e2e/suites/init -- --host-context=${KARMADA_HOST_CLUSTER_NAME}
ginkgo -v --race --trace --fail-fast -p --randomize-all ./test/e2e/suites/init -- --host-context=${HOST_CLUSTER_NAME}
TESTING_RESULT=$?

# Collect logs
echo "Collect logs to $ARTIFACTS_PATH..."
cp "$HOST_CLUSTER_KUBECONFIG" "$ARTIFACTS_PATH"
cp "$HOST_KUBECONFIG" "$ARTIFACTS_PATH"

if [ "$KARMADA_RUNNING_ON_KIND" = true ]; then
echo "Collecting $KARMADA_HOST_CLUSTER_NAME logs..."
mkdir -p "$ARTIFACTS_PATH/$KARMADA_HOST_CLUSTER_NAME"
kind export logs --name="$KARMADA_HOST_CLUSTER_NAME" "$ARTIFACTS_PATH/$KARMADA_HOST_CLUSTER_NAME"
echo "Collecting $HOST_CLUSTER_NAME logs..."
mkdir -p "$ARTIFACTS_PATH/$HOST_CLUSTER_NAME"
kind export logs --name="$HOST_CLUSTER_NAME" "$ARTIFACTS_PATH/$HOST_CLUSTER_NAME"
fi

echo "Collected logs at $ARTIFACTS_PATH:"
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/suites/init/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Init E2E Test Suite

This directory contains end-to-end (E2E) tests for the functionality of `karmadactl init`. These tests ensure that the
initialization process of Karmada clusters works as expected.

It contains two categories of tests:
- Basic Tests: These tests create a simple Karmada control plane and make a propagation test to verify that the initialization
process is functioning correctly.
path: test/e2e/suites/init/base_test.go
- Custom Tests: These tests create a Karmada control plane with custom configurations to validate that the custom
initialization settings are applied correctly.

## Guide for Writing Tests

1. **Namespace Isolation**: Use the variable `testNamespace` to isolate the Karmada instance.

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:
```go
"--karmada-data", karmadaDataPath,
"--karmada-pki", filepath.Join(karmadaDataPath, "pki"),
"--etcd-data", filepath.Join(karmadaDataPath, "etcd-data"),
```

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:
```go
"--port", karmadaAPIServerNodePort,
```
Loading