Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Minions -> Nodes internally #2788

Merged
merged 8 commits into from
Dec 10, 2014
3 changes: 2 additions & 1 deletion cmd/kubecfg/kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ var parser = kubecfg.NewParser(map[string]runtime.Object{
"pods": &api.Pod{},
"services": &api.Service{},
"replicationControllers": &api.ReplicationController{},
"minions": &api.Minion{},
"minions": &api.Node{},
"nodes": &api.Node{},
"events": &api.Event{},
})

Expand Down
4 changes: 4 additions & 0 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ kube::log::status "Testing kubectl(minions)"
"${kube_cmd[@]}" get minions "${kube_flags[@]}"
"${kube_cmd[@]}" get minions 127.0.0.1 "${kube_flags[@]}"

kube::log::status "Testing kubectl(nodes)"
"${kube_cmd[@]}" get nodes "${kube_flags[@]}"
"${kube_cmd[@]}" describe nodes 127.0.0.1 "${kube_flags[@]}"

kube::log::status "TEST PASSED"

# Start proxy
Expand Down
11 changes: 7 additions & 4 deletions pkg/api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func init() {
&ReplicationController{},
&ServiceList{},
&Service{},
&MinionList{},
&Minion{},
&NodeList{},
&Node{},
&Status{},
&ServerOpList{},
&ServerOp{},
Expand All @@ -46,6 +46,9 @@ func init() {
&BoundPod{},
&BoundPods{},
)
// Legacy names are supported
Scheme.AddKnownTypeWithName("", "Minion", &Node{})
Scheme.AddKnownTypeWithName("", "MinionList", &NodeList{})
}

func (*Pod) IsAnAPIObject() {}
Expand All @@ -56,8 +59,8 @@ func (*Service) IsAnAPIObject() {}
func (*ServiceList) IsAnAPIObject() {}
func (*Endpoints) IsAnAPIObject() {}
func (*EndpointsList) IsAnAPIObject() {}
func (*Minion) IsAnAPIObject() {}
func (*MinionList) IsAnAPIObject() {}
func (*Node) IsAnAPIObject() {}
func (*NodeList) IsAnAPIObject() {}
func (*Binding) IsAnAPIObject() {}
func (*Status) IsAnAPIObject() {}
func (*ServerOp) IsAnAPIObject() {}
Expand Down
13 changes: 6 additions & 7 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,9 @@ type ResourceName string

type ResourceList map[ResourceName]util.IntOrString

