Merge pull request #2145 from lavalamp/eventing2

Add a placeholder to boundPod's SelfLink
This commit is contained in:
Daniel Smith 2014-11-05 13:49:53 -08:00
commit 3bd10d4fb4
3 changed files with 17 additions and 8 deletions

View File

@ -229,23 +229,24 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
if err != nil { if err != nil {
return err return err
} }
// TODO: move this to a watch/rectification loop. boundPod, err := r.boundPodFactory.MakeBoundPod(machine, finalPod)
pod, err := r.boundPodFactory.MakeBoundPod(machine, finalPod)
if err != nil { if err != nil {
return err return err
} }
// Doing the constraint check this way provides atomicity guarantees.
contKey := makeContainerKey(machine) contKey := makeContainerKey(machine)
err = r.AtomicUpdate(contKey, &api.BoundPods{}, func(in runtime.Object) (runtime.Object, error) { err = r.AtomicUpdate(contKey, &api.BoundPods{}, func(in runtime.Object) (runtime.Object, error) {
pods := *in.(*api.BoundPods) boundPodList := in.(*api.BoundPods)
pods.Items = append(pods.Items, *pod) boundPodList.Items = append(boundPodList.Items, *boundPod)
if !constraint.Allowed(pods.Items) { if !constraint.Allowed(boundPodList.Items) {
return nil, fmt.Errorf("The assignment would cause a constraint violation") return nil, fmt.Errorf("The assignment would cause a constraint violation")
} }
return &pods, nil return boundPodList, nil
}) })
if err != nil { if err != nil {
// Put the pod's host back the way it was. This is a terrible hack that // Put the pod's host back the way it was. This is a terrible hack, but
// won't be needed if we convert this to a rectification loop. // can't really be helped, since there's not really a way to do atomic
// multi-object changes in etcd.
if _, err2 := r.setPodHostTo(ctx, podID, machine, ""); err2 != nil { if _, err2 := r.setPodHostTo(ctx, podID, machine, ""); err2 != nil {
glog.Errorf("Stranding pod %v; couldn't clear host after previous error: %v", podID, err2) glog.Errorf("Stranding pod %v; couldn't clear host after previous error: %v", podID, err2)
} }

View File

@ -43,5 +43,9 @@ func (b *BasicBoundPodFactory) MakeBoundPod(machine string, pod *api.Pod) (*api.
for ix, container := range boundPod.Spec.Containers { for ix, container := range boundPod.Spec.Containers {
boundPod.Spec.Containers[ix].Env = append(container.Env, envVars...) boundPod.Spec.Containers[ix].Env = append(container.Env, envVars...)
} }
// Make a dummy self link so that references to this bound pod will work.
// TODO: When kubelets get boundPods from apiserver instead of etcd, then
// the selflink should be generated there.
boundPod.SelfLink = "/api/v1beta1/boundPods/" + boundPod.Name
return boundPod, nil return boundPod, nil
} }

View File

@ -54,6 +54,10 @@ func TestMakeBoundPodNoServices(t *testing.T) {
if pod.Name != "foobar" { if pod.Name != "foobar" {
t.Errorf("Failed to assign ID to pod: %#v", pod.Name) t.Errorf("Failed to assign ID to pod: %#v", pod.Name)
} }
if _, err := api.GetReference(pod); err != nil {
t.Errorf("Unable to get a reference to bound pod: %v", err)
}
} }
func TestMakeBoundPodServices(t *testing.T) { func TestMakeBoundPodServices(t *testing.T) {