From 769fd347075c3b3ed386c85e9842f83758f763d3 Mon Sep 17 00:00:00 2001 From: sigmabaryon Date: Thu, 6 Apr 2023 09:03:35 +0530 Subject: [PATCH 1/2] Add support for spec.schedulingGates in calcDiffSpec --- .../resources/pods/translate/translator.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/controllers/resources/pods/translate/translator.go b/pkg/controllers/resources/pods/translate/translator.go index 644a0641a..a4caf5c91 100644 --- a/pkg/controllers/resources/pods/translate/translator.go +++ b/pkg/controllers/resources/pods/translate/translator.go @@ -911,6 +911,12 @@ func (t *translator) calcSpecDiff(pObj, vObj *corev1.Pod) *corev1.PodSpec { updatedPodSpec.InitContainers = updatedContainer } + schedulingGatesVal, equal := isPodSpecSchedulingGatesDiff(pObj.Spec.SchedulingGates, vObj.Spec.SchedulingGates) + if !equal { + updatedPodSpec = pObj.Spec.DeepCopy() + updatedPodSpec.SchedulingGates = schedulingGatesVal + } + return updatedPodSpec } @@ -959,3 +965,15 @@ func isInt64Different(i1, i2 *int64) (*int64, bool) { return updated, false } + +func isPodSpecSchedulingGatesDiff(pGates, vGates []corev1.PodSchedulingGate) ([]corev1.PodSchedulingGate, bool) { + if len(vGates) != len(pGates) { + return vGates, false + } + for i, v := range vGates { + if v.Name != pGates[i].Name { + return vGates, false + } + } + return vGates, true +} From 799ea4904adce2c9f596e735835779e718ae9348 Mon Sep 17 00:00:00 2001 From: sigmabaryon Date: Tue, 18 Apr 2023 10:09:47 +0530 Subject: [PATCH 2/2] Review changes: return bool, add a nil check --- .../resources/pods/translate/translator.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/controllers/resources/pods/translate/translator.go b/pkg/controllers/resources/pods/translate/translator.go index a4caf5c91..768c40d4d 100644 --- a/pkg/controllers/resources/pods/translate/translator.go +++ b/pkg/controllers/resources/pods/translate/translator.go @@ -911,10 +911,12 @@ func (t *translator) calcSpecDiff(pObj, vObj *corev1.Pod) *corev1.PodSpec { updatedPodSpec.InitContainers = updatedContainer } - schedulingGatesVal, equal := isPodSpecSchedulingGatesDiff(pObj.Spec.SchedulingGates, vObj.Spec.SchedulingGates) - if !equal { - updatedPodSpec = pObj.Spec.DeepCopy() - updatedPodSpec.SchedulingGates = schedulingGatesVal + isEqual := isPodSpecSchedulingGatesDiff(pObj.Spec.SchedulingGates, vObj.Spec.SchedulingGates) + if !isEqual { + if updatedPodSpec == nil { + updatedPodSpec = pObj.Spec.DeepCopy() + } + updatedPodSpec.SchedulingGates = vObj.Spec.SchedulingGates } return updatedPodSpec @@ -966,14 +968,14 @@ func isInt64Different(i1, i2 *int64) (*int64, bool) { return updated, false } -func isPodSpecSchedulingGatesDiff(pGates, vGates []corev1.PodSchedulingGate) ([]corev1.PodSchedulingGate, bool) { +func isPodSpecSchedulingGatesDiff(pGates, vGates []corev1.PodSchedulingGate) bool { if len(vGates) != len(pGates) { - return vGates, false + return false } for i, v := range vGates { if v.Name != pGates[i].Name { - return vGates, false + return false } } - return vGates, true + return true }