mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #5256 from jszczepkowski/podspec-host
Implemented writing Host in Pod.Spec during binding.
This commit is contained in:
commit
1a75c8843c
@ -172,9 +172,10 @@ func (r *BindingREST) setPodHostTo(ctx api.Context, podID, oldMachine, machine s
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unexpected object: %#v", obj)
|
return nil, fmt.Errorf("unexpected object: %#v", obj)
|
||||||
}
|
}
|
||||||
if pod.Status.Host != oldMachine {
|
if pod.Spec.Host != oldMachine || pod.Status.Host != oldMachine {
|
||||||
return nil, fmt.Errorf("pod %v is already assigned to host %v", pod.Name, pod.Status.Host)
|
return nil, fmt.Errorf("pod %v is already assigned to host %v or %v", pod.Name, pod.Spec.Host, pod.Status.Host)
|
||||||
}
|
}
|
||||||
|
pod.Spec.Host = machine
|
||||||
pod.Status.Host = machine
|
pod.Status.Host = machine
|
||||||
finalPod = pod
|
finalPod = pod
|
||||||
return pod, nil
|
return pod, nil
|
||||||
|
@ -1090,28 +1090,28 @@ func TestEtcdCreateBinding(t *testing.T) {
|
|||||||
"badKind": {
|
"badKind": {
|
||||||
binding: api.Binding{
|
binding: api.Binding{
|
||||||
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
||||||
Target: api.ObjectReference{Name: "machine", Kind: "unknown"},
|
Target: api.ObjectReference{Name: "machine1", Kind: "unknown"},
|
||||||
},
|
},
|
||||||
errOK: func(err error) bool { return errors.IsInvalid(err) },
|
errOK: func(err error) bool { return errors.IsInvalid(err) },
|
||||||
},
|
},
|
||||||
"emptyKind": {
|
"emptyKind": {
|
||||||
binding: api.Binding{
|
binding: api.Binding{
|
||||||
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
||||||
Target: api.ObjectReference{Name: "machine"},
|
Target: api.ObjectReference{Name: "machine2"},
|
||||||
},
|
},
|
||||||
errOK: func(err error) bool { return err == nil },
|
errOK: func(err error) bool { return err == nil },
|
||||||
},
|
},
|
||||||
"kindNode": {
|
"kindNode": {
|
||||||
binding: api.Binding{
|
binding: api.Binding{
|
||||||
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
||||||
Target: api.ObjectReference{Name: "machine", Kind: "Node"},
|
Target: api.ObjectReference{Name: "machine3", Kind: "Node"},
|
||||||
},
|
},
|
||||||
errOK: func(err error) bool { return err == nil },
|
errOK: func(err error) bool { return err == nil },
|
||||||
},
|
},
|
||||||
"kindMinion": {
|
"kindMinion": {
|
||||||
binding: api.Binding{
|
binding: api.Binding{
|
||||||
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault, Name: "foo"},
|
||||||
Target: api.ObjectReference{Name: "machine", Kind: "Minion"},
|
Target: api.ObjectReference{Name: "machine4", Kind: "Minion"},
|
||||||
},
|
},
|
||||||
errOK: func(err error) bool { return err == nil },
|
errOK: func(err error) bool { return err == nil },
|
||||||
},
|
},
|
||||||
@ -1124,13 +1124,22 @@ func TestEtcdCreateBinding(t *testing.T) {
|
|||||||
},
|
},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
fakeClient.Set("/registry/nodes/machine/boundpods", runtime.EncodeOrDie(latest.Codec, &api.BoundPods{}), 0)
|
path := fmt.Sprintf("/registry/nodes/%v/boundpods", test.binding.Target.Name)
|
||||||
|
fakeClient.Set(path, runtime.EncodeOrDie(latest.Codec, &api.BoundPods{}), 0)
|
||||||
if _, err := registry.Create(ctx, validNewPod()); err != nil {
|
if _, err := registry.Create(ctx, validNewPod()); err != nil {
|
||||||
t.Fatalf("%s: unexpected error: %v", k, err)
|
t.Fatalf("%s: unexpected error: %v", k, err)
|
||||||
}
|
}
|
||||||
fakeClient.Set("/registry/nodes/machine/boundpods", runtime.EncodeOrDie(latest.Codec, &api.BoundPods{}), 0)
|
fakeClient.Set(path, runtime.EncodeOrDie(latest.Codec, &api.BoundPods{}), 0)
|
||||||
if _, err := bindingRegistry.Create(ctx, &test.binding); !test.errOK(err) {
|
if _, err := bindingRegistry.Create(ctx, &test.binding); !test.errOK(err) {
|
||||||
t.Errorf("%s: unexpected error: %v", k, err)
|
t.Errorf("%s: unexpected error: %v", k, err)
|
||||||
|
} else if err == nil {
|
||||||
|
// If bind succeeded, verify Host field in pod's Spec.
|
||||||
|
pod, err := registry.Get(ctx, validNewPod().ObjectMeta.Name)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%s: unexpected error: %v", k, err)
|
||||||
|
} else if pod.(*api.Pod).Spec.Host != test.binding.Target.Name {
|
||||||
|
t.Errorf("%s: expected: %v, got: %v", k, pod.(*api.Pod).Spec.Host, test.binding.Target.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user