Skip to content

Commit d029879

Browse files
committed
init e2e: add e2e tests of command addons and command deinit
Signed-off-by: zhzhuang-zju <[email protected]>
1 parent 050353e commit d029879

File tree

3 files changed

+136
-17
lines changed

3 files changed

+136
-17
lines changed

test/e2e/framework/deployment.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,20 @@ func WaitDeploymentReplicasFitWith(clusters []string, namespace, name string, ex
304304
}, PollTimeout, PollInterval).Should(gomega.Equal(true))
305305
})
306306
}
307+
308+
// WaitDeploymentDisappear waits for a deployment to be removed from a namespace until timeout.
309+
func WaitDeploymentDisappear(client kubernetes.Interface, namespace, name string) {
310+
klog.Infof("Waiting for deployment(%s/%s) disappears", namespace, name)
311+
gomega.Eventually(func() bool {
312+
_, err := client.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{})
313+
if err == nil {
314+
return false
315+
}
316+
if apierrors.IsNotFound(err) {
317+
return true
318+
}
319+
320+
klog.Errorf("Failed to get deployment(%s/%s), err: %v", namespace, name, err)
321+
return false
322+
}, PollTimeout, PollInterval).Should(gomega.Equal(true))
323+
}

test/e2e/suites/init/base_test.go

Lines changed: 111 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package init
1818

1919
import (
20-
"fmt"
2120
"os"
2221
"path/filepath"
2322
"regexp"
@@ -36,6 +35,7 @@ import (
3635
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
3736
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
3837
"github.com/karmada-io/karmada/pkg/util/gclient"
38+
"github.com/karmada-io/karmada/pkg/util/names"
3939
"github.com/karmada-io/karmada/test/e2e/framework"
4040
testhelper "github.com/karmada-io/karmada/test/helper"
4141
)
@@ -62,6 +62,8 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
6262
var deploymentName string
6363
var policyName string
6464

65+
var addonComponentNames []string
66+
6567
var tempPki string
6668

6769
var etcdDataPath string
@@ -85,6 +87,14 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
8587
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
8688
pullModeClusterClient = kubernetes.NewForConfigOrDie(pullModeClusterRestConfig)
8789

90+
addonComponentNames = []string{
91+
names.KarmadaDeschedulerComponentName,
92+
names.KarmadaMetricsAdapterComponentName,
93+
names.KarmadaSearchComponentName,
94+
names.GenerateEstimatorDeploymentName(pullModeClusterName),
95+
names.GenerateEstimatorDeploymentName(pushModeClusterName),
96+
}
97+
8898
targetClusters = []string{pushModeClusterName, pullModeClusterName}
8999
})
90100

@@ -120,6 +130,22 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
120130
controlPlaneConfig = gclient.NewForConfigOrDie(karmadaRestConfig)
121131
kubeClient = kubernetes.NewForConfigOrDie(karmadaRestConfig)
122132
karmadaClient = karmada.NewForConfigOrDie(karmadaRestConfig)
133+
134+
ginkgo.DeferCleanup(func() {
135+
// Clean up the karmada instance by command deinit
136+
cmd := framework.NewKarmadactlCommand(
137+
kubeconfig, "", karmadactlPath, testNamespace, karmadactlTimeout,
138+
"deinit", "-f", // to skip confirmation prompt
139+
"--context", hostContext,
140+
"--v", "4",
141+
)
142+
_, err := cmd.ExecOrDie()
143+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
144+
145+
// Check karmada instance has been cleaned up
146+
framework.WaitDeploymentDisappear(hostClient, testNamespace, names.KarmadaAPIServerComponentName)
147+
framework.WaitDeploymentDisappear(hostClient, testNamespace, names.KarmadaControllerManagerComponentName)
148+
})
123149
})
124150

