Skip to content

Commit

Permalink
Merge pull request kubevirt#12834 from iholder101/report_migration_po…
Browse files Browse the repository at this point in the history
…licies

Report migration policies as part of the k8s reporter when tests finish
  • Loading branch information
kubevirt-bot authored Sep 17, 2024
2 parents 64bc387 + 6f86f1e commit 41c7a6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func main() {
// Hardcoding maxFails to 1 since the purpouse here is just to dump the state once
reporter := reporter.NewKubernetesReporter(os.Getenv("ARTIFACTS"), 1)
reporter.Cleanup()
reporter.DumpAllNamespaces(duration)
reporter.DumpTestObjects(duration)
}
1 change: 1 addition & 0 deletions tests/reporter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
deps = [
"//pkg/virt-handler/virt-chroot:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/migrations:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//tests:go_default_library",
Expand Down
26 changes: 19 additions & 7 deletions tests/reporter/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
apiregv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"

v12 "kubevirt.io/api/core/v1"
"kubevirt.io/api/migrations"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"
apicdi "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
Expand Down Expand Up @@ -117,7 +118,7 @@ func (r *KubernetesReporter) Report(report types.Report) {

printInfo("Test suite failed, collect artifacts in %s", r.artifactsDir)

r.dumpNamespaces(report.RunTime, testsuite.TestNamespaces)
r.dumpTestObjects(report.RunTime, testsuite.TestNamespaces)
}

func (r *KubernetesReporter) ReportSpec(specReport types.SpecReport) {
Expand All @@ -140,18 +141,18 @@ func (r *KubernetesReporter) ReportSpec(specReport types.SpecReport) {
reason = "due to use of programmatic focus container"
}
By(fmt.Sprintf("Collecting Logs %s", reason))
r.DumpTestNamespaces(specReport.RunTime)
r.DumpTestNamespacesAndClusterObjects(specReport.RunTime)
}

func (r *KubernetesReporter) DumpTestNamespaces(duration time.Duration) {
r.dumpNamespaces(duration, testsuite.TestNamespaces)
func (r *KubernetesReporter) DumpTestNamespacesAndClusterObjects(duration time.Duration) {
r.dumpTestObjects(duration, testsuite.TestNamespaces)
}

func (r *KubernetesReporter) DumpAllNamespaces(duration time.Duration) {
r.dumpNamespaces(duration, []string{v1.NamespaceAll})
func (r *KubernetesReporter) DumpTestObjects(duration time.Duration) {
r.dumpTestObjects(duration, []string{v1.NamespaceAll})
}

func (r *KubernetesReporter) dumpNamespaces(duration time.Duration, vmiNamespaces []string) {
func (r *KubernetesReporter) dumpTestObjects(duration time.Duration, vmiNamespaces []string) {
cfg, err := kubecli.GetKubevirtClientConfig()
if err != nil {
printError("failed to get client config: %v", err)
Expand Down Expand Up @@ -229,6 +230,7 @@ func (r *KubernetesReporter) dumpNamespaces(duration time.Duration, vmiNamespace

r.logCloudInit(virtCli, vmiNamespaces)
r.logVirtualMachinePools(virtCli)
r.logMigrationPolicies(virtCli)
}

// Cleanup cleans up the current content of the artifactsDir
Expand Down Expand Up @@ -1414,3 +1416,13 @@ func (r *KubernetesReporter) logVirtualMachinePools(virtCli kubecli.KubevirtClie

r.logObjects(pools, "virtualmachinepools")
}

func (r *KubernetesReporter) logMigrationPolicies(virtCli kubecli.KubevirtClient) {
policies, err := virtCli.MigrationPolicy().List(context.Background(), metav1.ListOptions{})
if err != nil {
printError("failed to fetch migration policies: %v", err)
return
}

r.logObjects(policies, migrations.ResourceMigrationPolicies)
}

0 comments on commit 41c7a6e

Please sign in to comment.