mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Add debugging info printing to etcd fake
And make tests pass again.
This commit is contained in:
parent
5cdce0e35a
commit
b7752a86d4
@ -209,7 +209,7 @@ type PodStatus string
|
|||||||
// These are the valid statuses of pods.
|
// These are the valid statuses of pods.
|
||||||
const (
|
const (
|
||||||
// PodWaiting means that we're waiting for the pod to begin running.
|
// PodWaiting means that we're waiting for the pod to begin running.
|
||||||
PodWaiting = "Waiting"
|
PodWaiting PodStatus = "Waiting"
|
||||||
// PodRunning means that the pod is up and running.
|
// PodRunning means that the pod is up and running.
|
||||||
PodRunning PodStatus = "Running"
|
PodRunning PodStatus = "Running"
|
||||||
// PodTerminated means that the pod has stopped.
|
// PodTerminated means that the pod has stopped.
|
||||||
|
@ -212,7 +212,7 @@ type PodStatus string
|
|||||||
// These are the valid statuses of pods.
|
// These are the valid statuses of pods.
|
||||||
const (
|
const (
|
||||||
// PodWaiting means that we're waiting for the pod to begin running.
|
// PodWaiting means that we're waiting for the pod to begin running.
|
||||||
PodWaiting = "Waiting"
|
PodWaiting PodStatus = "Waiting"
|
||||||
// PodRunning means that the pod is up and running.
|
// PodRunning means that the pod is up and running.
|
||||||
PodRunning PodStatus = "Running"
|
PodRunning PodStatus = "Running"
|
||||||
// PodTerminated means that the pod has stopped.
|
// PodTerminated means that the pod has stopped.
|
||||||
|
@ -86,18 +86,11 @@ func makeContainerKey(machine string) string {
|
|||||||
|
|
||||||
// CreatePod creates a pod based on a specification, schedule it onto a specific machine.
|
// CreatePod creates a pod based on a specification, schedule it onto a specific machine.
|
||||||
func (registry *EtcdRegistry) CreatePod(machine string, pod api.Pod) error {
|
func (registry *EtcdRegistry) CreatePod(machine string, pod api.Pod) error {
|
||||||
// TODO: When our client supports it, switch to atomic creates.
|
|
||||||
var pod2 api.Pod
|
|
||||||
err := registry.helper.ExtractObj(makePodKey(pod.ID), &pod2, false)
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("a pod named %s already exists (%#v)", pod.ID, pod2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set status to "Waiting".
|
// Set status to "Waiting".
|
||||||
pod.CurrentState.Status = api.PodWaiting
|
pod.CurrentState.Status = api.PodWaiting
|
||||||
pod.CurrentState.Host = ""
|
pod.CurrentState.Host = ""
|
||||||
|
|
||||||
err = registry.helper.SetObj(makePodKey(pod.ID), &pod)
|
err := registry.helper.CreateObj(makePodKey(pod.ID), &pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
|
|||||||
|
|
||||||
func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.MakeFakeEtcdClient(t)
|
||||||
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
@ -160,7 +161,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Unexpected non-error")
|
t.Fatalf("Unexpected non-error")
|
||||||
}
|
}
|
||||||
_, err = fakeClient.Get("/registry/pods/foo", false, false)
|
_, err = fakeClient.Get("/registry/pods/foo", false, false)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -173,6 +174,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
|||||||
|
|
||||||
func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.MakeFakeEtcdClient(t)
|
||||||
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
@ -202,7 +204,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := fakeClient.Get("/registry/pods/foo", false, false)
|
resp, err := fakeClient.Get("/registry/pods/foo", false, false)
|
||||||
@ -588,7 +590,7 @@ func TestEtcdCreateController(t *testing.T) {
|
|||||||
|
|
||||||
func TestEtcdCreateControllerAlreadyExisting(t *testing.T) {
|
func TestEtcdCreateControllerAlreadyExisting(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.MakeFakeEtcdClient(t)
|
||||||
fakeClient.Set("/registry/controllers/foo", util.MakeJSONString(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
||||||
|
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateController(api.ReplicationController{
|
err := registry.CreateController(api.ReplicationController{
|
||||||
@ -680,7 +682,7 @@ func TestEtcdCreateService(t *testing.T) {
|
|||||||
|
|
||||||
func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
|
func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.MakeFakeEtcdClient(t)
|
||||||
fakeClient.Set("/registry/services/specs/foo", util.MakeJSONString(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateService(api.Service{
|
err := registry.CreateService(api.Service{
|
||||||
JSONBase: api.JSONBase{ID: "foo"},
|
JSONBase: api.JSONBase{ID: "foo"},
|
||||||
@ -782,7 +784,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) {
|
|||||||
Endpoints: []string{"baz", "bar"},
|
Endpoints: []string{"baz", "bar"},
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeClient.Set("/registry/services/endpoints/foo", util.MakeJSONString(api.Endpoints{}), 0)
|
fakeClient.Set("/registry/services/endpoints/foo", api.EncodeOrDie(api.Endpoints{}), 0)
|
||||||
|
|
||||||
err := registry.UpdateEndpoints(endpoints)
|
err := registry.UpdateEndpoints(endpoints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,6 +87,7 @@ func (f *FakeEtcdClient) generateIndex() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f.ChangeIndex++
|
f.ChangeIndex++
|
||||||
|
f.t.Logf("generating index %v", f.ChangeIndex)
|
||||||
return f.ChangeIndex
|
return f.ChangeIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ func (f *FakeEtcdClient) Get(key string, sort, recursive bool) (*etcd.Response,
|
|||||||
|
|
||||||
func (f *FakeEtcdClient) nodeExists(key string) bool {
|
func (f *FakeEtcdClient) nodeExists(key string) bool {
|
||||||
result, ok := f.Data[key]
|
result, ok := f.Data[key]
|
||||||
return ok && result.R != nil && result.R.Node != nil
|
return ok && result.R != nil && result.R.Node != nil && result.E == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeEtcdClient) setLocked(key, value string, ttl uint64) (*etcd.Response, error) {
|
func (f *FakeEtcdClient) setLocked(key, value string, ttl uint64) (*etcd.Response, error) {
|
||||||
@ -128,6 +129,7 @@ func (f *FakeEtcdClient) setLocked(key, value string, ttl uint64) (*etcd.Respons
|
|||||||
if f.nodeExists(key) {
|
if f.nodeExists(key) {
|
||||||
prevResult := f.Data[key]
|
prevResult := f.Data[key]
|
||||||
createdIndex := prevResult.R.Node.CreatedIndex
|
createdIndex := prevResult.R.Node.CreatedIndex
|
||||||
|
f.t.Logf("updating %v, index %v -> %v", key, createdIndex, i)
|
||||||
result := EtcdResponseWithError{
|
result := EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
@ -141,6 +143,7 @@ func (f *FakeEtcdClient) setLocked(key, value string, ttl uint64) (*etcd.Respons
|
|||||||
return result.R, nil
|
return result.R, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.t.Logf("creating %v, index %v", key, i)
|
||||||
result := EtcdResponseWithError{
|
result := EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
@ -163,6 +166,7 @@ func (f *FakeEtcdClient) Set(key, value string, ttl uint64) (*etcd.Response, err
|
|||||||
|
|
||||||
func (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error) {
|
func (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue string, prevIndex uint64) (*etcd.Response, error) {
|
||||||
if f.Err != nil {
|
if f.Err != nil {
|
||||||
|
f.t.Logf("c&s: returning err %v", f.Err)
|
||||||
return nil, f.Err
|
return nil, f.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,16 +183,19 @@ func (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue
|
|||||||
defer f.Mutex.Unlock()
|
defer f.Mutex.Unlock()
|
||||||
|
|
||||||
if !f.nodeExists(key) {
|
if !f.nodeExists(key) {
|
||||||
|
f.t.Logf("c&s: node doesn't exist")
|
||||||
return nil, EtcdErrorNotFound
|
return nil, EtcdErrorNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
prevNode := f.Data[key].R.Node
|
prevNode := f.Data[key].R.Node
|
||||||
|
|
||||||
if prevValue != "" && prevValue != prevNode.Value {
|
if prevValue != "" && prevValue != prevNode.Value {
|
||||||
|
f.t.Logf("body didn't match")
|
||||||
return nil, EtcdErrorTestFailed
|
return nil, EtcdErrorTestFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
if prevIndex != 0 && prevIndex != prevNode.ModifiedIndex {
|
if prevIndex != 0 && prevIndex != prevNode.ModifiedIndex {
|
||||||
|
f.t.Logf("got index %v but needed %v", prevIndex, prevNode.ModifiedIndex)
|
||||||
return nil, EtcdErrorTestFailed
|
return nil, EtcdErrorTestFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user