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

e2e: more troubleshoot utilities #337

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
104 changes: 5 additions & 99 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ import (
"github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/client"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/yaml"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8swait "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"

"github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
Expand All @@ -54,12 +52,12 @@ import (
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/wait"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests/rte"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests/sched"
"github.com/k8stopologyawareschedwg/deployer/pkg/options"
"github.com/k8stopologyawareschedwg/deployer/pkg/stringify"
"github.com/k8stopologyawareschedwg/deployer/pkg/validator"
e2epods "github.com/k8stopologyawareschedwg/deployer/test/e2e/utils/pods"

e2edump "github.com/k8stopologyawareschedwg/deployer/test/e2e/utils/dump"
)

var (
Expand Down Expand Up @@ -283,109 +281,17 @@ func WithEnv(cli client.Client) *deployer.Environment {

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

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

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

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

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

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

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

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

e2epods.LogEventsForPod(k8sCli, ctx, pod.Namespace, pod.Name)
klog.Warningf("---\n")
}

var cm corev1.ConfigMap
key := client.ObjectKey{
Namespace: "tas-scheduler",
Name: "scheduler-config",
}
err = cli.Get(ctx, key, &cm)
if err == nil {
// skip errors until we can autodetect the CM key
klog.Infof("scheduler config:\n%s", cm.Data["scheduler-config.yaml"])
}

klog.Warning(">>> scheduler pod status end\n")
gomega.Expect(e2edump.SchedulerPods(ctx, cli)).To(gomega.Succeed())
}

func dumpWorkloadPods(ctx context.Context, pod *corev1.Pod) {
ginkgo.GinkgoHelper()

pod = pod.DeepCopy()

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

klog.Warning(">>> workload pod status begin:\n")
pod.ManagedFields = nil

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

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

e2epods.LogEventsForPod(k8sCli, ctx, pod.Namespace, pod.Name)
klog.Warningf("---\n")
klog.Warning(">>> workload pod status end\n")
gomega.Expect(e2edump.WorkloadPods(ctx, pod)).To(gomega.Succeed())
}

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

ns, err := manifests.Namespace(manifests.ComponentResourceTopologyExporter)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

// TODO: autodetect the platform
mfs, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, true, true)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mfs, err = mfs.Render(options.UpdaterDaemon{
Namespace: ns.Name,
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

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

pods, err := e2epods.GetByDaemonSet(cli, ctx, *mfs.DaemonSet)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

klog.Warning(">>> RTE pod status begin:\n")
if len(pods) > 1 {
klog.Warningf("UNEXPECTED POD COUNT %d: dumping only the first", len(pods))
}
if len(pods) > 0 {
pod := pods[0].DeepCopy()
pod.ManagedFields = nil

logs, err := e2epods.GetLogsForPod(k8sCli, pod.Namespace, pod.Name, pod.Spec.Containers[0].Name)
if err == nil {
// skip errors until we can autodetect the CM key
klog.Infof(">>> RTE logs begin:\n%s\n>>> RTE logs end", logs)
}
}

klog.Warning(">>> RTE pod status end\n")
gomega.Expect(e2edump.ResourceTopologyExporterPods(ctx, cli)).To(gomega.Succeed())
}

func expectSchedulerRunning(ctx context.Context, cli client.Client) {
Expand Down
21 changes: 13 additions & 8 deletions test/e2e/positive.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/k8stopologyawareschedwg/deployer/pkg/options"
"github.com/k8stopologyawareschedwg/deployer/pkg/validator"

e2edump "github.com/k8stopologyawareschedwg/deployer/test/e2e/utils/dump"
e2enodes "github.com/k8stopologyawareschedwg/deployer/test/e2e/utils/nodes"
e2epods "github.com/k8stopologyawareschedwg/deployer/test/e2e/utils/pods"
)
Expand Down Expand Up @@ -308,13 +309,10 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", ginkgo.Label("posit
ginkgo.By("checking the pod goes running")
updatedPod, err := e2epods.WaitForPodToBeRunning(context.TODO(), cli, testPod.Namespace, testPod.Name, 3*time.Minute)
if err != nil {
ctx := context.Background()
cli, cerr := clientutil.New()
if cerr != nil {
dumpResourceTopologyExporterPods(ctx, cli)
dumpSchedulerPods(ctx, cli)
dumpWorkloadPods(ctx, updatedPod)
}
cli2, err := clientutil.New()
if err == nil {
e2edump.ClusterState(context.TODO(), cli2, updatedPod)
} // else TODO: log somehow
}
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})
Expand Down Expand Up @@ -395,7 +393,14 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", ginkgo.Label("posit
gomega.Expect(err).ToNot(gomega.HaveOccurred())

