Merge pull request #2788 from smarterclayton/roundtrip_node_nodelist

Rename Minions -> Nodes internally
This commit is contained in:
Daniel Smith
2014-12-10 11:12:15 -08:00
52 changed files with 577 additions and 332 deletions

View File

@@ -574,26 +574,26 @@ func makeMinionKey(minionID string) string {
return "/registry/minions/" + minionID
}
func (r *Registry) ListMinions(ctx api.Context) (*api.MinionList, error) {
minions := &api.MinionList{}
func (r *Registry) ListMinions(ctx api.Context) (*api.NodeList, error) {
minions := &api.NodeList{}
err := r.ExtractToList("/registry/minions", minions)
return minions, err
}
func (r *Registry) CreateMinion(ctx api.Context, minion *api.Minion) error {
func (r *Registry) CreateMinion(ctx api.Context, minion *api.Node) error {
// TODO: Add some validations.
err := r.CreateObj(makeMinionKey(minion.Name), minion, 0)
return etcderr.InterpretCreateError(err, "minion", minion.Name)
}
func (r *Registry) UpdateMinion(ctx api.Context, minion *api.Minion) error {
func (r *Registry) UpdateMinion(ctx api.Context, minion *api.Node) error {
// TODO: Add some validations.
err := r.SetObj(makeMinionKey(minion.Name), minion)
return etcderr.InterpretUpdateError(err, "minion", minion.Name)
}
func (r *Registry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) {
var minion api.Minion
func (r *Registry) GetMinion(ctx api.Context, minionID string) (*api.Node, error) {
var minion api.Node
key := makeMinionKey(minionID)
err := r.ExtractObj(key, &minion, false)
if err != nil {

View File

@@ -1579,12 +1579,12 @@ func TestEtcdListMinions(t *testing.T) {
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Minion{
Value: runtime.EncodeOrDie(latest.Codec, &api.Node{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}),
},
{
Value: runtime.EncodeOrDie(latest.Codec, &api.Minion{
Value: runtime.EncodeOrDie(latest.Codec, &api.Node{
ObjectMeta: api.ObjectMeta{Name: "bar"},
}),
},
@@ -1608,7 +1608,7 @@ func TestEtcdCreateMinion(t *testing.T) {
ctx := api.NewContext()
fakeClient := tools.NewFakeEtcdClient(t)
registry := NewTestEtcdRegistry(fakeClient)
err := registry.CreateMinion(ctx, &api.Minion{
err := registry.CreateMinion(ctx, &api.Node{
ObjectMeta: api.ObjectMeta{Name: "foo"},
})
if err != nil {
@@ -1620,7 +1620,7 @@ func TestEtcdCreateMinion(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
var minion api.Minion
var minion api.Node
err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &minion)
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -1634,7 +1634,7 @@ func TestEtcdCreateMinion(t *testing.T) {
func TestEtcdGetMinion(t *testing.T) {
ctx := api.NewContext()
fakeClient := tools.NewFakeEtcdClient(t)
fakeClient.Set("/registry/minions/foo", runtime.EncodeOrDie(latest.Codec, &api.Minion{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
fakeClient.Set("/registry/minions/foo", runtime.EncodeOrDie(latest.Codec, &api.Node{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
registry := NewTestEtcdRegistry(fakeClient)
minion, err := registry.GetMinion(ctx, "foo")
if err != nil {

View File

@@ -36,7 +36,7 @@ func NewHealthyRegistry(delegate Registry, client client.KubeletHealthChecker) R
}
}
func (r *HealthyRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) {
func (r *HealthyRegistry) GetMinion(ctx api.Context, minionID string) (*api.Node, error) {
minion, err := r.delegate.GetMinion(ctx, minionID)
if minion == nil {
return nil, ErrDoesNotExist
@@ -58,16 +58,16 @@ func (r *HealthyRegistry) DeleteMinion(ctx api.Context, minionID string) error {
return r.delegate.DeleteMinion(ctx, minionID)
}
func (r *HealthyRegistry) CreateMinion(ctx api.Context, minion *api.Minion) error {
func (r *HealthyRegistry) CreateMinion(ctx api.Context, minion *api.Node) error {
return r.delegate.CreateMinion(ctx, minion)
}
func (r *HealthyRegistry) UpdateMinion(ctx api.Context, minion *api.Minion) error {
func (r *HealthyRegistry) UpdateMinion(ctx api.Context, minion *api.Node) error {
return r.delegate.UpdateMinion(ctx, minion)
}
func (r *HealthyRegistry) ListMinions(ctx api.Context) (currentMinions *api.MinionList, err error) {
result := &api.MinionList{}
func (r *HealthyRegistry) ListMinions(ctx api.Context) (currentMinions *api.NodeList, err error) {
result := &api.NodeList{}
list, err := r.delegate.ListMinions(ctx)
if err != nil {
return result, err

View File

@@ -45,7 +45,7 @@ func TestBasicDelegation(t *testing.T) {
if !reflect.DeepEqual(list, &mockMinionRegistry.Minions) {
t.Errorf("Expected %v, Got %v", mockMinionRegistry.Minions, list)
}
err = healthy.CreateMinion(ctx, &api.Minion{
err = healthy.CreateMinion(ctx, &api.Node{
ObjectMeta: api.ObjectMeta{Name: "foo"},
})
if err != nil {

View File

@@ -20,9 +20,9 @@ import "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
// MinionRegistry is an interface for things that know how to store minions.
type Registry interface {
ListMinions(ctx api.Context) (*api.MinionList, error)
CreateMinion(ctx api.Context, minion *api.Minion) error
UpdateMinion(ctx api.Context, minion *api.Minion) error
GetMinion(ctx api.Context, minionID string) (*api.Minion, error)
ListMinions(ctx api.Context) (*api.NodeList, error)
CreateMinion(ctx api.Context, minion *api.Node) error
UpdateMinion(ctx api.Context, minion *api.Node) error
GetMinion(ctx api.Context, minionID string) (*api.Node, error)
DeleteMinion(ctx api.Context, minionID string) error
}

View File

@@ -47,7 +47,7 @@ var ErrDoesNotExist = errors.New("The requested resource does not exist.")
var ErrNotHealty = errors.New("The requested minion is not healthy.")
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
minion, ok := obj.(*api.Minion)
minion, ok := obj.(*api.Node)
if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj)
}
@@ -93,11 +93,11 @@ func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Obj
}
func (rs *REST) New() runtime.Object {
return &api.Minion{}
return &api.Node{}
}
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RESTResult, error) {
minion, ok := obj.(*api.Minion)
minion, ok := obj.(*api.Node)
if !ok {
return nil, fmt.Errorf("not a minion: %#v", obj)
}
@@ -121,8 +121,8 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
}), nil
}
func (rs *REST) toApiMinion(name string) *api.Minion {
return &api.Minion{ObjectMeta: api.ObjectMeta{Name: name}}
func (rs *REST) toApiMinion(name string) *api.Node {
return &api.Node{ObjectMeta: api.ObjectMeta{Name: name}}
}
// ResourceLocation returns a URL to which one can send traffic for the specified minion.

View File

@@ -28,28 +28,28 @@ import (
func TestMinionREST(t *testing.T) {
ms := NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
ctx := api.NewContext()
if obj, err := ms.Get(ctx, "foo"); err != nil || obj.(*api.Minion).Name != "foo" {
if obj, err := ms.Get(ctx, "foo"); err != nil || obj.(*api.Node).Name != "foo" {
t.Errorf("missing expected object")
}
if obj, err := ms.Get(ctx, "bar"); err != nil || obj.(*api.Minion).Name != "bar" {
if obj, err := ms.Get(ctx, "bar"); err != nil || obj.(*api.Node).Name != "bar" {
t.Errorf("missing expected object")
}
if _, err := ms.Get(ctx, "baz"); err != ErrDoesNotExist {
t.Errorf("has unexpected object")
}
c, err := ms.Create(ctx, &api.Minion{ObjectMeta: api.ObjectMeta{Name: "baz"}})
c, err := ms.Create(ctx, &api.Node{ObjectMeta: api.ObjectMeta{Name: "baz"}})
if err != nil {
t.Errorf("insert failed")
}
obj := <-c
if !api.HasObjectMetaSystemFieldValues(&obj.Object.(*api.Minion).ObjectMeta) {
if !api.HasObjectMetaSystemFieldValues(&obj.Object.(*api.Node).ObjectMeta) {
t.Errorf("storage did not populate object meta field values")
}
if m, ok := obj.Object.(*api.Minion); !ok || m.Name != "baz" {
if m, ok := obj.Object.(*api.Node); !ok || m.Name != "baz" {
t.Errorf("insert return value was weird: %#v", obj)
}
if obj, err := ms.Get(ctx, "baz"); err != nil || obj.(*api.Minion).Name != "baz" {
if obj, err := ms.Get(ctx, "baz"); err != nil || obj.(*api.Node).Name != "baz" {
t.Errorf("insert didn't actually insert")
}
@@ -74,14 +74,14 @@ func TestMinionREST(t *testing.T) {
if err != nil {
t.Errorf("got error calling List")
}
expect := []api.Minion{
expect := []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: "foo"},
}, {
ObjectMeta: api.ObjectMeta{Name: "baz"},
},
}
nodeList := list.(*api.MinionList)
nodeList := list.(*api.NodeList)
if len(expect) != len(nodeList.Items) || !contains(nodeList, "foo") || !contains(nodeList, "baz") {
t.Errorf("Unexpected list value: %#v", list)
}
@@ -97,12 +97,12 @@ func TestMinionStorageWithHealthCheck(t *testing.T) {
ms := NewREST(&minionHealthRegistry)
ctx := api.NewContext()
c, err := ms.Create(ctx, &api.Minion{ObjectMeta: api.ObjectMeta{Name: "m1"}})
c, err := ms.Create(ctx, &api.Node{ObjectMeta: api.ObjectMeta{Name: "m1"}})
if err != nil {
t.Errorf("insert failed")
}
result := <-c
if m, ok := result.Object.(*api.Minion); !ok || m.Name != "m1" {
if m, ok := result.Object.(*api.Node); !ok || m.Name != "m1" {
t.Errorf("insert return value was weird: %#v", result)
}
if _, err := ms.Get(ctx, "m1"); err == nil {
@@ -110,7 +110,7 @@ func TestMinionStorageWithHealthCheck(t *testing.T) {
}
}
func contains(nodes *api.MinionList, nodeID string) bool {
func contains(nodes *api.NodeList, nodeID string) bool {
for _, node := range nodes.Items {
if node.Name == nodeID {
return true
@@ -126,7 +126,7 @@ func TestMinionStorageInvalidUpdate(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
minion, ok := obj.(*api.Minion)
minion, ok := obj.(*api.Node)
if !ok {
t.Fatalf("Object is not a minion: %#v", obj)
}
@@ -143,7 +143,7 @@ func TestMinionStorageValidUpdate(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
minion, ok := obj.(*api.Minion)
minion, ok := obj.(*api.Node)
if !ok {
t.Fatalf("Object is not a minion: %#v", obj)
}
@@ -161,7 +161,7 @@ func TestMinionStorageValidatesCreate(t *testing.T) {
ctx := api.NewContext()
validSelector := map[string]string{"a": "b"}
invalidSelector := map[string]string{"NoUppercaseOrSpecialCharsLike=Equals": "b"}
failureCases := map[string]api.Minion{
failureCases := map[string]api.Node{
"zero-length Name": {
ObjectMeta: api.ObjectMeta{
Name: "",

View File

@@ -60,7 +60,7 @@ type REST struct {
podInfoGetter client.PodInfoGetter
podPollPeriod time.Duration
registry Registry
minions client.MinionInterface
nodes client.NodeInterface
ipCache ipCache
clock clock
}
@@ -70,7 +70,7 @@ type RESTConfig struct {
PodCache client.PodInfoGetter
PodInfoGetter client.PodInfoGetter
Registry Registry
Minions client.MinionInterface
Nodes client.NodeInterface
}
// NewREST returns a new REST.
@@ -81,7 +81,7 @@ func NewREST(config *RESTConfig) *REST {
podInfoGetter: config.PodInfoGetter,
podPollPeriod: time.Second * 10,
registry: config.Registry,
minions: config.Minions,
nodes: config.Nodes,
ipCache: ipCache{},
clock: realClock{},
}
@@ -125,7 +125,7 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
}
if rs.podCache != nil || rs.podInfoGetter != nil {
rs.fillPodInfo(pod)
status, err := getPodStatus(pod, rs.minions)
status, err := getPodStatus(pod, rs.nodes)
if err != nil {
return pod, err
}
@@ -169,7 +169,7 @@ func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Obj
for i := range pods.Items {
pod := &pods.Items[i]
rs.fillPodInfo(pod)
status, err := getPodStatus(pod, rs.minions)
status, err := getPodStatus(pod, rs.nodes)
if err != nil {
return pod, err
}
@@ -275,26 +275,19 @@ func getInstanceIPFromCloud(cloud cloudprovider.Interface, host string) string {
return addr.String()
}
func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodPhase, error) {
func getPodStatus(pod *api.Pod, nodes client.NodeInterface) (api.PodPhase, error) {
if pod.Status.Host == "" {
return api.PodPending, nil
}
if minions != nil {
res, err := minions.List()
if nodes != nil {
_, err := nodes.Get(pod.Status.Host)
if err != nil {
if errors.IsNotFound(err) {
return api.PodFailed, nil
}
glog.Errorf("Error listing minions: %v", err)
return "", err
}
found := false
for _, minion := range res.Items {
if minion.Name == pod.Status.Host {
found = true
break
}
}
if !found {
return api.PodFailed, nil
}
} else {
glog.Errorf("Unexpected missing minion interface, status may be in-accurate")
}

View File

@@ -370,8 +370,8 @@ func TestGetPodCloud(t *testing.T) {
func TestMakePodStatus(t *testing.T) {
fakeClient := client.Fake{
MinionsList: api.MinionList{
Items: []api.Minion{
MinionsList: api.NodeList{
Items: []api.Node{
{
ObjectMeta: api.ObjectMeta{Name: "machine"},
},
@@ -499,7 +499,7 @@ func TestMakePodStatus(t *testing.T) {
},
}
for _, test := range tests {
if status, err := getPodStatus(test.pod, fakeClient.Minions()); status != test.status {
if status, err := getPodStatus(test.pod, fakeClient.Nodes()); status != test.status {
t.Errorf("In test %s, expected %v, got %v", test.test, test.status, status)
if err != nil {
t.Errorf("In test %s, unexpected error: %v", test.test, err)

View File

@@ -25,13 +25,13 @@ import (
type MinionRegistry struct {
Err error
Minion string
Minions api.MinionList
Minions api.NodeList
sync.Mutex
}
func MakeMinionList(minions []string, nodeResources api.NodeResources) *api.MinionList {
list := api.MinionList{
Items: make([]api.Minion, len(minions)),
func MakeMinionList(minions []string, nodeResources api.NodeResources) *api.NodeList {
list := api.NodeList{
Items: make([]api.Node, len(minions)),
}
for i := range minions {
list.Items[i].Name = minions[i]
@@ -46,13 +46,13 @@ func NewMinionRegistry(minions []string, nodeResources api.NodeResources) *Minio
}
}
func (r *MinionRegistry) ListMinions(ctx api.Context) (*api.MinionList, error) {
func (r *MinionRegistry) ListMinions(ctx api.Context) (*api.NodeList, error) {
r.Lock()
defer r.Unlock()
return &r.Minions, r.Err
}
func (r *MinionRegistry) CreateMinion(ctx api.Context, minion *api.Minion) error {
func (r *MinionRegistry) CreateMinion(ctx api.Context, minion *api.Node) error {
r.Lock()
defer r.Unlock()
r.Minion = minion.Name
@@ -60,7 +60,7 @@ func (r *MinionRegistry) CreateMinion(ctx api.Context, minion *api.Minion) error
return r.Err
}
func (r *MinionRegistry) UpdateMinion(ctx api.Context, minion *api.Minion) error {
func (r *MinionRegistry) UpdateMinion(ctx api.Context, minion *api.Node) error {
r.Lock()
defer r.Unlock()
for i, node := range r.Minions.Items {
@@ -72,7 +72,7 @@ func (r *MinionRegistry) UpdateMinion(ctx api.Context, minion *api.Minion) error
return r.Err
}
func (r *MinionRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) {
func (r *MinionRegistry) GetMinion(ctx api.Context, minionID string) (*api.Node, error) {
r.Lock()
defer r.Unlock()
for _, node := range r.Minions.Items {
@@ -86,10 +86,10 @@ func (r *MinionRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minio
func (r *MinionRegistry) DeleteMinion(ctx api.Context, minionID string) error {
r.Lock()
defer r.Unlock()
var newList []api.Minion
var newList []api.Node
for _, node := range r.Minions.Items {
if node.Name != minionID {
newList = append(newList, api.Minion{ObjectMeta: api.ObjectMeta{Name: node.Name}})
newList = append(newList, api.Node{ObjectMeta: api.ObjectMeta{Name: node.Name}})
}
}
r.Minions.Items = newList

View File

@@ -154,7 +154,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
}), nil
}
func hostsFromMinionList(list *api.MinionList) []string {
func hostsFromMinionList(list *api.NodeList) []string {
result := make([]string, len(list.Items))
for ix := range list.Items {
result[ix] = list.Items[ix].Name