Skip to content

Commit

Permalink
[NO-ISSUE] add verbose output to waitforpod to see waiing reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
gtully committed Aug 28, 2024
1 parent 43ef027 commit 91ea49a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 64 deletions.
8 changes: 4 additions & 4 deletions controllers/activemqartemis_controller2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var _ = Describe("artemis controller 2", func() {
})

By("waiting for pod ready")
WaitForPod(brokerCr.Name, 0)
WaitForPod(brokerCr.Name)

By("writing some files to the volume")
podWithOrdinal := namer.CrToSS(brokerCr.Name) + "-0"
Expand Down Expand Up @@ -251,7 +251,7 @@ var _ = Describe("artemis controller 2", func() {
})

By("waiting for pod ready")
WaitForPod(brokerCr.Name, 0)
WaitForPod(brokerCr.Name)

By("checking the file still exist on volumes")
lsCmd = []string{"ls", "/opt/common"}
Expand Down Expand Up @@ -320,7 +320,7 @@ var _ = Describe("artemis controller 2", func() {
defaultMoutPath := volumes.GetDefaultExternalPVCMountPath("mydata")

By("waiting for pod ready")
WaitForPod(brokerCr.Name, 0)
WaitForPod(brokerCr.Name)

By("writing some files to the volume")
podWithOrdinal := namer.CrToSS(brokerCr.Name) + "-0"
Expand Down Expand Up @@ -375,7 +375,7 @@ var _ = Describe("artemis controller 2", func() {
})

By("waiting 2 pods ready")
WaitForPod(brokerCr.Name, 0, 1)
WaitForPods(brokerCr.Name, 0, 1)

By("checking the file exists on pod 0")
lsCmd = []string{"ls", mountPath}
Expand Down
19 changes: 4 additions & 15 deletions controllers/activemqartemis_controller_cert_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
tm "github.com/cert-manager/trust-manager/pkg/apis/trust/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -213,28 +212,18 @@ var _ = Describe("artemis controller with cert manager test", Label("controller-
})

By("verify pod is up and acceptor is working")
ssKey := types.NamespacedName{
Name: namer.CrToSS(brokerCr.Name),
Namespace: defaultNamespace,
}
currentSS := &appsv1.StatefulSet{}
podKey := types.NamespacedName{Name: namer.CrToSS(brokerCr.Name) + "-0", Namespace: defaultNamespace}
pod := &corev1.Pod{}
WaitForPod(brokerCr.Name)
podName := namer.CrToSSOrdinal(brokerCr.Name, 0)
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, ssKey, currentSS)).Should(Succeed())
g.Expect(currentSS.Status.ReadyReplicas).To(Equal(int32(1)))
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())
g.Expect(len(pod.Status.ContainerStatuses)).Should(Equal(1))
g.Expect(pod.Status.ContainerStatuses[0].State.Running).ShouldNot(BeNil())
CheckAcceptorStarted(pod.Name, brokerCr.Name, "amqps", g)
CheckAcceptorStarted(podName, brokerCr.Name, "amqps", g)
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

By("check messaging should work")
keyStorePath := "/amq/extra/secrets/" + trustSec.Name + "/broker.ks"
trustStorePath := "/etc/" + certSecret.Name + "-volume/truststore.p12"
password := "password"
Eventually(func(g Gomega) {
checkMessagingInPodWithJavaStore(pod.Name, brokerCr.Name, "5671", trustStorePath, password, &keyStorePath, &password, g)
checkMessagingInPodWithJavaStore(podName, brokerCr.Name, "5671", trustStorePath, password, &keyStorePath, &password, g)
}, timeout, interval).Should(Succeed())

By("clean up")
Expand Down
49 changes: 6 additions & 43 deletions controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,8 @@ var _ = Describe("artemis controller", func() {
}
})

ssKey := types.NamespacedName{
Name: namer.CrToSS(brokerCr.Name),
Namespace: defaultNamespace,
}

By("verify pod is up")
currentSS := &appsv1.StatefulSet{}
podKey := types.NamespacedName{Name: namer.CrToSS(brokerCr.Name) + "-0", Namespace: defaultNamespace}
pod := &corev1.Pod{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, ssKey, currentSS)).Should(Succeed())
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())
g.Expect(len(pod.Status.ContainerStatuses)).Should(Equal(1))
g.Expect(pod.Status.ContainerStatuses[0].State.Running).ShouldNot(BeNil())
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())
WaitForPod(brokerCr.Name)

