From 5743cebab0560ba052b21536a0005a5c8d9f1a21 Mon Sep 17 00:00:00 2001 From: dddddai Date: Mon, 25 Jul 2022 12:11:29 +0800 Subject: [PATCH] make sure to update resource status Signed-off-by: dddddai --- pkg/resourceinterpreter/defaultinterpreter/default.go | 8 ++++---- pkg/resourceinterpreter/interpreter.go | 5 ----- pkg/util/helper/job.go | 4 +++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pkg/resourceinterpreter/defaultinterpreter/default.go b/pkg/resourceinterpreter/defaultinterpreter/default.go index 8895a7990..91d3b4a2e 100644 --- a/pkg/resourceinterpreter/defaultinterpreter/default.go +++ b/pkg/resourceinterpreter/defaultinterpreter/default.go @@ -72,7 +72,7 @@ func (e *DefaultInterpreter) HookEnabled(kind schema.GroupVersionKind, operation func (e *DefaultInterpreter) GetReplicas(object *unstructured.Unstructured) (int32, *workv1alpha2.ReplicaRequirements, error) { handler, exist := e.replicaHandlers[object.GroupVersionKind()] if !exist { - return 0, &workv1alpha2.ReplicaRequirements{}, fmt.Errorf("defalut %s interpreter for %q not found", configv1alpha1.InterpreterOperationInterpretReplica, object.GroupVersionKind()) + return 0, &workv1alpha2.ReplicaRequirements{}, fmt.Errorf("default %s interpreter for %q not found", configv1alpha1.InterpreterOperationInterpretReplica, object.GroupVersionKind()) } return handler(object) } @@ -81,7 +81,7 @@ func (e *DefaultInterpreter) GetReplicas(object *unstructured.Unstructured) (int func (e *DefaultInterpreter) ReviseReplica(object *unstructured.Unstructured, replica int64) (*unstructured.Unstructured, error) { handler, exist := e.reviseReplicaHandlers[object.GroupVersionKind()] if !exist { - return nil, fmt.Errorf("defalut %s interpreter for %q not found", configv1alpha1.InterpreterOperationReviseReplica, object.GroupVersionKind()) + return nil, fmt.Errorf("default %s interpreter for %q not found", configv1alpha1.InterpreterOperationReviseReplica, object.GroupVersionKind()) } return handler(object, replica) } @@ -99,7 +99,7 @@ func (e *DefaultInterpreter) Retain(desired *unstructured.Unstructured, observed func (e *DefaultInterpreter) AggregateStatus(object *unstructured.Unstructured, aggregatedStatusItems []workv1alpha2.AggregatedStatusItem) (*unstructured.Unstructured, error) { handler, exist := e.aggregateStatusHandlers[object.GroupVersionKind()] if !exist { - return nil, fmt.Errorf("defalut %s interpreter for %q not found", configv1alpha1.InterpreterOperationAggregateStatus, object.GroupVersionKind()) + return nil, fmt.Errorf("default %s interpreter for %q not found", configv1alpha1.InterpreterOperationAggregateStatus, object.GroupVersionKind()) } return handler(object, aggregatedStatusItems) } @@ -108,7 +108,7 @@ func (e *DefaultInterpreter) AggregateStatus(object *unstructured.Unstructured, func (e *DefaultInterpreter) GetDependencies(object *unstructured.Unstructured) (dependencies []configv1alpha1.DependentObjectReference, err error) { handler, exist := e.dependenciesHandlers[object.GroupVersionKind()] if !exist { - return dependencies, fmt.Errorf("defalut interpreter for operation %s not found", configv1alpha1.InterpreterOperationInterpretDependency) + return dependencies, fmt.Errorf("default interpreter for operation %s not found", configv1alpha1.InterpreterOperationInterpretDependency) } return handler(object) } diff --git a/pkg/resourceinterpreter/interpreter.go b/pkg/resourceinterpreter/interpreter.go index ed5ea2259..06b7aefcb 100644 --- a/pkg/resourceinterpreter/interpreter.go +++ b/pkg/resourceinterpreter/interpreter.go @@ -146,11 +146,6 @@ func (i *customResourceInterpreterImpl) Retain(desired *unstructured.Unstructure func (i *customResourceInterpreterImpl) AggregateStatus(object *unstructured.Unstructured, aggregatedStatusItems []workv1alpha2.AggregatedStatusItem) (*unstructured.Unstructured, error) { klog.V(4).Infof("Begin to aggregate status for object: %v %s/%s.", object.GroupVersionKind(), object.GetNamespace(), object.GetName()) - // If status has not been collected, there is no need to aggregate. - if len(aggregatedStatusItems) == 0 { - return object, nil - } - obj, hookEnabled, err := i.customizedInterpreter.Patch(context.TODO(), &webhook.RequestAttributes{ Operation: configv1alpha1.InterpreterOperationAggregateStatus, Object: object.DeepCopy(), diff --git a/pkg/util/helper/job.go b/pkg/util/helper/job.go index 37cefbfca..8e5255bc8 100644 --- a/pkg/util/helper/job.go +++ b/pkg/util/helper/job.go @@ -67,7 +67,9 @@ func ParsingJobStatus(obj *batchv1.Job, status []workv1alpha2.AggregatedStatusIt }) } - if successfulJobs == len(status) { + // aggregated status can be empty when the binding is just created + // in which case we should not set the job status to complete + if successfulJobs == len(status) && successfulJobs > 0 { newStatus.Conditions = append(newStatus.Conditions, batchv1.JobCondition{ Type: batchv1.JobComplete, Status: corev1.ConditionTrue,