Skip to content

Commit 01d088f

Browse files
authored
Merge pull request #1954 from chengjoey/fix/memory-warnings
fix unnecessary memory-not-equal warnings
2 parents ab7a705 + ebdaeac commit 01d088f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

internal/status/no_warnings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func NoWarningsCondition(resources []runtime.Object, oldCondition *RabbitmqClust
3535
goto assignLastTransitionTime
3636
}
3737

38-
if !equality.Semantic.DeepEqual(resource.Spec.Template.Spec.Containers[0].Resources.Limits["memory"], resource.Spec.Template.Spec.Containers[0].Resources.Requests["memory"]) {
38+
limitMemory := resource.Spec.Template.Spec.Containers[0].Resources.Limits["memory"]
39+
requestMemory := resource.Spec.Template.Spec.Containers[0].Resources.Requests["memory"]
40+
if (!limitMemory.IsZero() && !requestMemory.IsZero()) && !equality.Semantic.DeepEqual(limitMemory, requestMemory) {
3941
condition.Status = corev1.ConditionFalse
4042
condition.Reason = "MemoryRequestAndLimitDifferent"
4143
condition.Message = "RabbitMQ container memory resource request and limit must be equal"

internal/status/no_warnings_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ var _ = Describe("NoWarnings", func() {
6565
})
6666
})
6767

68+
It("is true if the memory limit are not set but the request is set", func() {
69+
sts := noMemoryWarningStatefulSet()
70+
sts.Spec.Template.Spec.Containers[0].Resources.Limits = corev1.ResourceList{}
71+
condition := rabbitmqstatus.NoWarningsCondition([]runtime.Object{sts}, nil)
72+
By("having the correct type", func() {
73+
var conditionType rabbitmqstatus.RabbitmqClusterConditionType = "NoWarnings"
74+
Expect(condition.Type).To(Equal(conditionType))
75+
})
76+
77+
By("having status false and reason message", func() {
78+
Expect(condition.Status).To(Equal(corev1.ConditionTrue))
79+
Expect(condition.Reason).To(Equal("NoWarnings"))
80+
Expect(condition.Message).To(BeEmpty())
81+
})
82+
})
83+
6884
It("is unknown when the StatefulSet does not exist", func() {
6985
var sts *appsv1.StatefulSet = nil
7086
condition := rabbitmqstatus.NoWarningsCondition([]runtime.Object{sts}, nil)

0 commit comments

Comments
 (0)