From 48f50fd6e40e51924d99f949adc3682932d5773a Mon Sep 17 00:00:00 2001 From: AiRanthem Date: Wed, 4 Sep 2024 17:44:10 +0800 Subject: [PATCH] fix golint and unittest Signed-off-by: AiRanthem --- .../uniteddeployment/uniteddeployment_controller.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/controller/uniteddeployment/uniteddeployment_controller.go b/pkg/controller/uniteddeployment/uniteddeployment_controller.go index 29f36e0aa5..8b15133515 100644 --- a/pkg/controller/uniteddeployment/uniteddeployment_controller.go +++ b/pkg/controller/uniteddeployment/uniteddeployment_controller.go @@ -215,8 +215,15 @@ func (r *ReconcileUnitedDeployment) Reconcile(_ context.Context, request reconci // "apps.kruise.io/subset-reallocate" = "true"; // 2. During this Reconcile, a previously schedulable subset is found to have // just become unschedulable, which means UnschedulableTimestamp is nil - nextReplicas := &map[string]int32{} - reallocate := instance.Annotations[appsv1alpha1.AnnotationReallocate] == "true" + var nextReplicas *map[string]int32 + var reallocate bool + if annotation, ok := instance.Annotations[appsv1alpha1.AnnotationReallocate]; ok { + reallocate = annotation == "true" + } else { + // if the webhook is running, this branch is never entered. + // this branch is reserved for unit tests without a webhook running. + reallocate = true + } for name, subset := range *nameToSubset { if status := subset.Status.UnschedulableStatus; status.Unschedulable && status.UnschedulableTimestamp == nil { klog.InfoS("new unschedulable subset discovered, should reallocate", "name", name) @@ -224,7 +231,7 @@ func (r *ReconcileUnitedDeployment) Reconcile(_ context.Context, request reconci } } if reallocate { - klog.Info("reallocate subset replicas for spec is changed") + klog.Info("reallocate subset replicas for spec is changed or new unschedulable subset found") nextReplicas, err = NewReplicaAllocator(instance).Alloc(nameToSubset) if err != nil { klog.ErrorS(err, "UnitedDeployment specified subset replicas is ineffective", "unitedDeployment", klog.KObj(instance))