예제 #1
0
func (r *Registry) UpdatePod(ctx api.Context, pod *api.Pod) error {
	var podOut api.Pod
	podKey, err := makePodKey(ctx, pod.Name)
	if err != nil {
		return err
	}
	err = r.EtcdHelper.ExtractObj(podKey, &podOut, false)
	if err != nil {
		return err
	}
	scheduled := podOut.Status.Host != ""
	if scheduled {
		pod.Status.Host = podOut.Status.Host
		// If it's already been scheduled, limit the types of updates we'll accept.
		errs := validation.ValidatePodUpdate(pod, &podOut)
		if len(errs) != 0 {
			return errors.NewInvalid("Pod", pod.Name, errs)
		}
	}
	// There's no race with the scheduler, because either this write will fail because the host
	// has been updated, or the host update will fail because this pod has been updated.
	err = r.EtcdHelper.SetObj(podKey, pod)
	if err != nil {
		return err
	}
	if !scheduled {
		// never scheduled, just update.
		return nil
	}

	containerKey := makeBoundPodsKey(podOut.Status.Host)
	return r.AtomicUpdate(containerKey, &api.BoundPods{}, func(in runtime.Object) (runtime.Object, error) {
		boundPods := in.(*api.BoundPods)
		for ix := range boundPods.Items {
			if boundPods.Items[ix].Name == pod.Name {
				boundPods.Items[ix].Spec = pod.Spec
				// sync cpuset and network
				boundPods.Items[ix].Res.Network = pod.Status.Network
				boundPods.Items[ix].Res.CpuSet = pod.Status.CpuSet
				return boundPods, nil
			}
		}
		// This really shouldn't happen
		glog.Warningf("Couldn't find: %s in %#v", pod.Name, boundPods)
		return boundPods, fmt.Errorf("failed to update pod, couldn't find %s in %#v", pod.Name, boundPods)
	})
}
예제 #2
0
// ValidateUpdate is the default update validation for an end user.
func (podStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
	errorList := validation.ValidatePod(obj.(*api.Pod))
	return append(errorList, validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod))...)
}
예제 #3
0
파일: rest.go 프로젝트: vrosnet/kubernetes
// ValidateUpdate is the default update validation for an end user.
func (podStrategy) ValidateUpdate(obj, old runtime.Object) errors.ValidationErrorList {
	return validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod))
}