Skip to content

Commit 48bed09

Browse files
author
lamai93
committed
Added test for rotation.
1 parent 6747623 commit 48bed09

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

pkg/deployment/reconcile/plan_builder.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,30 @@ func podNeedsRotation(log zerolog.Logger, p v1.Pod, apiObject metav1.Object, spe
346346
}
347347

348348
// Check resource requirements
349-
// Kubernetes will fill in some default values thus this will always rotate the pod.
350-
// One could come up with something more sophisticated to check if a rotation is needed. (check if the requirements are more than requested and limits are less than requested)
351-
/*if !reflect.DeepEqual(spec.GetServerGroupSpec(group).Resources, k8sutil.GetArangoDBContainerFromPod(&p).Resources) {
349+
if resourcesRequireRotation(spec.GetServerGroupSpec(group).Resources, k8sutil.GetArangoDBContainerFromPod(&p).Resources) {
352350
return true, "Resource Requirements changed"
353-
}*/
351+
}
354352

355353
return false, ""
356354
}
357355

356+
// resourcesRequireRotation returns true if the resource requirements have changed such that a rotation is required
357+
func resourcesRequireRotation(wanted, given v1.ResourceRequirements) bool {
358+
checkList := func(wanted, given v1.ResourceList) bool {
359+
for k, v := range wanted {
360+
if gv, ok := given[k]; !ok {
361+
return true
362+
} else if v.Cmp(gv) != 0 {
363+
return true
364+
}
365+
}
366+
367+
return false
368+
}
369+
370+
return checkList(wanted.Limits, given.Limits) || checkList(wanted.Requests, given.Requests)
371+
}
372+
358373
// normalizeServiceAccountName replaces default with empty string, otherwise returns the input.
359374
func normalizeServiceAccountName(name string) string {
360375
if name == "default" {

0 commit comments

Comments
 (0)