By("checking service is created for console")
serviceName := brokerCr.Name + "-amqp-ssl-0-svc"
Expand Down Expand Up @@ -1844,6 +1831,7 @@ var _ = Describe("artemis controller", func() {
g.Expect(k8sClient.Get(ctx, brokerKey, deployedCrd)).Should(Succeed())
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

WaitForPod(crd.Name)
ssKey := types.NamespacedName{
Name: namer.CrToSS(crd.Name),
Namespace: defaultNamespace,
Expand All @@ -1854,13 +1842,7 @@ var _ = Describe("artemis controller", func() {
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

By("verify pod is up")
podKey := types.NamespacedName{Name: namer.CrToSS(crd.Name) + "-0", Namespace: defaultNamespace}
Eventually(func(g Gomega) {
pod := &corev1.Pod{}
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())
g.Expect(pod.Status.ContainerStatuses).Should(HaveLen(1))
g.Expect(pod.Status.ContainerStatuses[0].State.Running).Should(Not(BeNil()))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())
WaitForPod(crd.Name)

var host string

Expand Down Expand Up @@ -2013,13 +1995,7 @@ var _ = Describe("artemis controller", func() {
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

By("verify pod is up")
podKey := types.NamespacedName{Name: namer.CrToSS(crd.Name) + "-0", Namespace: defaultNamespace}
Eventually(func(g Gomega) {
pod := &corev1.Pod{}
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())
g.Expect(pod.Status.ContainerStatuses).Should(HaveLen(1))
g.Expect(pod.Status.ContainerStatuses[0].State.Running).Should(Not(BeNil()))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())
WaitForPod(crd.Name)

if isOpenshift {
By("check console acceptor is created")
Expand Down Expand Up @@ -2195,13 +2171,7 @@ var _ = Describe("artemis controller", func() {
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

By("verify pod is up")
podKey := types.NamespacedName{Name: namer.CrToSS(crd.Name) + "-0", Namespace: defaultNamespace}
Eventually(func(g Gomega) {
pod := &corev1.Pod{}
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())
g.Expect(len(pod.Status.ContainerStatuses)).Should(Equal(1))
g.Expect(pod.Status.ContainerStatuses[0].State.Running).Should(Not(BeNil()))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())
WaitForPod(crd.Name)

if isOpenshift {
By("check route is created")
Expand Down Expand Up @@ -2898,14 +2868,7 @@ var _ = Describe("artemis controller", func() {
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

By("verify ready status of pod with correct image")
Eventually(func(g Gomega) {
pod := &corev1.Pod{}
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())

By("verify running status of pod")
g.Expect(len(pod.Status.ContainerStatuses)).Should(Equal(1))
g.Expect(pod.Status.ContainerStatuses[0].State.Running).Should(Not(BeNil()))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())
WaitForPod(crd.Name)
}

Expect(k8sClient.Delete(ctx, &crd)).Should(Succeed())
Expand Down
11 changes: 9 additions & 2 deletions controllers/common_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,11 @@ func DeployCustomPVC(name string, targetNamespace string, customFunc func(candid
return &pvc, &createdPvc
}

func WaitForPod(crName string, iPods ...int32) {
func WaitForPod(crName string) {
WaitForPods(crName, 0)
}

func WaitForPods(crName string, iPods ...int32) {
ssKey := types.NamespacedName{
Name: namer.CrToSS(crName),
Namespace: defaultNamespace,
Expand All @@ -826,12 +830,15 @@ func WaitForPod(crName string, iPods ...int32) {
currentSS := &appsv1.StatefulSet{}

for podOrdinal := range iPods {
podKey := types.NamespacedName{Name: namer.CrToSS(crName) + "-" + strconv.Itoa(podOrdinal), Namespace: defaultNamespace}
podKey := types.NamespacedName{Name: namer.CrToSSOrdinal(crName, podOrdinal), Namespace: defaultNamespace}
pod := &corev1.Pod{}
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, ssKey, currentSS)).Should(Succeed())
g.Expect(k8sClient.Get(ctx, podKey, pod)).Should(Succeed())
g.Expect(len(pod.Status.ContainerStatuses)).Should(Equal(1))
if verbose {
fmt.Printf("container status for pod %s in %v\n", podKey.Name, pod.Status.ContainerStatuses[0])
}
g.Expect(pod.Status.ContainerStatuses[0].State.Running).ShouldNot(BeNil())
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/namer/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func CrToSS(crName string) string {
return crName + "-ss"
}

func CrToSSOrdinal(crName string, ordinal int) string {
return CrToSS(crName) + "-" + strconv.Itoa(ordinal)
}

func SSToCr(ssName string) string {
return strings.TrimSuffix(ssName, "-ss")
}
Expand Down

0 comments on commit 91ea49a

Please sign in to comment.