Skip to content

Commit

Permalink
WIP: log pod resources on test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Jul 20, 2023
1 parent 5e20794 commit 00eb175
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions e2e/nomostest/nt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"kpt.dev/configsync/pkg/metadata"
"kpt.dev/configsync/pkg/testing/fake"
"kpt.dev/configsync/pkg/util"
"kpt.dev/configsync/pkg/util/log"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -469,6 +470,21 @@ func (nt *NT) PodLogs(namespace, deployment, container string, previousPodLog bo
nt.T.Logf("%s\n%s", cmd, out)
}

// LogDeploymentPodResources logs the resources of the deployment's pod's containers
func (nt *NT) LogDeploymentPodResources(namespace, deployment string) {
nt.T.Helper()
pod, err := nt.KubeClient.GetDeploymentPod(
deployment, namespace, 10*time.Second)
if err != nil {
nt.T.Error(err)
return
}
nt.T.Logf("Deployment %s/%s pod container resources:", namespace, deployment)
for _, container := range pod.Spec.Containers {
nt.T.Logf("%s: %s", container.Name, log.AsJSON(container.Resources))
}
}

// printTestLogs prints test logs and pods information for debugging.
func (nt *NT) printTestLogs() {
nt.T.Log("[CLEANUP] Printing test logs for current container instances")
Expand Down Expand Up @@ -501,11 +517,13 @@ func (nt *NT) testLogs(previousPodLog bool) {
nt.PodLogs(configmanagement.ControllerNamespace, core.RootReconcilerName(name),
reconcilermanager.Reconciler, previousPodLog)
//nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.NsReconcilerName(ns), reconcilermanager.GitSync, previousPodLog)
nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, core.RootReconcilerName(name))
}
for nn := range nt.NonRootRepos {
nt.PodLogs(configmanagement.ControllerNamespace, core.NsReconcilerName(nn.Namespace, nn.Name),
reconcilermanager.Reconciler, previousPodLog)
//nt.PodLogs(configmanagement.ControllerNamespace, reconcilermanager.NsReconcilerName(ns), reconcilermanager.GitSync, previousPodLog)
nt.LogDeploymentPodResources(configmanagement.ControllerNamespace, core.NsReconcilerName(nn.Namespace, nn.Name))
}
}

Expand Down
8 changes: 8 additions & 0 deletions e2e/testcases/helm_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func TestPublicHelm(t *testing.T) {
err := nt.WatchForAllSyncs(nomostest.WithRootSha1Func(helmChartVersion("15.2.35")),
nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "wordpress"}))
if err != nil {
reconcilerNN := core.RootReconcilerObjectKey(configsync.RootSyncName)
nt.LogDeploymentPodResources(reconcilerNN.Namespace, reconcilerNN.Name)
nt.T.Fatal(err)
}
var expectedCPURequest string
Expand Down Expand Up @@ -257,6 +259,8 @@ service:
err := nt.WatchForAllSyncs(nomostest.WithRootSha1Func(helmChartVersion("15.2.35")),
nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "wordpress"}))
if err != nil {
reconcilerNN := core.RootReconcilerObjectKey(configsync.RootSyncName)
nt.LogDeploymentPodResources(reconcilerNN.Namespace, reconcilerNN.Name)
nt.T.Fatal(err)
}
var expectedCPURequest string
Expand Down Expand Up @@ -364,6 +368,8 @@ image:
err := nt.WatchForAllSyncs(nomostest.WithRootSha1Func(helmChartVersion("15.2.35")),
nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "wordpress"}))
if err != nil {
reconcilerNN := core.RootReconcilerObjectKey(configsync.RootSyncName)
nt.LogDeploymentPodResources(reconcilerNN.Namespace, reconcilerNN.Name)
nt.T.Fatal(err)
}

Expand Down Expand Up @@ -489,6 +495,8 @@ func TestHelmVersionRange(t *testing.T) {
err := nt.WatchForAllSyncs(nomostest.WithRootSha1Func(helmChartVersion("15.4.1")),
nomostest.WithSyncDirectoryMap(map[types.NamespacedName]string{nomostest.DefaultRootRepoNamespacedName: "wordpress"}))
if err != nil {
reconcilerNN := core.RootReconcilerObjectKey(configsync.RootSyncName)
nt.LogDeploymentPodResources(reconcilerNN.Namespace, reconcilerNN.Name)
nt.T.Fatal(err)
}

Expand Down

0 comments on commit 00eb175

Please sign in to comment.