ginkgo.By("checking the pod goes running")
e2epods.ExpectPodToBeRunning(cli, testPod.Namespace, testPod.Name, 2*time.Minute)
pod, err := e2epods.WaitForPodToBeRunning(context.Background(), cli, testPod.Namespace, testPod.Name, 2*time.Minute)
if err != nil {
cli2, err := clientutil.New()
if err == nil {
e2edump.ClusterState(context.Background(), cli2, pod)
} // else TODO: log somehow
}
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})
})
})
Expand Down
184 changes: 184 additions & 0 deletions test/e2e/utils/dump/dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2021 Red Hat, Inc.
*/

package dump

import (
"context"

"github.com/go-logr/logr"

corev1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"

"github.com/k8stopologyawareschedwg/deployer/pkg/clientutil"
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests/rte"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests/sched"
"github.com/k8stopologyawareschedwg/deployer/pkg/options"
e2epods "github.com/k8stopologyawareschedwg/deployer/test/e2e/utils/pods"
)

// todo: port to deployer.Environment

func ClusterState(ctx context.Context, cli client.Client, updatedPod *corev1.Pod) error {
if err := ResourceTopologyExporterPods(ctx, cli); err != nil {
return err
}
if err := SchedulerPods(ctx, cli); err != nil {
return err
}
if err := WorkloadPods(ctx, updatedPod); err != nil {
return err
}
return nil
}

func SchedulerPods(ctx context.Context, cli client.Client) error {
ns, err := manifests.Namespace(manifests.ComponentSchedulerPlugin)
if err != nil {
return err
}

// TODO: autodetect the platform
mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name)
if err != nil {
return err
}
mfs, err = mfs.Render(logr.Discard(), options.Scheduler{
Replicas: int32(1),
})
if err != nil {
return err
}

k8sCli, err := clientutil.NewK8s()
if err != nil {
return err
}

pods, err := e2epods.GetByDeployment(cli, ctx, *mfs.DPScheduler)
if err != nil {
return err
}

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

data, err := yaml.Marshal(pod)
if err != nil {
return err
}

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

e2epods.LogEventsForPod(k8sCli, ctx, pod.Namespace, pod.Name)
klog.Warningf("---\n")
}

var cm corev1.ConfigMap
key := client.ObjectKey{
Namespace: "tas-scheduler",
Name: "scheduler-config",
}
err = cli.Get(ctx, key, &cm)
if err == nil {
// skip errors until we can autodetect the CM key
klog.Infof("scheduler config:\n%s", cm.Data["scheduler-config.yaml"])
} else {
klog.Errorf("error getting config map: %v", err)
}

klog.Warning(">>> scheduler pod status end\n")
return nil
}

func WorkloadPods(ctx context.Context, pod *corev1.Pod) error {
pod = pod.DeepCopy()

k8sCli, err := clientutil.NewK8s()
if err != nil {
return err
}

klog.Warning(">>> workload pod status begin:\n")
pod.ManagedFields = nil

data, err := yaml.Marshal(pod)
if err != nil {
return err
}

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

e2epods.LogEventsForPod(k8sCli, ctx, pod.Namespace, pod.Name)
klog.Warningf("---\n")
klog.Warning(">>> workload pod status end\n")
return nil
}

func ResourceTopologyExporterPods(ctx context.Context, cli client.Client) error {
ns, err := manifests.Namespace(manifests.ComponentResourceTopologyExporter)
if err != nil {
return err
}

// TODO: autodetect the platform
mfs, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, true, false)
if err != nil {
return err
}
mfs, err = mfs.Render(options.UpdaterDaemon{Namespace: ns.Name})
if err != nil {
return err
}

k8sCli, err := clientutil.NewK8s()
if err != nil {
return err
}

pods, err := e2epods.GetByDaemonSet(cli, ctx, *mfs.DaemonSet)
if err != nil {
return err
}

klog.Warning(">>> RTE pod status begin:\n")
if len(pods) > 1 {
klog.Warningf("UNEXPECTED POD COUNT %d: dumping only the first", len(pods))
}
if len(pods) > 0 {
pod := pods[0].DeepCopy()
pod.ManagedFields = nil

logs, err := e2epods.GetLogsForPod(k8sCli, pod.Namespace, pod.Name, pod.Spec.Containers[0].Name)
if err == nil {
// skip errors until we can autodetect the CM key
klog.Infof(">>> RTE logs begin:\n%s\n>>> RTE logs end", logs)
} else {
klog.Errorf("error getting logs for pod %s/%s/%s", pod.Namespace, pod.Name, pod.Spec.Containers[0].Name)
}
}

klog.Warning(">>> RTE pod status end\n")
return nil
}
Loading