// Minion is a worker node in Kubernetenes
// The name of the minion according to etcd is in ObjectMeta.Name.
// TODO: Rename to Node
type Minion struct {
// Node is a worker node in Kubernetenes
// The name of the node according to etcd is in ObjectMeta.Name.
type Node struct {
TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`

Expand All @@ -686,12 +685,12 @@ type Minion struct {
Status NodeStatus `json:"status,omitempty"`
}

// MinionList is a list of minions.
type MinionList struct {
// NodeList is a list of minions.
type NodeList struct {
TypeMeta `json:",inline"`
ListMeta `json:"metadata,omitempty"`

Items []Minion `json:"items"`
Items []Node `json:"items"`
}

// Binding is written by a scheduler to cause a pod to be bound to a host.
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func init() {
},

// MinionList.Items had a wrong name in v1beta1
func(in *newer.MinionList, out *MinionList, s conversion.Scope) error {
func(in *newer.NodeList, out *MinionList, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
Expand All @@ -150,7 +150,7 @@ func init() {
out.Minions = out.Items
return nil
},
func(in *MinionList, out *newer.MinionList, s conversion.Scope) error {
func(in *MinionList, out *newer.NodeList, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
Expand Down Expand Up @@ -444,7 +444,7 @@ func init() {
return nil
},

func(in *newer.Minion, out *Minion, s conversion.Scope) error {
func(in *newer.Node, out *Minion, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
Expand All @@ -458,7 +458,7 @@ func init() {
out.HostIP = in.Status.HostIP
return s.Convert(&in.Spec.Capacity, &out.NodeResources.Capacity, 0)
},
func(in *Minion, out *newer.Minion, s conversion.Scope) error {
func(in *Minion, out *newer.Node, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
Expand Down
105 changes: 64 additions & 41 deletions pkg/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@ import (
"testing"

newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
current "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
)

var Convert = newer.Scheme.Convert

func TestNodeConversion(t *testing.T) {
obj, err := current.Codec.Decode([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if _, ok := obj.(*newer.Node); !ok {
t.Errorf("unexpected type: %#v", obj)
}

obj, err = current.Codec.Decode([]byte(`{"kind":"NodeList","apiVersion":"v1beta1"}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if _, ok := obj.(*newer.NodeList); !ok {
t.Errorf("unexpected type: %#v", obj)
}

obj = &newer.Node{}
if err := current.Codec.DecodeInto([]byte(`{"kind":"Node","apiVersion":"v1beta1"}`), obj); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

func TestEnvConversion(t *testing.T) {
nonCanonical := []v1beta1.EnvVar{
nonCanonical := []current.EnvVar{
{Key: "EV"},
{Key: "EV", Name: "EX"},
}
Expand All @@ -48,7 +71,7 @@ func TestEnvConversion(t *testing.T) {

// Test conversion the other way, too.
for i := range canonical {
var got v1beta1.EnvVar
var got current.EnvVar
err := Convert(&canonical[i], &got)
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -65,15 +88,15 @@ func TestEnvConversion(t *testing.T) {
func TestVolumeMountConversionToOld(t *testing.T) {
table := []struct {
in newer.VolumeMount
out v1beta1.VolumeMount
out current.VolumeMount
}{
{
in: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
out: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
out: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/foo", ReadOnly: true},
},
}
for _, item := range table {
got := v1beta1.VolumeMount{}
got := current.VolumeMount{}
err := Convert(&item.in, &got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -87,17 +110,17 @@ func TestVolumeMountConversionToOld(t *testing.T) {

func TestVolumeMountConversionToNew(t *testing.T) {
table := []struct {
in v1beta1.VolumeMount
in current.VolumeMount
out newer.VolumeMount
}{
{
in: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
}, {
in: v1beta1.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
in: current.VolumeMount{Name: "foo", MountPath: "/dev/foo", Path: "/dev/bar", ReadOnly: true},
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/foo", ReadOnly: true},
}, {
in: v1beta1.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
in: current.VolumeMount{Name: "foo", Path: "/dev/bar", ReadOnly: true},
out: newer.VolumeMount{Name: "foo", MountPath: "/dev/bar", ReadOnly: true},
},
}
Expand All @@ -115,42 +138,42 @@ func TestVolumeMountConversionToNew(t *testing.T) {
}

func TestMinionListConversionToNew(t *testing.T) {
oldMinion := func(id string) v1beta1.Minion {
return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}}
oldMinion := func(id string) current.Minion {
return current.Minion{TypeMeta: current.TypeMeta{ID: id}}
}
newMinion := func(id string) newer.Minion {
return newer.Minion{ObjectMeta: newer.ObjectMeta{Name: id}}
newNode := func(id string) newer.Node {
return newer.Node{ObjectMeta: newer.ObjectMeta{Name: id}}
}
oldMinions := []v1beta1.Minion{
oldMinions := []current.Minion{
oldMinion("foo"),
oldMinion("bar"),
}
newMinions := []newer.Minion{
newMinion("foo"),
newMinion("bar"),
newMinions := []newer.Node{
newNode("foo"),
newNode("bar"),
}

table := []struct {
oldML *v1beta1.MinionList
newML *newer.MinionList
oldML *current.MinionList
newML *newer.NodeList
}{
{
oldML: &v1beta1.MinionList{Items: oldMinions},
newML: &newer.MinionList{Items: newMinions},
oldML: &current.MinionList{Items: oldMinions},
newML: &newer.NodeList{Items: newMinions},
}, {
oldML: &v1beta1.MinionList{Minions: oldMinions},
newML: &newer.MinionList{Items: newMinions},
oldML: &current.MinionList{Minions: oldMinions},
newML: &newer.NodeList{Items: newMinions},
}, {
oldML: &v1beta1.MinionList{
oldML: &current.MinionList{
Items: oldMinions,
Minions: []v1beta1.Minion{oldMinion("baz")},
Minions: []current.Minion{oldMinion("baz")},
},
newML: &newer.MinionList{Items: newMinions},
newML: &newer.NodeList{Items: newMinions},
},
}

for _, item := range table {
got := &newer.MinionList{}
got := &newer.NodeList{}
err := Convert(item.oldML, got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -162,28 +185,28 @@ func TestMinionListConversionToNew(t *testing.T) {
}

func TestMinionListConversionToOld(t *testing.T) {
oldMinion := func(id string) v1beta1.Minion {
return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}}
oldMinion := func(id string) current.Minion {
return current.Minion{TypeMeta: current.TypeMeta{ID: id}}
}
newMinion := func(id string) newer.Minion {
return newer.Minion{ObjectMeta: newer.ObjectMeta{Name: id}}
newNode := func(id string) newer.Node {
return newer.Node{ObjectMeta: newer.ObjectMeta{Name: id}}
}
oldMinions := []v1beta1.Minion{
oldMinions := []current.Minion{
oldMinion("foo"),
oldMinion("bar"),
}
newMinions := []newer.Minion{
newMinion("foo"),
newMinion("bar"),
newMinions := []newer.Node{
newNode("foo"),
newNode("bar"),
}

newML := &newer.MinionList{Items: newMinions}
oldML := &v1beta1.MinionList{
newML := &newer.NodeList{Items: newMinions}
oldML := &current.MinionList{
Items: oldMinions,
Minions: oldMinions,
}

got := &v1beta1.MinionList{}
got := &current.MinionList{}
err := Convert(newML, got)
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -195,7 +218,7 @@ func TestMinionListConversionToOld(t *testing.T) {

func TestServiceEmptySelector(t *testing.T) {
// Nil map should be preserved
svc := &v1beta1.Service{Selector: nil}
svc := &current.Service{Selector: nil}
data, err := newer.Scheme.EncodeToVersion(svc, "v1beta1")
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -210,7 +233,7 @@ func TestServiceEmptySelector(t *testing.T) {
}

// Empty map should be preserved
svc2 := &v1beta1.Service{Selector: map[string]string{}}
svc2 := &current.Service{Selector: map[string]string{}}
data, err = newer.Scheme.EncodeToVersion(svc2, "v1beta1")
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down
7 changes: 7 additions & 0 deletions pkg/api/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
var Codec = runtime.CodecFor(api.Scheme, "v1beta1")

func init() {
// Future names are supported, and declared first so they take precedence
api.Scheme.AddKnownTypeWithName("v1beta1", "Node", &Minion{})
api.Scheme.AddKnownTypeWithName("v1beta1", "NodeList", &MinionList{})

api.Scheme.AddKnownTypes("v1beta1",
&Pod{},
&PodList{},
Expand All @@ -47,6 +51,9 @@ func init() {
&BoundPod{},
&BoundPods{},
)
// Future names are supported
api.Scheme.AddKnownTypeWithName("v1beta1", "Node", &Minion{})
api.Scheme.AddKnownTypeWithName("v1beta1", "NodeList", &MinionList{})
}

func (*Pod) IsAnAPIObject() {}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func init() {
return nil
},

func(in *newer.Minion, out *Minion, s conversion.Scope) error {
func(in *newer.Node, out *Minion, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
Expand All @@ -388,7 +388,7 @@ func init() {
out.HostIP = in.Status.HostIP
return s.Convert(&in.Spec.Capacity, &out.NodeResources.Capacity, 0)
},
func(in *Minion, out *newer.Minion, s conversion.Scope) error {
func(in *Minion, out *newer.Node, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
Expand Down