125151
ginkgo.By("join a push mode cluster", func() {
@@ -130,7 +156,6 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
130156
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
131157

132158
ginkgo.DeferCleanup(func() {
133-
// Unjoin the push mode cluster
134159
cmd := framework.NewKarmadactlCommand(karmadaConfigFilePath, "", karmadactlPath, "", karmadactlTimeout,
135160
"unjoin", "--cluster-kubeconfig", pushModeKubeConfigPath, "--cluster-context", pushModeClusterName, "--cluster-namespace", "karmada-cluster",
136161
"--v", "4", pushModeClusterName)
@@ -173,15 +198,13 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
173198
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
174199

175200
ginkgo.DeferCleanup(func() {
176-
ginkgo.By(fmt.Sprintf("Unregistering cluster: %s", pullModeClusterName), func() {
177-
cmd := framework.NewKarmadactlCommand(
178-
kubeconfig, "", karmadactlPath, "", karmadactlTimeout,
179-
"unregister", pullModeClusterName, "--cluster-kubeconfig", pullModeKubeConfigPath,
180-
"--cluster-context", pullModeClusterName, "--namespace", testNamespace,
181-
)
182-
_, err := cmd.ExecOrDie()
183-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
184-
})
201+
cmd := framework.NewKarmadactlCommand(
202+
kubeconfig, "", karmadactlPath, "", karmadactlTimeout,
203+
"unregister", pullModeClusterName, "--cluster-kubeconfig", pullModeKubeConfigPath,
204+
"--cluster-context", pullModeClusterName, "--namespace", testNamespace,
205+
)
206+
_, err := cmd.ExecOrDie()
207+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
185208
})
186209
})
187210

@@ -195,6 +218,48 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
195218
})
196219
})
197220

221+
ginkgo.By("Enable descheduler, metrics-adapter, scheduler-estimator and search by command addons", func() {
222+
// Command "enable all" means enable all addons including descheduler, metrics-adapter, search and scheduler-estimator.
223+
// But each time only one scheduler-estimator can be enabled for one cluster. So, we need to enable
224+
// scheduler-estimator twice for push mode cluster and pull mode cluster respectively.
225+
cmd := framework.NewKarmadactlCommand(
226+
kubeconfig, "", karmadactlPath, testNamespace, karmadactlTimeout,
227+
"addons", "enable", "all",
228+
"--cluster", pullModeClusterName,
229+
"--karmada-kubeconfig", karmadaConfigFilePath,
230+
"--member-kubeconfig", pullModeKubeConfigPath,
231+
"--karmada-descheduler-image", karmadaDeschedulerImage,
232+
"--karmada-metrics-adapter-image", karmadaMetricsAdapterImage,
233+
"--karmada-search-image", karmadaSearchImage,
234+
"--karmada-scheduler-estimator-image", karmadaSchedulerEstimatorImage,
235+
"--member-context", pullModeClusterName,
236+
"--v", "4",
237+
)
238+
_, err := cmd.ExecOrDie()
239+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
240+
241+
cmd = framework.NewKarmadactlCommand(
242+
kubeconfig, "", karmadactlPath, testNamespace, karmadactlTimeout,
243+
"addons", "enable", names.KarmadaSchedulerEstimatorComponentName,
244+
"--cluster", pushModeClusterName,
245+
"--karmada-kubeconfig", karmadaConfigFilePath,
246+
"--member-kubeconfig", pushModeKubeConfigPath,
247+
"--karmada-scheduler-estimator-image", karmadaSchedulerEstimatorImage,
248+
"--member-context", pushModeClusterName,
249+
"--v", "4",
250+
)
251+
_, err = cmd.ExecOrDie()
252+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
253+
})
254+
255+
ginkgo.By("Wait for the addons to be ready", func() {
256+
for _, component := range addonComponentNames {
257+
framework.WaitDeploymentFitWith(hostClient, testNamespace, component, func(deployment *appsv1.Deployment) bool {
258+
return framework.CheckDeploymentReadyStatus(deployment, *deployment.Spec.Replicas)
259+
})
260+
}
261+
})
262+
198263
ginkgo.By("Do a simple propagation testing", func() {
199264
deploymentNamespace = "deployment-" + rand.String(RandomStrLength)
200265
framework.CreateNamespace(kubeClient, testhelper.NewNamespace(deploymentNamespace))
@@ -216,13 +281,9 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
216281
})
217282

