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

Operator e2e init #4148

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
63 changes: 63 additions & 0 deletions .github/workflows/operator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI Workflow operator
on:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
build:
name: compile
runs-on: ubuntu-22.04
steps:
- name: checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.6
- name: compile
run: make all
e2e:
name: e2e test
needs: build
runs-on: ubuntu-22.04
strategy:
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.27.3 ]
steps:
- name: checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.6
- name: setup e2e test environment
run: |
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
hack/operator-testing-environment.sh
- name: run e2e
env:
GINKGO_PARAM: ${{ matrix.test }}
run: |
export KUBECONFIG=${HOME}/karmada/karmada-host.config
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo -v --race --trace -p ./test/e2e_operator/
- name: upload logs
if: always()
uses: actions/upload-artifact@v3
with:
name: karmada_e2e_log_${{ matrix.k8s }}
path: ${{ github.workspace }}/karmada-e2e-logs/${{ matrix.k8s }}/
- name: upload kind logs
if: always()
uses: actions/upload-artifact@v3
with:
name: karmada_kind_log_${{ matrix.k8s }}
path: /tmp/karmada/
51 changes: 51 additions & 0 deletions hack/operator-testing-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail

# This script starts a local karmada control plane with karmadactl and with a certain number of clusters joined.
# This script depends on utils in: ${REPO_ROOT}/hack/util.sh
# 1. used by developer to setup develop environment quickly.
# 2. used by e2e testing to setup test environment automatically.

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

# variable define
KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"}
HOST_CLUSTER_NAME=${HOST_CLUSTER_NAME:-"karmada-host"}
CLUSTER_VERSION=${CLUSTER_VERSION:-"kindest/node:v1.27.3"}
BUILD_PATH=${BUILD_PATH:-"_output/bin/linux/amd64"}

# prepare the newest crds
# echo "Prepare the newest crds"
# cd charts/karmada/
# cp -r _crds crds
# tar -zcvf ../../crds.tar.gz crds
# cd -

# build karmada operator
make image-karmada-operator

# create host/member1/member2 cluster
echo "Start create clusters..."
hack/create-cluster.sh ${HOST_CLUSTER_NAME} ${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config

# wait cluster ready
echo "Wait clusters ready..."
util::wait_file_exist ${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config 300
util::wait_context_exist ${HOST_CLUSTER_NAME} ${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config 300
kubectl wait --for=condition=Ready nodes --all --timeout=800s --kubeconfig=${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config
util::wait_nodes_taint_disappear 800 ${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config

kind get clusters
IMGTAG=`git describe --tags --dirty`
kubectl apply -f operator/config/crds --kubeconfig=${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config
docker tag docker.io/karmada/karmada-operator:$IMGTAG docker.io/karmada/karmada-operator:latest
kind load docker-image docker.io/karmada/karmada-operator:latest --name $HOST_CLUSTER_NAME

kubectl create namespace karmada-system --kubeconfig=${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config
kubectl create namespace test --kubeconfig=${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config
kubectl apply -f operator/config/deploy --kubeconfig=${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config
# test for samples yamls
kubectl apply -f operator/config/samples --kubeconfig=${KUBECONFIG_PATH}/${HOST_CLUSTER_NAME}.config
57 changes: 57 additions & 0 deletions test/e2e_operator/operator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package e2e_operator

import (
"context"
"fmt"
"os"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/client-go/kubernetes"

operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
operator "github.com/karmada-io/karmada/operator/pkg/generated/clientset/versioned"
"github.com/karmada-io/karmada/test/e2e/framework"
"github.com/karmada-io/karmada/test/helper"
)

var _ = ginkgo.Describe("operator testing", func() {
homeDir := os.Getenv("HOME")
kubeConfigPath := fmt.Sprintf("%s/.kube/%s.config", homeDir, "karmada-host")
restConfig, err := framework.LoadRESTClientConfig(kubeConfigPath, "karmada-host")
gomega.Expect(err).ToNot(gomega.HaveOccurred())
kubeClient, err := kubernetes.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
operatorClient, _ := operator.NewForConfig(restConfig)

ginkgo.BeforeEach(func() {
})

ginkgo.Context("[operator]Test namespaced resource: deployment", func() {
var deploymentNamespace, deploymentName string

ginkgo.BeforeEach(func() {
deploymentNamespace = fmt.Sprintf("karmadatest-%s", rand.String(RandomStrLength))
deploymentName = "test" + rand.String(RandomStrLength)
})

ginkgo.AfterEach(func() {
framework.RemoveNamespace(kubeClient, deploymentNamespace)
})

ginkgo.It("[operator]test", func() {

ginkgo.By(fmt.Sprintf("Creating karmada %s with namespace %s ", deploymentName, deploymentNamespace), func() {
deploymentNamespaceObj := helper.NewNamespace(deploymentNamespace)
framework.CreateNamespace(kubeClient, deploymentNamespaceObj)
karmada := &operatorv1alpha1.Karmada{}
_, err := operatorClient.OperatorV1alpha1().Karmadas("default").Create(context.TODO(), karmada, v1.CreateOptions{})
gomega.Expect(err).To(gomega.HaveOccurred())
})
})

})

})
20 changes: 20 additions & 0 deletions test/e2e_operator/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package e2e_operator

import (
"testing"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)

const (
RandomStrLength = 5
)

func init() {
}

func TestE2E(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "E2E Suite")
}