mirror of
https://github.com/outbackdingo/kamaji.git
synced 2026-01-27 10:19:29 +00:00
feat(e2e): reporting kamaji logs in case of test failure
This commit is contained in:
@@ -5,48 +5,23 @@ metadata:
|
||||
spec:
|
||||
controlPlane:
|
||||
deployment:
|
||||
replicas: 2
|
||||
additionalMetadata:
|
||||
annotations:
|
||||
environment.clastix.io: test
|
||||
tier.clastix.io: "0"
|
||||
labels:
|
||||
tenant.clastix.io: test
|
||||
kind.clastix.io: deployment
|
||||
replicas: 1
|
||||
service:
|
||||
additionalMetadata:
|
||||
annotations:
|
||||
environment.clastix.io: test
|
||||
tier.clastix.io: "0"
|
||||
labels:
|
||||
tenant.clastix.io: test
|
||||
kind.clastix.io: service
|
||||
serviceType: LoadBalancer
|
||||
ingress:
|
||||
enabled: true
|
||||
hostname: kamaji.local
|
||||
ingressClassName: nginx
|
||||
additionalMetadata:
|
||||
annotations:
|
||||
kubernetes.io/ingress.allow-http: "false"
|
||||
nginx.ingress.kubernetes.io/secure-backends: "true"
|
||||
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
|
||||
enabled: false
|
||||
kubernetes:
|
||||
version: "v1.23.1"
|
||||
kubelet:
|
||||
cgroupfs: systemd
|
||||
cgroupfs: cgroupfs
|
||||
admissionControllers:
|
||||
- ResourceQuota
|
||||
- LimitRanger
|
||||
networkProfile:
|
||||
address: "127.0.0.1"
|
||||
port: 6443
|
||||
certSANs:
|
||||
- "test.clastix.labs"
|
||||
serviceCidr: "10.96.0.0/16"
|
||||
podCidr: "10.244.0.0/16"
|
||||
dnsServiceIPs:
|
||||
- "10.96.0.10"
|
||||
addons:
|
||||
coreDNS: {}
|
||||
kubeProxy: {}
|
||||
konnectivity:
|
||||
proxyPort: 8134
|
||||
serviceType: LoadBalancer
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
|
||||
|
||||
var (
|
||||
cfg *rest.Config // nolint
|
||||
cfg *rest.Config
|
||||
k8sClient client.Client
|
||||
testEnv *envtest.Environment
|
||||
)
|
||||
@@ -45,7 +45,9 @@ var _ = BeforeSuite(func() {
|
||||
UseExistingCluster: pointer.Bool(true),
|
||||
}
|
||||
|
||||
cfg, err := testEnv.Start()
|
||||
var err error
|
||||
|
||||
cfg, err = testEnv.Start()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(cfg).NotTo(BeNil())
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ var _ = Describe("Deploy a TenantControlPlane resource", func() {
|
||||
|
||||
// Delete the TenantControlPlane resource after test is finished
|
||||
JustAfterEach(func() {
|
||||
PrintKamajiLogs()
|
||||
Expect(k8sClient.Delete(context.Background(), &tcp)).Should(Succeed())
|
||||
})
|
||||
|
||||
|
||||
@@ -4,11 +4,16 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"fmt"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"io/ioutil"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
func GetKindIPAddress() string {
|
||||
@@ -17,3 +22,42 @@ func GetKindIPAddress() string {
|
||||
|
||||
return ep.Subsets[0].Addresses[0].IP
|
||||
}
|
||||
|
||||
func PrintKamajiLogs() {
|
||||
if CurrentGinkgoTestDescription().Failed {
|
||||
clientset, err := kubernetes.NewForConfig(cfg)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
list, err := clientset.CoreV1().Pods("kamaji-system").List(context.Background(), metav1.ListOptions{
|
||||
LabelSelector: "app.kubernetes.io/component=controller-manager",
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(list.Items).To(HaveLen(1))
|
||||
|
||||
request := clientset.CoreV1().Pods("kamaji-system").GetLogs(list.Items[0].GetName(), &corev1.PodLogOptions{
|
||||
Container: "manager",
|
||||
SinceSeconds: func() *int64 {
|
||||
seconds := int64(CurrentGinkgoTestDescription().Duration.Seconds())
|
||||
|
||||
return &seconds
|
||||
}(),
|
||||
Timestamps: true,
|
||||
})
|
||||
|
||||
podLogs, err := request.Stream(context.Background())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
defer podLogs.Close()
|
||||
|
||||
podBytes, err := ioutil.ReadAll(podLogs)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, _ = fmt.Fprintln(GinkgoWriter, "DEBUG: retrieving Kamaji Pod logs")
|
||||
|
||||
for _, line := range bytes.Split(podBytes, []byte("\n")) {
|
||||
_, _ = fmt.Fprintln(GinkgoWriter, ">>> ", string(line))
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(GinkgoWriter, "DEBUG: end of Kamaji Pod logs")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +92,9 @@ var _ = Describe("starting a kind worker with kubeadm", func() {
|
||||
})
|
||||
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(ctx, &tcp)).Should(Succeed())
|
||||
PrintKamajiLogs()
|
||||
Expect(workerContainer.Terminate(ctx)).ToNot(HaveOccurred())
|
||||
Expect(k8sClient.Delete(ctx, &tcp)).Should(Succeed())
|
||||
Expect(os.Remove(kubeconfigFile.Name())).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ var _ = Describe("validating kubeconfig", func() {
|
||||
})
|
||||
|
||||
JustAfterEach(func() {
|
||||
PrintKamajiLogs()
|
||||
Expect(k8sClient.Delete(ctx, tcp)).Should(Succeed())
|
||||
Expect(os.Remove(kubeconfigFile.Name())).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user