218283
framework.CreateDeployment(kubeClient, deployment)
219-
ginkgo.DeferCleanup(func() {
220-
framework.RemoveDeployment(kubeClient, deploymentNamespace, deploymentName)
221-
})
284+
defer framework.RemoveDeployment(kubeClient, deploymentNamespace, deploymentName)
222285
framework.CreatePropagationPolicy(karmadaClient, policy)
223-
ginkgo.DeferCleanup(func() {
224-
framework.RemovePropagationPolicy(karmadaClient, deploymentNamespace, policyName)
225-
})
286+
defer framework.RemovePropagationPolicy(karmadaClient, deploymentNamespace, policyName)
226287
framework.WaitDeploymentFitWith(pushModeClusterClient, deployment.Namespace, deployment.Name,
227288
func(*appsv1.Deployment) bool {
228289
return true
@@ -232,6 +293,39 @@ var _ = ginkgo.Describe("Base E2E: deploy a karmada instance by cmd init and do
232293
return true
233294
})
234295
})
296+
297+
ginkgo.By("Disable descheduler, metrics-adapter, scheduler-estimator and search by command addons", func() {
298+
// Command "disable all" means disable all addons including descheduler, metrics-adapter, search and scheduler-estimator.
299+
// But each time only one scheduler-estimator can be disabled for one cluster. So, we need to disable
300+
// scheduler-estimator twice for push mode cluster and pull mode cluster respectively.
301+
cmd := framework.NewKarmadactlCommand(
302+
kubeconfig, "", karmadactlPath, testNamespace, karmadactlTimeout,
303+
"addons", "disable", "all",
304+
"--cluster", pullModeClusterName,
305+
"--karmada-kubeconfig", karmadaConfigFilePath,
306+
"-f", // to skip confirmation prompt
307+
"--v", "4",
308+
)
309+
_, err := cmd.ExecOrDie()
310+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
311+
312+
cmd = framework.NewKarmadactlCommand(
313+
kubeconfig, "", karmadactlPath, testNamespace, karmadactlTimeout,
314+
"addons", "disable", names.KarmadaSchedulerEstimatorComponentName,
315+
"--cluster", pushModeClusterName,
316+
"--karmada-kubeconfig", karmadaConfigFilePath,
317+
"-f", // to skip confirmation prompt
318+
"--v", "4",
319+
)
320+
_, err = cmd.ExecOrDie()
321+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
322+
})
323+
324+
ginkgo.By("Wait for addons to be cleaned up", func() {
325+
for _, component := range addonComponentNames {
326+
framework.WaitDeploymentDisappear(hostClient, testNamespace, component)
327+
}
328+
})
235329
})
236330
})
237331
})

test/e2e/suites/init/suite_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ var (
7676
karmadaControllerManagerImage string
7777
karmadaSchedulerImage string
7878
karmadaWebhookImage string
79+
karmadaDeschedulerImage string
80+
karmadaMetricsAdapterImage string
81+
karmadaSearchImage string
82+
karmadaSchedulerEstimatorImage string
7983
)
8084

8185
func init() {
@@ -112,6 +116,10 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { return nil }, func([]byte
112116
karmadaControllerManagerImage = fmt.Sprintf("%s/karmada-controller-manager:%s", registry, version)
113117
karmadaSchedulerImage = fmt.Sprintf("%s/karmada-scheduler:%s", registry, version)
114118
karmadaWebhookImage = fmt.Sprintf("%s/karmada-webhook:%s", registry, version)
119+
karmadaDeschedulerImage = fmt.Sprintf("%s/karmada-descheduler:%s", registry, version)
120+
karmadaMetricsAdapterImage = fmt.Sprintf("%s/karmada-metrics-adapter:%s", registry, version)
121+
karmadaSearchImage = fmt.Sprintf("%s/karmada-search:%s", registry, version)
122+
karmadaSchedulerEstimatorImage = fmt.Sprintf("%s/karmada-scheduler-estimator:%s", registry, version)
115123

116124
goPathCmd := exec.Command("go", "env", "GOPATH")
117125
goPath, err := goPathCmd.CombinedOutput()

0 commit comments

Comments
 (0)