mirror of
https://github.com/clastix/kamaji.git
synced 2026-02-14 10:00:02 +00:00
feat(e2e): reporting tcp status and resources in case of failed test
This commit is contained in:
@@ -59,6 +59,7 @@ var _ = Describe("Deploy a TenantControlPlane resource", func() {
|
||||
|
||||
// Delete the TenantControlPlane resource after test is finished
|
||||
JustAfterEach(func() {
|
||||
PrintTenantControlPlaneInfo(&tcp)
|
||||
PrintKamajiLogs()
|
||||
Expect(k8sClient.Delete(context.Background(), &tcp)).Should(Succeed())
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -15,6 +16,8 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
|
||||
)
|
||||
|
||||
func GetKindIPAddress() string {
|
||||
@@ -24,6 +27,49 @@ func GetKindIPAddress() string {
|
||||
return ep.Subsets[0].Addresses[0].IP
|
||||
}
|
||||
|
||||
func PrintTenantControlPlaneInfo(tcp *kamajiv1alpha1.TenantControlPlane) {
|
||||
kubectlExec := func(args ...string) {
|
||||
cmd := exec.Command("kubectl")
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
cmd.Args = args
|
||||
|
||||
Expect(cmd.Run()).ToNot(HaveOccurred())
|
||||
|
||||
for {
|
||||
line, err := out.ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprint(GinkgoWriter, ">>> ", line)
|
||||
}
|
||||
}
|
||||
|
||||
if CurrentGinkgoTestDescription().Failed {
|
||||
_, _ = fmt.Fprintln(GinkgoWriter, "DEBUG: Tenant Control Plane definition")
|
||||
kubectlExec(
|
||||
fmt.Sprintf("--namespace=%s", tcp.GetNamespace()),
|
||||
"get",
|
||||
"tcp",
|
||||
tcp.GetName(),
|
||||
)
|
||||
_, _ = fmt.Fprintln(GinkgoWriter, "DEBUG: Tenant Control Plane resources")
|
||||
kubectlExec(
|
||||
fmt.Sprintf("--namespace=%s", tcp.GetNamespace()),
|
||||
"get",
|
||||
"svc,deployment,pods,ep,configmap,secrets",
|
||||
)
|
||||
_, _ = fmt.Fprintln(GinkgoWriter, "DEBUG: Tenant Control Plane pods")
|
||||
kubectlExec(
|
||||
fmt.Sprintf("--namespace=%s", tcp.GetNamespace()),
|
||||
"describe",
|
||||
"pods",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func PrintKamajiLogs() {
|
||||
if CurrentGinkgoTestDescription().Failed {
|
||||
clientset, err := kubernetes.NewForConfig(cfg)
|
||||
|
||||
@@ -92,6 +92,7 @@ var _ = Describe("starting a kind worker with kubeadm", func() {
|
||||
})
|
||||
|
||||
JustAfterEach(func() {
|
||||
PrintTenantControlPlaneInfo(&tcp)
|
||||
PrintKamajiLogs()
|
||||
Expect(workerContainer.Terminate(ctx)).ToNot(HaveOccurred())
|
||||
Expect(k8sClient.Delete(ctx, &tcp)).Should(Succeed())
|
||||
|
||||
@@ -50,7 +50,7 @@ var _ = Describe("validating kubeconfig", func() {
|
||||
},
|
||||
NetworkProfile: kamajiv1alpha1.NetworkProfileSpec{
|
||||
Address: GetKindIPAddress(),
|
||||
Port: 31443,
|
||||
Port: 30001,
|
||||
},
|
||||
Kubernetes: kamajiv1alpha1.KubernetesSpec{
|
||||
Version: "v1.23.6",
|
||||
@@ -75,12 +75,13 @@ var _ = Describe("validating kubeconfig", func() {
|
||||
|
||||
JustAfterEach(func() {
|
||||
PrintKamajiLogs()
|
||||
PrintTenantControlPlaneInfo(tcp)
|
||||
Expect(k8sClient.Delete(ctx, tcp)).Should(Succeed())
|
||||
Expect(os.Remove(kubeconfigFile.Name())).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("return kubernetes version", func() {
|
||||
for _, port := range []int32{31444, 31445, 31446} {
|
||||
for _, port := range []int32{30002, 30003, 30004} {
|
||||
Eventually(func() string {
|
||||
By(fmt.Sprintf("ensuring TCP port is set to %d", port), func() {
|
||||
Eventually(func() (err error) {
|
||||
@@ -158,7 +159,7 @@ var _ = Describe("validating kubeconfig", func() {
|
||||
})
|
||||
|
||||
return version.GitVersion
|
||||
}, 5*time.Minute, 5*time.Second).Should(Equal(tcp.Spec.Kubernetes.Version))
|
||||
}, 3*time.Minute, 5*time.Second).Should(Equal(tcp.Spec.Kubernetes.Version))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user