Skip to content

Commit

Permalink
compare container resource requirements explicitly
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Revin <[email protected]>
  • Loading branch information
nrvnrvn committed Aug 26, 2019
1 parent 7a4625f commit 4a567e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion pkg/controller/redis/object_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ func statefulSetUpdateNeeded(got, want *appsv1.StatefulSet) (needed bool) {
needed = true
}

if !deepContains(got.Spec.Template, want.Spec.Template) || (got.Annotations[hashAnnotationKey] != want.Annotations[hashAnnotationKey]) {
// compare container resources explicitly. They escape the deepContains comparison because of private fields.
if !deepContains(got.Spec.Template, want.Spec.Template) ||
got.Annotations[hashAnnotationKey] != want.Annotations[hashAnnotationKey] ||
!resourceRequirementsEqual(got.Spec.Template.Spec.Containers, want.Spec.Template.Spec.Containers) {
got.Spec.Template = want.Spec.Template
needed = true
}
Expand Down Expand Up @@ -509,3 +512,17 @@ func hashObject(object k8sruntime.Object) (string, error) {

return hex.EncodeToString(hash.Sum(nil)), nil
}

func resourceRequirementsEqual(got, want []corev1.Container) bool {
if len(got) < len(want) {
return false
}

for i := range want {
if !reflect.DeepEqual(got[i].Resources, want[i].Resources) {
return false
}
}

return true
}
2 changes: 1 addition & 1 deletion pkg/controller/redis/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (reconciler *ReconcileRedis) Reconcile(request reconcile.Request) (reconcil
if result, err := reconciler.createOrUpdate(ctx, object, redisObject, options); err != nil {
return reconcile.Result{}, err
} else if result.Requeue {
logger.Info(fmt.Sprintf("Applied %#v", object))
logger.Info(fmt.Sprintf("Applied %T", object))
return result, nil
}
}
Expand Down

0 comments on commit 4a567e5

Please sign in to comment.