Skip to content

Commit d066251

Browse files
committed
add cmdinit e2e test for initing karmada control plane with config file
Signed-off-by: rayo1uo <[email protected]>
1 parent b175217 commit d066251

File tree

4 files changed

+144
-222
lines changed

4 files changed

+144
-222
lines changed

.github/workflows/installation-cli.yaml

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,47 +71,3 @@ jobs:
7171
with:
7272
name: karmada_init_kind_log_${{ matrix.k8s }}
7373
path: /tmp/karmada/
74-
75-
init-config:
76-
name: init with config file
77-
runs-on: ubuntu-22.04
78-
strategy:
79-
fail-fast: false
80-
matrix:
81-
# Latest three minor releases of Kubernetes
82-
k8s: [ v1.32.0, v1.33.0, v1.34.0 ]
83-
steps:
84-
- name: checkout code
85-
uses: actions/checkout@v6
86-
with:
87-
fetch-depth: 0
88-
- name: install Go
89-
uses: actions/setup-go@v6
90-
with:
91-
go-version-file: go.mod
92-
- name: run karmadactl init with config file test
93-
run: |
94-
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
95-
96-
# Run custom test for workload configuration deployment
97-
hack/cli-testing-init-with-config.sh
98-
99-
# run a single e2e
100-
export PULL_BASED_CLUSTERS="config-member1:${HOME}/.kube/config-member1.config"
101-
export KUBECONFIG=${HOME}/.kube/karmada-host.config:${HOME}/karmada/karmada-apiserver.config
102-
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
103-
ginkgo -v --race --trace -p --focus="[BasicPropagation] propagation testing deployment propagation testing" ./test/e2e/suites/base
104-
- name: export logs for config test
105-
if: always()
106-
run: |
107-
export ARTIFACTS_PATH=${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/config
108-
mkdir -p $ARTIFACTS_PATH
109-
110-
mkdir -p $ARTIFACTS_PATH/karmada-host
111-
kind export logs --name=karmada-host $ARTIFACTS_PATH/karmada-host
112-
- name: upload config test logs
113-
if: always()
114-
uses: actions/upload-artifact@v6
115-
with:
116-
name: karmadactl_config_test_logs_${{ matrix.k8s }}
117-
path: ${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/config/

hack/cli-testing-init-with-config.sh

Lines changed: 0 additions & 169 deletions
This file was deleted.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
Copyright 2026 The Karmada Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package init
18+
19+
import (
20+
"fmt"
21+
"os"
22+
"path/filepath"
23+
"time"
24+
25+
"github.com/onsi/ginkgo/v2"
26+
"github.com/onsi/gomega"
27+
28+
"github.com/karmada-io/karmada/test/e2e/framework"
29+
"github.com/karmada-io/karmada/test/e2e/framework/resource/cmdinit"
30+
)
31+
32+
const configTemplate = `apiVersion: config.karmada.io/v1alpha1
33+
kind: KarmadaInitConfig
34+
spec:
35+
hostCluster:
36+
kubeconfig: "${KUBECONFIG_PATH}"
37+
etcd:
38+
local:
39+
dataPath: "${ETCD_DATA_PATH}"
40+
components:
41+
karmadaControllerManager:
42+
repository: "${REGISTRY}/karmada-controller-manager"
43+
tag: "${VERSION}"
44+
karmadaScheduler:
45+
repository: "${REGISTRY}/karmada-scheduler"
46+
tag: "${VERSION}"
47+
karmadaWebhook:
48+
repository: "${REGISTRY}/karmada-webhook"
49+
tag: "${VERSION}"
50+
karmadaAggregatedAPIServer:
51+
repository: "${REGISTRY}/karmada-aggregated-apiserver"
52+
tag: "${VERSION}"
53+
karmadaAPIServer:
54+
networking:
55+
port: ${KARMADA_APISERVER_NODE_PORT}
56+
karmadaDataPath: "${KARMADA_DATA_PATH}"
57+
karmadaPkiPath: "${KARMADA_PKI_PATH}"
58+
karmadaCrds: "${KARMADA_CRDS}"`
59+
60+
// config variable value should be consistent with template placeholder name
61+
const (
62+
configVarKubeconfigPath = "KUBECONFIG_PATH"
63+
configVarRegistry = "REGISTRY"
64+
configVarVersion = "VERSION"
65+
configVarKarmadaDataPath = "KARMADA_DATA_PATH"
66+
configVarKarmadaPkiPath = "KARMADA_PKI_PATH"
67+
configVarKarmadaCrds = "KARMADA_CRDS"
68+
configVarEtcdDataPath = "ETCD_DATA_PATH"
69+
configVarKarmadaAPIServerNodePort = "KARMADA_APISERVER_NODE_PORT"
70+
)
71+
72+
const karmadactlInitTimeout = time.Second * 120
73+
74+
var _ = ginkgo.Describe("Custom E2E: initialize karmada control plane with config file", func() {
75+
var tempPki string
76+
var etcdDataPath string
77+
78+
var configFilePath string
79+
var configVariables map[string]any
80+
81+
ginkgo.Context("Karmadactl init with config file testing", func() {
82+
ginkgo.BeforeEach(func() {
83+
tempPki = filepath.Join(karmadaDataPath, "pki")
84+
etcdDataPath = filepath.Join(karmadaDataPath, "etcd-data")
85+
86+
configFilePath = filepath.Join(karmadaDataPath, "karmada-config.yaml")
87+
})
88+
89+
ginkgo.It("Deploy karmada control plane with config file", func() {
90+
ginkgo.By("Generate karmada init config file with template", func() {
91+
configVariables = map[string]any{
92+
configVarKubeconfigPath: kubeconfig,
93+
configVarRegistry: registry,
94+
configVarVersion: version,
95+
configVarKarmadaDataPath: karmadaDataPath,
96+
configVarKarmadaPkiPath: tempPki,
97+
configVarKarmadaCrds: crdsPath,
98+
configVarEtcdDataPath: etcdDataPath,
99+
configVarKarmadaAPIServerNodePort: karmadaAPIServerNodePort,
100+
}
101+
102+
renderedContent := renderTemplateWithGenericMap(configTemplate, configVariables)
103+
err := os.WriteFile(configFilePath, []byte(renderedContent), 0600)
104+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
105+
})
106+
107+
ginkgo.By("Execute the command karmadactl init", func() {
108+
args := []string{"init",
109+
"--config", configFilePath,
110+
"--v", "4",
111+
}
112+
113+
cmd := framework.NewKarmadactlCommand(
114+
"", // kubeconfig is not specified as it will use the kubeconfig specified in karmada config file
115+
"",
116+
karmadactlPath,
117+
testNamespace,
118+
karmadactlInitTimeout,
119+
args...,
120+
)
121+
_, err := cmd.ExecOrDie()
122+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
123+
})
124+
125+
ginkgo.By("Waiting for components to be ready", func() {
126+
cmdinit.WaitAllKarmadaComponentReady(hostClient, testNamespace)
127+
})
128+
})
129+
})
130+
})
131+
132+
func renderTemplateWithGenericMap(templateContent string, variables map[string]any) string {
133+
mapper := func(placeholderName string) string {
134+
val, ok := variables[placeholderName]
135+
if !ok {
136+
return ""
137+
}
138+
return fmt.Sprintf("%v", val)
139+
}
140+
141+
return os.Expand(templateContent, mapper)
142+
}

test/e2e/suites/init/suite_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,10 @@ var _ = ginkgo.SynchronizedAfterSuite(func() {
154154
func setupTestNamespace(namespace string, kubeClient kubernetes.Interface) error {
155155
namespaceObj := helper.NewNamespace(namespace)
156156
_, err := util.CreateNamespace(kubeClient, namespaceObj)
157-
if err != nil {
158-
return err
159-
}
160-
return nil
157+
return err
161158
}
162159

163160
// cleanupTestNamespace will remove the namespace we setup before for the whole testing.
164161
func cleanupTestNamespace(namespace string, kubeClient kubernetes.Interface) error {
165-
err := util.DeleteNamespace(kubeClient, namespace)
166-
if err != nil {
167-
return err
168-
}
169-
return nil
162+
return util.DeleteNamespace(kubeClient, namespace)
170163
}

0 commit comments

Comments
 (0)