Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
speed up mk tests - consolidate probe config and default, add test-mk…
Browse files Browse the repository at this point in the history
…-do-fast for ci smoke
  • Loading branch information
gtully authored and brusdev committed Dec 12, 2022
1 parent 53527f5 commit ec71063
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 116 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ test-mk: manifests generate fmt vet envtest ## Run tests against minikube with l
test-mk-do: manifests generate fmt vet envtest generate-deploy ## Run tests against minikube with deployed operator(do)
DEPLOY_OPERATOR=true USE_EXISTING_CLUSTER=true ENABLE_WEBHOOKS=false go test ./controllers/... -test.timeout=40m -ginkgo.slow-spec-threshold=30s -ginkgo.fail-fast -ginkgo.v -ginkgo.label-filter="do"

# useful for CI smoke
test-mk-do-fast: manifests generate fmt vet envtest generate-deploy ## Run tests against minikube with deployed operator(do) and exclude slow
DEPLOY_OPERATOR=true USE_EXISTING_CLUSTER=true ENABLE_WEBHOOKS=false go test ./controllers/... -test.timeout=40m -ginkgo.slow-spec-threshold=30s -ginkgo.fail-fast -ginkgo.v -ginkgo.label-filter="do && !slow"

##@ Build

build: generate fmt vet manifests ## Build manager binary.
Expand Down
86 changes: 82 additions & 4 deletions controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3095,6 +3095,11 @@ var _ = Describe("artemis controller", func() {
By("By creating a crd without Liveness Probe")
ctx := context.Background()
crd := generateArtemisSpec(defaultNamespace)

// whack test defaults
crd.Spec.DeploymentPlan.ReadinessProbe = nil
crd.Spec.DeploymentPlan.LivenessProbe = nil

crd.Spec.AdminUser = "admin"
crd.Spec.AdminPassword = "password"
createdCrd := &brokerv1beta1.ActiveMQArtemis{}
Expand Down Expand Up @@ -4493,6 +4498,64 @@ var _ = Describe("artemis controller", func() {
})
})

Context("time to ready", func() {
It("expect ok ready is fast", func() {

By("By creating a crd without persistence")
ctx := context.Background()
crd := generateArtemisSpec(defaultNamespace)

crd.Spec.DeploymentPlan.LivenessProbe = &corev1.Probe{
InitialDelaySeconds: 1,
PeriodSeconds: 2,
}
crd.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 1,
PeriodSeconds: 2,
}

// about 10s to 1, 30s for 5 on minikube
deploymentSize := 1
crd.Spec.DeploymentPlan.Size = int32(deploymentSize)
crd.Spec.DeploymentPlan.PersistenceEnabled = true

Expect(k8sClient.Create(ctx, &crd)).Should(Succeed())

createdSs := &appsv1.StatefulSet{}
key := types.NamespacedName{Name: namer.CrToSS(crd.Name), Namespace: defaultNamespace}

if os.Getenv("USE_EXISTING_CLUSTER") == "true" {

By("Checking ready on SS")
Eventually(func(g Gomega) {

g.Expect(k8sClient.Get(ctx, key, createdSs)).Should(Succeed())
g.Expect(createdSs.Status.ReadyReplicas).Should(BeEquivalentTo(deploymentSize))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

createdCrd := &brokerv1beta1.ActiveMQArtemis{}
brokerKey := types.NamespacedName{Name: crd.Name, Namespace: crd.Namespace}

By("verifying started via Status")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, brokerKey, createdCrd)).Should(Succeed())
g.Expect(len(createdCrd.Status.PodStatus.Ready)).Should(BeEquivalentTo(deploymentSize))
g.Expect(meta.IsStatusConditionTrue(createdCrd.Status.Conditions, brokerv1beta1.ConfigAppliedConditionType)).Should(BeTrue())
g.Expect(meta.IsStatusConditionTrue(createdCrd.Status.Conditions, brokerv1beta1.DeployedConditionType)).Should(BeTrue())
g.Expect(meta.IsStatusConditionTrue(createdCrd.Status.Conditions, common.ReadyConditionType)).Should(BeTrue())

}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

}
// cleanup
Expect(k8sClient.Delete(ctx, &crd)).Should(Succeed())
By("check it has gone")
Eventually(func() bool {
return checkCrdDeleted(crd.ObjectMeta.Name, defaultNamespace, &crd)
}, timeout, interval).Should(BeTrue())
})
})

