diff --git a/internal/status/no_warnings.go b/internal/status/no_warnings.go index a4e18a24a..335fb6514 100644 --- a/internal/status/no_warnings.go +++ b/internal/status/no_warnings.go @@ -35,7 +35,9 @@ func NoWarningsCondition(resources []runtime.Object, oldCondition *RabbitmqClust goto assignLastTransitionTime } - if !equality.Semantic.DeepEqual(resource.Spec.Template.Spec.Containers[0].Resources.Limits["memory"], resource.Spec.Template.Spec.Containers[0].Resources.Requests["memory"]) { + limitMemory := resource.Spec.Template.Spec.Containers[0].Resources.Limits["memory"] + requestMemory := resource.Spec.Template.Spec.Containers[0].Resources.Requests["memory"] + if (!limitMemory.IsZero() && !requestMemory.IsZero()) && !equality.Semantic.DeepEqual(limitMemory, requestMemory) { condition.Status = corev1.ConditionFalse condition.Reason = "MemoryRequestAndLimitDifferent" condition.Message = "RabbitMQ container memory resource request and limit must be equal" diff --git a/internal/status/no_warnings_test.go b/internal/status/no_warnings_test.go index d5aacf1d0..74a06a68f 100644 --- a/internal/status/no_warnings_test.go +++ b/internal/status/no_warnings_test.go @@ -65,6 +65,22 @@ var _ = Describe("NoWarnings", func() { }) }) + It("is true if the memory limit are not set but the request is set", func() { + sts := noMemoryWarningStatefulSet() + sts.Spec.Template.Spec.Containers[0].Resources.Limits = corev1.ResourceList{} + condition := rabbitmqstatus.NoWarningsCondition([]runtime.Object{sts}, nil) + By("having the correct type", func() { + var conditionType rabbitmqstatus.RabbitmqClusterConditionType = "NoWarnings" + Expect(condition.Type).To(Equal(conditionType)) + }) + + By("having status false and reason message", func() { + Expect(condition.Status).To(Equal(corev1.ConditionTrue)) + Expect(condition.Reason).To(Equal("NoWarnings")) + Expect(condition.Message).To(BeEmpty()) + }) + }) + It("is unknown when the StatefulSet does not exist", func() { var sts *appsv1.StatefulSet = nil condition := rabbitmqstatus.NoWarningsCondition([]runtime.Object{sts}, nil)