Skip to content

Commit

Permalink
e2e: utils: make the functions more reusable
Browse files Browse the repository at this point in the history
Improve the reusability of the helpers, accepting
clients and contexts instead of recreating them every single time.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Mar 5, 2024
1 parent 1a8759d commit 31a9c42
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 40 deletions.
71 changes: 35 additions & 36 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ func deployWithManifests() error {
// TODO: use error wrapping
err := runCmdline(cmdline, "failed to deploy components before test started")
if err != nil {
dumpSchedulerPods()
cli, cerr := clientutil.New()
if cerr == nil {
// don't hide the previous error
dumpSchedulerPods(context.Background(), cli)
} // else?
}
return err
}
Expand All @@ -224,7 +228,11 @@ func deploy(updaterType string, pfpEnable bool) error {
// TODO: use error wrapping
err := runCmdline(cmdline, "failed to deploy components before test started")
if err != nil {
dumpSchedulerPods()
cli, cerr := clientutil.New()
if cerr == nil {
// don't hide the previous error
dumpSchedulerPods(context.Background(), cli)
} // else?
}
return err
}
Expand Down Expand Up @@ -258,7 +266,7 @@ func runCmdline(cmdline []string, errMsg string) error {

func NullEnv() *deployer.Environment {
cli, err := clientutil.New()
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
env := deployer.Environment{
Ctx: context.TODO(),
Cli: cli,
Expand All @@ -267,39 +275,33 @@ func NullEnv() *deployer.Environment {
return &env
}

func dumpSchedulerPods() {
func dumpSchedulerPods(ctx context.Context, cli client.Client) {
ginkgo.GinkgoHelper()

ns, err := manifests.Namespace(manifests.ComponentSchedulerPlugin)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

// TODO: autodetect the platform
mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mfs, err = mfs.Render(logr.Discard(), options.Scheduler{
Replicas: int32(1),
})
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())

cli, err := clientutil.New()
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

k8sCli, err := clientutil.NewK8s()
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())

ctx := context.Background()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

pods, err := e2epods.GetByDeployment(cli, ctx, *mfs.DPScheduler)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

klog.Warning(">>> scheduler pod status begin:\n")
for idx := range pods {
pod := &pods[idx]

// TODO
pod := pods[idx].DeepCopy()
pod.ManagedFields = nil
// TODO

data, err := yaml.Marshal(pod)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

klog.Warningf("%s\n---\n", string(data))

Expand All @@ -309,14 +311,11 @@ func dumpSchedulerPods() {
klog.Warning(">>> scheduler pod status end\n")
}

func expectSchedulerRunning() {
ns, err := manifests.Namespace(manifests.ComponentSchedulerPlugin)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())

cli, err := clientutil.New()
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
func expectSchedulerRunning(ctx context.Context, cli client.Client) {
ginkgo.GinkgoHelper()

ctx := context.Background()
ns, err := manifests.Namespace(manifests.ComponentSchedulerPlugin)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

ginkgo.By("checking that scheduler plugin is configured")

Expand All @@ -327,30 +326,30 @@ func expectSchedulerRunning() {
},
}
err = cli.Get(ctx, client.ObjectKeyFromObject(&confMap), &confMap)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.ExpectWithOffset(1, confMap.Data).ToNot(gomega.BeNil(), "empty config map for scheduler config")
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(confMap.Data).ToNot(gomega.BeNil(), "empty config map for scheduler config")

data, ok := confMap.Data[manifests.SchedulerConfigFileName]
gomega.ExpectWithOffset(1, ok).To(gomega.BeTrue(), "empty config data for %q", manifests.SchedulerConfigFileName)
gomega.Expect(ok).To(gomega.BeTrue(), "empty config data for %q", manifests.SchedulerConfigFileName)

allParams, err := manifests.DecodeSchedulerProfilesFromData([]byte(data))
gomega.ExpectWithOffset(1, len(allParams)).To(gomega.Equal(1), "unexpected params: %#v", allParams)
gomega.Expect(len(allParams)).To(gomega.Equal(1), "unexpected params: %#v", allParams)

params := allParams[0] // TODO: smarter find
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.ExpectWithOffset(1, params.Cache).ToNot(gomega.BeNil(), "no data for scheduler cache config")
gomega.ExpectWithOffset(1, params.Cache.ResyncPeriodSeconds).ToNot(gomega.BeNil(), "no data for scheduler cache resync period")
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(params.Cache).ToNot(gomega.BeNil(), "no data for scheduler cache config")
gomega.Expect(params.Cache.ResyncPeriodSeconds).ToNot(gomega.BeNil(), "no data for scheduler cache resync period")

ginkgo.By("checking that scheduler plugin is running")

ginkgo.By("checking that topo-aware-scheduler pod is running")
// TODO: autodetect the platform
mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mfs, err = mfs.Render(logr.Discard(), options.Scheduler{
Replicas: int32(1),
})
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

var wg sync.WaitGroup
for _, dp := range []*appsv1.Deployment{
Expand All @@ -362,7 +361,7 @@ func expectSchedulerRunning() {
defer ginkgo.GinkgoRecover()
defer wg.Done()
_, err = wait.With(cli, logr.Discard()).Interval(10*time.Second).Timeout(3*time.Minute).ForDeploymentComplete(ctx, dp)
gomega.ExpectWithOffset(1, err).ToNot(gomega.HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}(dp)
}
wg.Wait()
Expand Down
22 changes: 18 additions & 4 deletions test/e2e/positive.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,11 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer partial execution", func() {
"failed to deploy partial components before test started",
)
if err != nil {
dumpSchedulerPods()
cli, cerr := clientutil.New()
if cerr == nil {
// don't hide the previous error
dumpSchedulerPods(context.Background(), cli)
} // else?
}
gomega.Expect(err).ToNot(gomega.HaveOccurred())

Expand All @@ -460,7 +464,10 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer partial execution", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}()

expectSchedulerRunning()
cli, err := clientutil.New()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

expectSchedulerRunning(context.Background(), cli)
})

ginkgo.It("should perform the deployment of scheduler plugin (with extreme verbosity) + API and verify all pods are running", func() {
Expand All @@ -477,7 +484,11 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer partial execution", func() {
"failed to deploy partial components before test started",
)
if err != nil {
dumpSchedulerPods()
cli, cerr := clientutil.New()
if cerr == nil {
// don't hide the previous error
dumpSchedulerPods(context.Background(), cli)
} // else?
}
gomega.Expect(err).ToNot(gomega.HaveOccurred())

Expand All @@ -495,7 +506,10 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer partial execution", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}()

expectSchedulerRunning()
cli, err := clientutil.New()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

expectSchedulerRunning(context.Background(), cli)
})
})
})

0 comments on commit 31a9c42

Please sign in to comment.