Context("With deployed controller - acceptor", func() {

It("Add acceptor via update", func() {
Expand Down Expand Up @@ -5546,6 +5609,7 @@ var _ = Describe("artemis controller", func() {
randString := nameFromTest()
crd := generateOriginalArtemisSpec(defaultNamespace, "br-"+randString)

crd.Spec.DeploymentPlan.ReadinessProbe = nil
crd.Spec.AdminUser = "admin"
crd.Spec.AdminPassword = "secret"
crd.Spec.DeploymentPlan.LivenessProbe = &corev1.Probe{
Expand Down Expand Up @@ -6086,10 +6150,24 @@ var _ = Describe("artemis controller", func() {

})

func generateArtemisSpec(namespace string) brokerv1beta1.ActiveMQArtemis {

func newArtemisSpecWithFastPropes() brokerv1beta1.ActiveMQArtemisSpec {
spec := brokerv1beta1.ActiveMQArtemisSpec{}

// sensible fast defaults for tests against existing cluster
spec.DeploymentPlan.LivenessProbe = &corev1.Probe{
InitialDelaySeconds: 1,
PeriodSeconds: 2,
}
spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 1,
PeriodSeconds: 2,
}

return spec
}

func generateArtemisSpec(namespace string) brokerv1beta1.ActiveMQArtemis {

toCreate := brokerv1beta1.ActiveMQArtemis{
TypeMeta: metav1.TypeMeta{
Kind: "ActiveMQArtemis",
Expand All @@ -6099,15 +6177,15 @@ func generateArtemisSpec(namespace string) brokerv1beta1.ActiveMQArtemis {
Name: nameFromTest(),
Namespace: namespace,
},
Spec: spec,
Spec: newArtemisSpecWithFastPropes(),
}

return toCreate
}

func generateOriginalArtemisSpec(namespace string, name string) *brokerv1beta1.ActiveMQArtemis {

spec := brokerv1beta1.ActiveMQArtemisSpec{}
spec := newArtemisSpecWithFastPropes()

toCreate := brokerv1beta1.ActiveMQArtemis{
TypeMeta: metav1.TypeMeta{
Expand Down
53 changes: 36 additions & 17 deletions controllers/activemqartemis_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,20 @@ func configureLivenessProbe(container *corev1.Container, probeFromCr *corev1.Pro
return livenessProbe
}

var command = []string{
"/bin/bash",
"-c",
"/opt/amq/bin/readinessProbe.sh",
}

var betterCommand = []string{
"/bin/bash",
"-c",
"/opt/amq/bin/readinessProbe.sh",
"1", // retries/count - so we get fast feedback and can configure via the Probe
// "1", sleep seconds not applicable with 1 retry
}

func configureReadinessProbe(container *corev1.Container, probeFromCr *corev1.Probe) *corev1.Probe {

var readinessProbe *corev1.Probe = container.ReadinessProbe
Expand All @@ -1995,32 +2009,37 @@ func configureReadinessProbe(container *corev1.Container, probeFromCr *corev1.Pr
if probeFromCr != nil {
applyNonDefaultedValues(readinessProbe, probeFromCr)
if probeFromCr.Exec == nil && probeFromCr.HTTPGet == nil && probeFromCr.TCPSocket == nil {
//add the default readiness check if none
clog.V(1).Info("Using user provided readiness Probe")
readinessProbe.ProbeHandler = corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"/bin/bash",
"-c",
"/opt/amq/bin/readinessProbe.sh",
clog.V(1).Info("adding default handler to user provided readiness Probe")

// respect existing command where already deployed
if readinessProbe.ProbeHandler.Exec != nil && reflect.DeepEqual(readinessProbe.ProbeHandler.Exec.Command, command) {
// leave it be so we don't force a reconcile
} else {
// upgrade to betterCommand!
readinessProbe.ProbeHandler = corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: betterCommand,
},
},
}
}
} else {
readinessProbe.ProbeHandler = probeFromCr.ProbeHandler
}
} else {
clog.V(1).Info("Creating Default readiness Probe")
clog.V(1).Info("vreating default readiness Probe")
readinessProbe.InitialDelaySeconds = defaultLivenessProbeInitialDelay
readinessProbe.TimeoutSeconds = 5
readinessProbe.ProbeHandler = corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"/bin/bash",
"-c",
"/opt/amq/bin/readinessProbe.sh",

// respect existing command where already deployed
if readinessProbe.ProbeHandler.Exec != nil && reflect.DeepEqual(readinessProbe.ProbeHandler.Exec.Command, command) {
// leave it be so we don't force a reconcile
} else {
// upgrade to betterCommand!
readinessProbe.ProbeHandler = corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: betterCommand,
},
},
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("Address controller DO", Label("do"), func() {

Context("Address test", func() {

It("Deploy CR with size 5 (pods)", func() {
It("Deploy CR with size 5 (pods)", Label("slow"), func() {

ctx := context.Background()

Expand All @@ -61,15 +61,6 @@ var _ = Describe("Address controller DO", Label("do"), func() {

brokerCrd.Spec.DeploymentPlan.Size = 5

brokerCrd.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 5,
}
brokerCrd.Spec.DeploymentPlan.LivenessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 5,
}

if os.Getenv("USE_EXISTING_CLUSTER") == "true" {

Expect(k8sClient.Create(ctx, &brokerCrd)).Should(Succeed())
Expand Down Expand Up @@ -202,14 +193,10 @@ var _ = Describe("Address controller DO", Label("do"), func() {

Context("Address delete and scale down", func() {

It("Scale down, verify RemoveFromBrokerOnDelete", func() {
It("Scale down, verify RemoveFromBrokerOnDelete", Label("slow"), func() {

ctx := context.Background()
crd := generateArtemisSpec(defaultNamespace)
crd.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 1,
PeriodSeconds: 5,
}
crd.Spec.DeploymentPlan.Size = 2

By("By deploying address cr for a2 for this broker in advance")
Expand Down Expand Up @@ -377,10 +364,6 @@ var _ = Describe("Address controller DO", Label("do"), func() {

ctx := context.Background()
crd := generateArtemisSpec(defaultNamespace)
crd.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
}
crd.Spec.DeploymentPlan.Size = 1
crd.Spec.DeploymentPlan.JolokiaAgentEnabled = true

Expand Down Expand Up @@ -434,10 +417,6 @@ var _ = Describe("Address controller DO", Label("do"), func() {

ctx := context.Background()
crd := generateArtemisSpec(defaultNamespace)
crd.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
}
crd.Spec.DeploymentPlan.Size = 1
crd.Spec.DeploymentPlan.JolokiaAgentEnabled = true

Expand Down Expand Up @@ -493,10 +472,6 @@ var _ = Describe("Address controller DO", Label("do"), func() {

ctx := context.Background()
crd := generateArtemisSpec(defaultNamespace)
crd.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
}
crd.Spec.DeploymentPlan.Size = 1
crd.Spec.DeploymentPlan.JolokiaAgentEnabled = true

Expand Down Expand Up @@ -548,30 +523,18 @@ var _ = Describe("Address controller DO", Label("do"), func() {
k8sClient.Delete(ctx, &crd)
})

It("address creation with multiple ApplyToCrNames", func() {
It("address creation with multiple ApplyToCrNames", Label("slow"), func() {

ctx := context.Background()
crd0 := generateOriginalArtemisSpec(defaultNamespace, "broker")
crd0.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
}
crd0.Spec.DeploymentPlan.Size = 1
crd0.Spec.DeploymentPlan.JolokiaAgentEnabled = true

crd1 := generateOriginalArtemisSpec(defaultNamespace, "broker1")
crd1.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
}
crd1.Spec.DeploymentPlan.Size = 1
crd1.Spec.DeploymentPlan.JolokiaAgentEnabled = true

crd2 := generateOriginalArtemisSpec(defaultNamespace, "broker2")
crd2.Spec.DeploymentPlan.ReadinessProbe = &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
}
crd2.Spec.DeploymentPlan.Size = 1
crd2.Spec.DeploymentPlan.JolokiaAgentEnabled = true

Expand Down
Loading

0 comments on commit ec71063

Please sign in to comment.