mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 22:53:22 +00:00
Implement bindings
This will effectively cause no changes until we remove the assignPod call from CreatePod().
This commit is contained in:
@@ -111,12 +111,17 @@ func (r *Registry) CreatePod(machine string, pod api.Pod) error {
|
||||
return err
|
||||
}
|
||||
// TODO: Until scheduler separation is completed, just assign here.
|
||||
return r.AssignPod(pod.ID, machine)
|
||||
return r.assignPod(pod.ID, machine)
|
||||
}
|
||||
|
||||
// AssignPod assigns the given pod to the given machine.
|
||||
// ApplyBinding implements binding's registry
|
||||
func (r *Registry) ApplyBinding(binding *api.Binding) error {
|
||||
return r.assignPod(binding.PodID, binding.Host)
|
||||
}
|
||||
|
||||
// assignPod assigns the given pod to the given machine.
|
||||
// TODO: hook this up via apiserver, not by calling it from CreatePod().
|
||||
func (r *Registry) AssignPod(podID string, machine string) error {
|
||||
func (r *Registry) assignPod(podID string, machine string) error {
|
||||
podKey := makePodKey(podID)
|
||||
var finalPod *api.Pod
|
||||
err := r.AtomicUpdate(podKey, &api.Pod{}, func(obj interface{}) (interface{}, error) {
|
||||
@@ -124,6 +129,9 @@ func (r *Registry) AssignPod(podID string, machine string) error {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object: %#v", obj)
|
||||
}
|
||||
if pod.DesiredState.Host != "" {
|
||||
return nil, fmt.Errorf("pod %v is already assigned to host %v", pod.ID, pod.DesiredState.Host)
|
||||
}
|
||||
pod.DesiredState.Host = machine
|
||||
finalPod = pod
|
||||
return pod, nil
|
||||
|
Reference in New Issue
Block a user