diff --git a/pkg/registry/core/pod/storage/storage.go b/pkg/registry/core/pod/storage/storage.go index 5017395f231..91dff4a0fa2 100644 --- a/pkg/registry/core/pod/storage/storage.go +++ b/pkg/registry/core/pod/storage/storage.go @@ -186,10 +186,10 @@ func (r *BindingREST) Create(ctx context.Context, name string, obj runtime.Objec return } -// setPodHostAndAnnotations sets the given pod's host to 'machine' if and only if it was -// previously 'oldMachine' and merges the provided annotations with those of the pod. +// setPodHostAndAnnotations sets the given pod's host to 'machine' if and only if +// the pod is unassigned and merges the provided annotations with those of the pod. // Returns the current state of the pod, or an error. -func (r *BindingREST) setPodHostAndAnnotations(ctx context.Context, podUID types.UID, podResourceVersion, podID, oldMachine, machine string, annotations map[string]string, dryRun bool) (finalPod *api.Pod, err error) { +func (r *BindingREST) setPodHostAndAnnotations(ctx context.Context, podUID types.UID, podResourceVersion, podID, machine string, annotations map[string]string, dryRun bool) (finalPod *api.Pod, err error) { podKey, err := r.store.KeyFunc(ctx, podID) if err != nil { return nil, err @@ -214,7 +214,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx context.Context, podUID types if pod.DeletionTimestamp != nil { return nil, fmt.Errorf("pod %s is being deleted, cannot be assigned to a host", pod.Name) } - if pod.Spec.NodeName != oldMachine { + if pod.Spec.NodeName != "" { return nil, fmt.Errorf("pod %v is already assigned to node %q", pod.Name, pod.Spec.NodeName) } pod.Spec.NodeName = machine @@ -236,7 +236,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx context.Context, podUID types // assignPod assigns the given pod to the given machine. func (r *BindingREST) assignPod(ctx context.Context, podUID types.UID, podResourceVersion, podID string, machine string, annotations map[string]string, dryRun bool) (err error) { - if _, err = r.setPodHostAndAnnotations(ctx, podUID, podResourceVersion, podID, "", machine, annotations, dryRun); err != nil { + if _, err = r.setPodHostAndAnnotations(ctx, podUID, podResourceVersion, podID, machine, annotations, dryRun); err != nil { err = storeerr.InterpretGetError(err, api.Resource("pods"), podID) err = storeerr.InterpretUpdateError(err, api.Resource("pods"), podID) if _, ok := err.(*errors.StatusError); !ok {