From bb77a5d15f6a1cb6730951404aea012f14cbf828 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Wed, 22 Oct 2014 13:02:02 -0400 Subject: [PATCH] Rename ID -> Name --- cmd/e2e/e2e.go | 8 +- cmd/integration/integration.go | 22 +-- pkg/api/conversion.go | 6 +- pkg/api/latest/latest_test.go | 2 +- pkg/api/ref_test.go | 6 +- pkg/api/serialization_test.go | 4 +- pkg/api/types.go | 4 +- pkg/api/v1beta1/conversion.go | 4 +- pkg/api/v1beta1/conversion_test.go | 4 +- pkg/api/v1beta1/types.go | 2 +- pkg/api/v1beta2/conversion.go | 4 +- pkg/api/v1beta2/types.go | 2 +- pkg/api/v1beta3/types.go | 2 +- pkg/api/validation/validation.go | 26 +-- pkg/api/validation/validation_test.go | 78 ++++----- pkg/apiserver/apiserver_test.go | 24 +-- pkg/apiserver/operation.go | 2 +- pkg/apiserver/operation_test.go | 8 +- pkg/apiserver/watch_test.go | 6 +- pkg/client/cache/reflector_test.go | 24 +-- pkg/client/client.go | 8 +- pkg/client/client_test.go | 36 ++--- pkg/client/fake.go | 4 +- pkg/client/record/event_test.go | 2 +- pkg/client/request_test.go | 12 +- .../controller/minioncontroller.go | 14 +- .../controller/minioncontroller_test.go | 10 +- pkg/controller/replication_controller.go | 8 +- pkg/controller/replication_controller_test.go | 4 +- pkg/kubecfg/kubecfg.go | 6 +- pkg/kubecfg/kubecfg_test.go | 14 +- pkg/kubecfg/parse_test.go | 8 +- pkg/kubecfg/resource_printer.go | 16 +- pkg/kubecfg/resource_printer_test.go | 4 +- pkg/kubectl/describe.go | 50 +++--- pkg/kubectl/resource_printer.go | 16 +- pkg/kubectl/resource_printer_test.go | 2 +- pkg/kubelet/config/config.go | 6 +- pkg/kubelet/config/config_test.go | 8 +- pkg/kubelet/config/etcd.go | 4 +- pkg/kubelet/config/etcd_test.go | 16 +- pkg/kubelet/config/file.go | 4 +- pkg/kubelet/config/file_test.go | 8 +- pkg/kubelet/config/http.go | 8 +- pkg/kubelet/config/http_test.go | 6 +- pkg/kubelet/kubelet.go | 6 +- pkg/kubelet/kubelet_test.go | 32 ++-- pkg/kubelet/runonce.go | 14 +- pkg/kubelet/runonce_test.go | 6 +- pkg/kubelet/server.go | 18 +-- pkg/kubelet/server_test.go | 8 +- pkg/kubelet/types.go | 2 +- pkg/master/master.go | 2 +- pkg/master/pod_cache.go | 2 +- pkg/master/pod_cache_test.go | 2 +- pkg/proxy/config/api_test.go | 8 +- pkg/proxy/config/config.go | 12 +- pkg/proxy/config/config_test.go | 36 ++--- pkg/proxy/config/etcd.go | 10 +- pkg/proxy/proxier.go | 24 +-- pkg/proxy/proxier_test.go | 28 ++-- pkg/proxy/roundrobin.go | 10 +- pkg/proxy/roundrobin_test.go | 14 +- pkg/registry/controller/rest.go | 12 +- pkg/registry/controller/rest_test.go | 32 ++-- pkg/registry/endpoint/rest.go | 6 +- pkg/registry/endpoint/rest_test.go | 12 +- pkg/registry/etcd/etcd.go | 48 +++--- pkg/registry/etcd/etcd_test.go | 152 +++++++++--------- pkg/registry/event/registry_test.go | 4 +- pkg/registry/event/rest.go | 4 +- pkg/registry/event/rest_test.go | 12 +- pkg/registry/generic/etcd/etcd_test.go | 20 +-- pkg/registry/minion/healthy_registry.go | 2 +- pkg/registry/minion/healthy_registry_test.go | 2 +- pkg/registry/minion/rest.go | 8 +- pkg/registry/minion/rest_test.go | 16 +- pkg/registry/pod/bound_pod_factory_test.go | 10 +- pkg/registry/pod/rest.go | 24 +-- pkg/registry/pod/rest_test.go | 44 ++--- pkg/registry/registrytest/minion.go | 10 +- pkg/registry/registrytest/service.go | 2 +- pkg/registry/service/rest.go | 70 ++++---- pkg/registry/service/rest_test.go | 102 ++++++------ pkg/runtime/embedded_test.go | 6 +- pkg/runtime/helper_test.go | 16 +- pkg/runtime/typemeta.go | 2 +- pkg/runtime/typemeta_test.go | 6 +- pkg/runtime/types.go | 2 +- pkg/scheduler/generic_scheduler.go | 4 +- pkg/scheduler/generic_scheduler_test.go | 12 +- pkg/scheduler/predicates.go | 2 +- pkg/scheduler/priorities.go | 4 +- pkg/scheduler/priorities_test.go | 2 +- pkg/scheduler/spreading.go | 2 +- pkg/service/endpoints_controller.go | 6 +- pkg/service/endpoints_controller_test.go | 12 +- pkg/tools/etcd_tools_test.go | 58 +++---- pkg/tools/etcd_tools_watch_test.go | 26 +-- pkg/watch/json/decoder_test.go | 2 +- pkg/watch/json/encoder_test.go | 6 +- plugin/pkg/scheduler/factory/factory.go | 10 +- plugin/pkg/scheduler/factory/factory_test.go | 22 +-- plugin/pkg/scheduler/scheduler.go | 4 +- plugin/pkg/scheduler/scheduler_test.go | 4 +- test/integration/client_test.go | 6 +- test/integration/etcd_tools_test.go | 2 +- 107 files changed, 777 insertions(+), 777 deletions(-) diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index 8cc28dc0bcd..89822fede58 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -111,15 +111,15 @@ func TestPodUpdate(c *client.Client) bool { glog.Errorf("Failed to create pod: %v", err) return false } - defer c.DeletePod(ctx, pod.ID) - waitForPodRunning(c, pod.ID) + defer c.DeletePod(ctx, pod.Name) + waitForPodRunning(c, pod.Name) pods, err := c.ListPods(ctx, labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))) if len(pods.Items) != 1 { glog.Errorf("Failed to find the correct pod") return false } - podOut, err := c.GetPod(ctx, pod.ID) + podOut, err := c.GetPod(ctx, pod.Name) if err != nil { glog.Errorf("Failed to get pod: %v", err) return false @@ -133,7 +133,7 @@ func TestPodUpdate(c *client.Client) bool { glog.Errorf("Failed to update pod: %v", err) return false } - waitForPodRunning(c, pod.ID) + waitForPodRunning(c, pod.Name) pods, err = c.ListPods(ctx, labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))) if len(pods.Items) != 1 { glog.Errorf("Failed to find the correct pod after update.") diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index c24384cc278..0edfdb9f2e6 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -184,7 +184,7 @@ func podsOnMinions(c *client.Client, pods api.PodList) wait.ConditionFunc { podInfo := fakePodInfoGetter{} return func() (bool, error) { for i := range pods.Items { - host, id, namespace := pods.Items[i].CurrentState.Host, pods.Items[i].ID, pods.Items[i].Namespace + host, id, namespace := pods.Items[i].CurrentState.Host, pods.Items[i].Name, pods.Items[i].Namespace if len(host) == 0 { return false, nil } @@ -251,7 +251,7 @@ func runAtomicPutTest(c *client.Client) { var svc api.Service err := c.Post().Path("services").Body( &api.Service{ - TypeMeta: api.TypeMeta{ID: "atomicservice", APIVersion: latest.Version}, + TypeMeta: api.TypeMeta{Name: "atomicservice", APIVersion: latest.Version}, Port: 12345, Labels: map[string]string{ "name": "atomicService", @@ -282,7 +282,7 @@ func runAtomicPutTest(c *client.Client) { var tmpSvc api.Service err := c.Get(). Path("services"). - Path(svc.ID). + Path(svc.Name). PollPeriod(100 * time.Millisecond). Do(). Into(&tmpSvc) @@ -296,7 +296,7 @@ func runAtomicPutTest(c *client.Client) { tmpSvc.Selector[l] = v } glog.Infof("Posting update (%s, %s)", l, v) - err = c.Put().Path("services").Path(svc.ID).Body(&tmpSvc).Do().Error() + err = c.Put().Path("services").Path(svc.Name).Body(&tmpSvc).Do().Error() if err != nil { if errors.IsConflict(err) { glog.Infof("Conflict: (%s, %s)", l, v) @@ -313,7 +313,7 @@ func runAtomicPutTest(c *client.Client) { }(label, value) } wg.Wait() - if err := c.Get().Path("services").Path(svc.ID).Do().Into(&svc); err != nil { + if err := c.Get().Path("services").Path(svc.Name).Do().Into(&svc); err != nil { glog.Fatalf("Failed getting atomicService after writers are complete: %v", err) } if !reflect.DeepEqual(testLabels, labels.Set(svc.Selector)) { @@ -325,7 +325,7 @@ func runAtomicPutTest(c *client.Client) { func runServiceTest(client *client.Client) { ctx := api.NewDefaultContext() pod := api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Version: "v1beta1", @@ -351,11 +351,11 @@ func runServiceTest(client *client.Client) { if err != nil { glog.Fatalf("Failed to create pod: %v, %v", pod, err) } - if err := wait.Poll(time.Second, time.Second*20, podExists(client, ctx, pod.ID)); err != nil { + if err := wait.Poll(time.Second, time.Second*20, podExists(client, ctx, pod.Name)); err != nil { glog.Fatalf("FAILED: pod never started running %v", err) } svc1 := api.Service{ - TypeMeta: api.TypeMeta{ID: "service1"}, + TypeMeta: api.TypeMeta{Name: "service1"}, Selector: map[string]string{ "name": "thisisalonglabel", }, @@ -365,12 +365,12 @@ func runServiceTest(client *client.Client) { if err != nil { glog.Fatalf("Failed to create service: %v, %v", svc1, err) } - if err := wait.Poll(time.Second, time.Second*20, endpointsSet(client, ctx, svc1.ID, 1)); err != nil { + if err := wait.Poll(time.Second, time.Second*20, endpointsSet(client, ctx, svc1.Name, 1)); err != nil { glog.Fatalf("FAILED: unexpected endpoints: %v", err) } // A second service with the same port. svc2 := api.Service{ - TypeMeta: api.TypeMeta{ID: "service2"}, + TypeMeta: api.TypeMeta{Name: "service2"}, Selector: map[string]string{ "name": "thisisalonglabel", }, @@ -380,7 +380,7 @@ func runServiceTest(client *client.Client) { if err != nil { glog.Fatalf("Failed to create service: %v, %v", svc2, err) } - if err := wait.Poll(time.Second, time.Second*20, endpointsSet(client, ctx, svc2.ID, 1)); err != nil { + if err := wait.Poll(time.Second, time.Second*20, endpointsSet(client, ctx, svc2.Name, 1)); err != nil { glog.Fatalf("FAILED: unexpected endpoints: %v", err) } glog.Info("Service test passed.") diff --git a/pkg/api/conversion.go b/pkg/api/conversion.go index e6f93710318..a43bd8f0554 100644 --- a/pkg/api/conversion.go +++ b/pkg/api/conversion.go @@ -32,7 +32,7 @@ func init() { out.Spec.Containers = in.Containers out.Spec.Volumes = in.Volumes out.Spec.RestartPolicy = in.RestartPolicy - out.ID = in.ID + out.Name = in.ID out.UID = in.UUID return nil }, @@ -41,7 +41,7 @@ func init() { out.Volumes = in.Spec.Volumes out.RestartPolicy = in.Spec.RestartPolicy out.Version = "v1beta2" - out.ID = in.ID + out.ID = in.Name out.UUID = in.UID return nil }, @@ -71,7 +71,7 @@ func init() { // Only copy a subset of fields, and override manifest attributes with the pod // metadata out.UID = in.UID - out.ID = in.ID + out.Name = in.Name out.Namespace = in.Namespace out.CreationTimestamp = in.CreationTimestamp return nil diff --git a/pkg/api/latest/latest_test.go b/pkg/api/latest/latest_test.go index fbef7f1ee4a..81b5964ef4e 100644 --- a/pkg/api/latest/latest_test.go +++ b/pkg/api/latest/latest_test.go @@ -37,7 +37,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( // APIVersion and Kind must remain blank in memory. j.APIVersion = "" j.Kind = "" - j.ID = c.RandString() + j.Name = c.RandString() // TODO: Fix JSON/YAML packages and/or write custom encoding // for uint64's. Somehow the LS *byte* of this is lost, but // only when all 8 bytes are set. diff --git a/pkg/api/ref_test.go b/pkg/api/ref_test.go index eca95cf6195..14be5bb1600 100644 --- a/pkg/api/ref_test.go +++ b/pkg/api/ref_test.go @@ -36,7 +36,7 @@ func TestGetReference(t *testing.T) { "pod": { obj: &Pod{ TypeMeta: TypeMeta{ - ID: "foo", + Name: "foo", ResourceVersion: "42", SelfLink: "/api/v1beta1/pods/foo", }, @@ -52,7 +52,7 @@ func TestGetReference(t *testing.T) { "serviceList": { obj: &ServiceList{ TypeMeta: TypeMeta{ - ID: "foo", + Name: "foo", ResourceVersion: "42", SelfLink: "/api/v1beta2/services", }, @@ -68,7 +68,7 @@ func TestGetReference(t *testing.T) { "badSelfLink": { obj: &ServiceList{ TypeMeta: TypeMeta{ - ID: "foo", + Name: "foo", ResourceVersion: "42", SelfLink: "v1beta2/services", }, diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index 4feeda1bd8a..e5c9c2371e7 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -46,7 +46,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( // APIVersion and Kind must remain blank in memory. j.APIVersion = "" j.Kind = "" - j.ID = c.RandString() + j.Name = c.RandString() // TODO: Fix JSON/YAML packages and/or write custom encoding // for uint64's. Somehow the LS *byte* of this is lost, but // only when all 8 bytes are set. @@ -63,7 +63,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( // APIVersion and Kind must remain blank in memory. j.APIVersion = "" j.Kind = "" - j.ID = c.RandString() + j.Name = c.RandString() // TODO: Fix JSON/YAML packages and/or write custom encoding // for uint64's. Somehow the LS *byte* of this is lost, but // only when all 8 bytes are set. diff --git a/pkg/api/types.go b/pkg/api/types.go index b1bda3540c2..eaeb4d71667 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -245,7 +245,7 @@ type Lifecycle struct { // TypeMeta is shared by all objects sent to, or returned from the client. type TypeMeta struct { Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` - ID string `json:"id,omitempty" yaml:"id,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"` @@ -458,7 +458,7 @@ 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 TypeMeta.ID. +// The name of the minion according to etcd is in ID. type Minion struct { TypeMeta `json:",inline" yaml:",inline"` // Queried from cloud provider, if available. diff --git a/pkg/api/v1beta1/conversion.go b/pkg/api/v1beta1/conversion.go index a745c97bec4..92751eb5efb 100644 --- a/pkg/api/v1beta1/conversion.go +++ b/pkg/api/v1beta1/conversion.go @@ -30,7 +30,7 @@ func init() { out.APIVersion = in.APIVersion out.Kind = in.Kind out.Namespace = in.Namespace - out.ID = in.ID + out.ID = in.Name out.CreationTimestamp = in.CreationTimestamp out.SelfLink = in.SelfLink out.Annotations = in.Annotations @@ -48,7 +48,7 @@ func init() { out.APIVersion = in.APIVersion out.Kind = in.Kind out.Namespace = in.Namespace - out.ID = in.ID + out.Name = in.ID out.CreationTimestamp = in.CreationTimestamp out.SelfLink = in.SelfLink out.Annotations = in.Annotations diff --git a/pkg/api/v1beta1/conversion_test.go b/pkg/api/v1beta1/conversion_test.go index eb49588aeaa..beb9076558b 100644 --- a/pkg/api/v1beta1/conversion_test.go +++ b/pkg/api/v1beta1/conversion_test.go @@ -119,7 +119,7 @@ func TestMinionListConversionToNew(t *testing.T) { return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}} } newMinion := func(id string) newer.Minion { - return newer.Minion{TypeMeta: newer.TypeMeta{ID: id}} + return newer.Minion{TypeMeta: newer.TypeMeta{Name: id}} } oldMinions := []v1beta1.Minion{ oldMinion("foo"), @@ -166,7 +166,7 @@ func TestMinionListConversionToOld(t *testing.T) { return v1beta1.Minion{TypeMeta: v1beta1.TypeMeta{ID: id}} } newMinion := func(id string) newer.Minion { - return newer.Minion{TypeMeta: newer.TypeMeta{ID: id}} + return newer.Minion{TypeMeta: newer.TypeMeta{Name: id}} } oldMinions := []v1beta1.Minion{ oldMinion("foo"), diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 76530043069..12b576a2e84 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -484,7 +484,7 @@ 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 TypeMeta.ID. +// The name of the minion according to etcd is in ID. type Minion struct { TypeMeta `json:",inline" yaml:",inline"` // Queried from cloud provider, if available. diff --git a/pkg/api/v1beta2/conversion.go b/pkg/api/v1beta2/conversion.go index 15e32926598..83e2a008c8a 100644 --- a/pkg/api/v1beta2/conversion.go +++ b/pkg/api/v1beta2/conversion.go @@ -30,7 +30,7 @@ func init() { out.APIVersion = in.APIVersion out.Kind = in.Kind out.Namespace = in.Namespace - out.ID = in.ID + out.ID = in.Name out.CreationTimestamp = in.CreationTimestamp out.SelfLink = in.SelfLink out.Annotations = in.Annotations @@ -48,7 +48,7 @@ func init() { out.APIVersion = in.APIVersion out.Kind = in.Kind out.Namespace = in.Namespace - out.ID = in.ID + out.Name = in.ID out.CreationTimestamp = in.CreationTimestamp out.SelfLink = in.SelfLink out.Annotations = in.Annotations diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index 4807660e695..858cabc1c25 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -449,7 +449,7 @@ 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 TypeMeta.ID. +// The name of the minion according to etcd is in ID. type Minion struct { TypeMeta `json:",inline" yaml:",inline"` // Queried from cloud provider, if available. diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index dd239d6136d..c41c54f3c33 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -657,7 +657,7 @@ type ResourceName string type ResourceList map[ResourceName]util.IntOrString // Node is a worker node in Kubernetenes. -// The name of the node according to etcd is in TypeMeta.ID. +// The name of the node according to etcd is in ID. type Node struct { TypeMeta `json:",inline" yaml:",inline"` Metadata ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"` diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 25bc6aa6a76..3173ad4f02b 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -332,8 +332,8 @@ func ValidatePodState(podState *api.PodState) errs.ErrorList { // ValidatePod tests if required fields in the pod are set. func ValidatePod(pod *api.Pod) errs.ErrorList { allErrs := errs.ErrorList{} - if len(pod.ID) == 0 { - allErrs = append(allErrs, errs.NewFieldRequired("id", pod.ID)) + if len(pod.Name) == 0 { + allErrs = append(allErrs, errs.NewFieldRequired("id", pod.Name)) } if !util.IsDNSSubdomain(pod.Namespace) { allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace)) @@ -346,8 +346,8 @@ func ValidatePod(pod *api.Pod) errs.ErrorList { func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ErrorList { allErrs := errs.ErrorList{} - if newPod.ID != oldPod.ID { - allErrs = append(allErrs, errs.NewFieldInvalid("ID", newPod.ID)) + if newPod.Name != oldPod.Name { + allErrs = append(allErrs, errs.NewFieldInvalid("ID", newPod.Name)) } if len(newPod.DesiredState.Manifest.Containers) != len(oldPod.DesiredState.Manifest.Containers) { @@ -373,10 +373,10 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ErrorList { // ValidateService tests if required fields in the service are set. func ValidateService(service *api.Service) errs.ErrorList { allErrs := errs.ErrorList{} - if len(service.ID) == 0 { - allErrs = append(allErrs, errs.NewFieldRequired("id", service.ID)) - } else if !util.IsDNS952Label(service.ID) { - allErrs = append(allErrs, errs.NewFieldInvalid("id", service.ID)) + if len(service.Name) == 0 { + allErrs = append(allErrs, errs.NewFieldRequired("id", service.Name)) + } else if !util.IsDNS952Label(service.Name) { + allErrs = append(allErrs, errs.NewFieldInvalid("id", service.Name)) } if !util.IsDNSSubdomain(service.Namespace) { allErrs = append(allErrs, errs.NewFieldInvalid("namespace", service.Namespace)) @@ -398,8 +398,8 @@ func ValidateService(service *api.Service) errs.ErrorList { // ValidateReplicationController tests if required fields in the replication controller are set. func ValidateReplicationController(controller *api.ReplicationController) errs.ErrorList { allErrs := errs.ErrorList{} - if len(controller.ID) == 0 { - allErrs = append(allErrs, errs.NewFieldRequired("id", controller.ID)) + if len(controller.Name) == 0 { + allErrs = append(allErrs, errs.NewFieldRequired("id", controller.Name)) } if !util.IsDNSSubdomain(controller.Namespace) { allErrs = append(allErrs, errs.NewFieldInvalid("namespace", controller.Namespace)) @@ -440,15 +440,15 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ErrorList { // ValidateBoundPod tests if required fields on a bound pod are set. func ValidateBoundPod(pod *api.BoundPod) (errors []error) { - if !util.IsDNSSubdomain(pod.ID) { - errors = append(errors, errs.NewFieldInvalid("id", pod.ID)) + if !util.IsDNSSubdomain(pod.Name) { + errors = append(errors, errs.NewFieldInvalid("id", pod.Name)) } if !util.IsDNSSubdomain(pod.Namespace) { errors = append(errors, errs.NewFieldInvalid("namespace", pod.Namespace)) } containerManifest := &api.ContainerManifest{ Version: "v1beta2", - ID: pod.ID, + ID: pod.Name, UUID: pod.UID, Containers: pod.Spec.Containers, Volumes: pod.Spec.Volumes, diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index baa3b0171fd..0414076fe49 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -367,7 +367,7 @@ func TestValidateManifest(t *testing.T) { func TestValidatePod(t *testing.T) { errs := ValidatePod(&api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "foo", Namespace: api.NamespaceDefault}, Labels: map[string]string{ "foo": "bar", }, @@ -385,7 +385,7 @@ func TestValidatePod(t *testing.T) { t.Errorf("Unexpected non-zero error list: %#v", errs) } errs = ValidatePod(&api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "foo", Namespace: api.NamespaceDefault}, Labels: map[string]string{ "foo": "bar", }, @@ -398,7 +398,7 @@ func TestValidatePod(t *testing.T) { } errs = ValidatePod(&api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "foo", Namespace: api.NamespaceDefault}, Labels: map[string]string{ "foo": "bar", }, @@ -426,23 +426,23 @@ func TestValidatePodUpdate(t *testing.T) { {api.Pod{}, api.Pod{}, true, "nothing"}, { api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }, api.Pod{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, }, false, "ids", }, { api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Labels: map[string]string{ "foo": "bar", }, }, api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Labels: map[string]string{ "bar": "foo", }, @@ -452,7 +452,7 @@ func TestValidatePodUpdate(t *testing.T) { }, { api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -464,7 +464,7 @@ func TestValidatePodUpdate(t *testing.T) { }, }, api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -483,7 +483,7 @@ func TestValidatePodUpdate(t *testing.T) { }, { api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -495,7 +495,7 @@ func TestValidatePodUpdate(t *testing.T) { }, }, api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -511,7 +511,7 @@ func TestValidatePodUpdate(t *testing.T) { }, { api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -524,7 +524,7 @@ func TestValidatePodUpdate(t *testing.T) { }, }, api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -541,7 +541,7 @@ func TestValidatePodUpdate(t *testing.T) { }, { api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -556,7 +556,7 @@ func TestValidatePodUpdate(t *testing.T) { }, }, api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -608,7 +608,7 @@ func TestValidateService(t *testing.T) { { name: "missing namespace", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Port: 8675, Selector: map[string]string{"foo": "bar"}, }, @@ -618,7 +618,7 @@ func TestValidateService(t *testing.T) { { name: "invalid id", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "123abc", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "123abc", Namespace: api.NamespaceDefault}, Port: 8675, Selector: map[string]string{"foo": "bar"}, }, @@ -628,7 +628,7 @@ func TestValidateService(t *testing.T) { { name: "missing port", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc123", Namespace: api.NamespaceDefault}, Selector: map[string]string{"foo": "bar"}, }, // Should fail because the port number is missing/invalid. @@ -637,7 +637,7 @@ func TestValidateService(t *testing.T) { { name: "invalid port", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc123", Namespace: api.NamespaceDefault}, Port: 65536, Selector: map[string]string{"foo": "bar"}, }, @@ -647,7 +647,7 @@ func TestValidateService(t *testing.T) { { name: "invalid protocol", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc123", Namespace: api.NamespaceDefault}, Port: 8675, Protocol: "INVALID", Selector: map[string]string{"foo": "bar"}, @@ -658,7 +658,7 @@ func TestValidateService(t *testing.T) { { name: "missing selector", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "foo", Namespace: api.NamespaceDefault}, Port: 8675, }, // Should fail because the selector is missing. @@ -667,7 +667,7 @@ func TestValidateService(t *testing.T) { { name: "valid 1", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc123", Namespace: api.NamespaceDefault}, Port: 1, Protocol: "TCP", Selector: map[string]string{"foo": "bar"}, @@ -677,7 +677,7 @@ func TestValidateService(t *testing.T) { { name: "valid 2", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc123", Namespace: api.NamespaceDefault}, Port: 65535, Protocol: "UDP", Selector: map[string]string{"foo": "bar"}, @@ -687,7 +687,7 @@ func TestValidateService(t *testing.T) { { name: "valid 3", svc: api.Service{ - TypeMeta: api.TypeMeta{ID: "abc123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc123", Namespace: api.NamespaceDefault}, Port: 80, Selector: map[string]string{"foo": "bar"}, }, @@ -704,7 +704,7 @@ func TestValidateService(t *testing.T) { svc := api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "foo", Namespace: api.NamespaceDefault}, Selector: map[string]string{"foo": "bar"}, } errs := ValidateService(&svc) @@ -736,14 +736,14 @@ func TestValidateReplicationController(t *testing.T) { } successCases := []api.ReplicationController{ { - TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: validSelector, PodTemplate: validPodTemplate, }, }, { - TypeMeta: api.TypeMeta{ID: "abc-123", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc-123", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: validSelector, PodTemplate: validPodTemplate, @@ -758,47 +758,47 @@ func TestValidateReplicationController(t *testing.T) { errorCases := map[string]api.ReplicationController{ "zero-length ID": { - TypeMeta: api.TypeMeta{ID: "", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: validSelector, PodTemplate: validPodTemplate, }, }, "missing-namespace": { - TypeMeta: api.TypeMeta{ID: "abc-123"}, + TypeMeta: api.TypeMeta{Name: "abc-123"}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: validSelector, PodTemplate: validPodTemplate, }, }, "empty selector": { - TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ PodTemplate: validPodTemplate, }, }, "selector_doesnt_match": { - TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: map[string]string{"foo": "bar"}, PodTemplate: validPodTemplate, }, }, "invalid manifest": { - TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: validSelector, }, }, "read-write presistent disk": { - TypeMeta: api.TypeMeta{ID: "abc"}, + TypeMeta: api.TypeMeta{Name: "abc"}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: validSelector, PodTemplate: invalidVolumePodTemplate, }, }, "negative_replicas": { - TypeMeta: api.TypeMeta{ID: "abc", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "abc", Namespace: api.NamespaceDefault}, DesiredState: api.ReplicationControllerState{ Replicas: -1, ReplicaSelector: validSelector, @@ -827,13 +827,13 @@ func TestValidateReplicationController(t *testing.T) { func TestValidateBoundPodNoName(t *testing.T) { errorCases := map[string]api.BoundPod{ // manifest is tested in api/validation_test.go, ensure it is invoked - "empty version": {TypeMeta: api.TypeMeta{ID: "test"}, Spec: api.PodSpec{Containers: []api.Container{{Name: ""}}}}, + "empty version": {TypeMeta: api.TypeMeta{Name: "test"}, Spec: api.PodSpec{Containers: []api.Container{{Name: ""}}}}, // Name - "zero-length name": {TypeMeta: api.TypeMeta{ID: ""}}, - "name > 255 characters": {TypeMeta: api.TypeMeta{ID: strings.Repeat("a", 256)}}, - "name not a DNS subdomain": {TypeMeta: api.TypeMeta{ID: "a.b.c."}}, - "name with underscore": {TypeMeta: api.TypeMeta{ID: "a_b_c"}}, + "zero-length name": {TypeMeta: api.TypeMeta{Name: ""}}, + "name > 255 characters": {TypeMeta: api.TypeMeta{Name: strings.Repeat("a", 256)}}, + "name not a DNS subdomain": {TypeMeta: api.TypeMeta{Name: "a.b.c."}}, + "name with underscore": {TypeMeta: api.TypeMeta{Name: "a_b_c"}}, } for k, v := range errorCases { if errs := ValidateBoundPod(&v); len(errs) == 0 { diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index 02909fa2d3c..4a485e9c781 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -54,7 +54,7 @@ func init() { type Simple struct { api.TypeMeta `yaml:",inline" json:",inline"` - Name string `yaml:"name,omitempty" json:"name,omitempty"` + Other string `yaml:"other,omitempty" json:"other,omitempty"` } func (*Simple) IsAnAPIObject() {} @@ -108,7 +108,7 @@ func (storage *SimpleRESTStorage) Delete(ctx api.Context, id string) (<-chan run } return MakeAsync(func() (runtime.Object, error) { if storage.injectedFunction != nil { - return storage.injectedFunction(&Simple{TypeMeta: api.TypeMeta{ID: id}}) + return storage.injectedFunction(&Simple{TypeMeta: api.TypeMeta{Name: id}}) } return &api.Status{Status: api.StatusSuccess}, nil }), nil @@ -295,7 +295,7 @@ func TestNonEmptyList(t *testing.T) { list: []Simple{ { TypeMeta: api.TypeMeta{Kind: "Simple"}, - Name: "foo", + Other: "foo", }, }, } @@ -322,7 +322,7 @@ func TestNonEmptyList(t *testing.T) { t.Errorf("Unexpected response: %#v", listOut) return } - if listOut.Items[0].Name != simpleStorage.list[0].Name { + if listOut.Items[0].Other != simpleStorage.list[0].Other { t.Errorf("Unexpected data: %#v, %s", listOut.Items[0], string(body)) } } @@ -331,7 +331,7 @@ func TestGet(t *testing.T) { storage := map[string]RESTStorage{} simpleStorage := SimpleRESTStorage{ item: Simple{ - Name: "foo", + Other: "foo", }, } selfLinker := &setTestSelfLinker{ @@ -431,7 +431,7 @@ func TestUpdate(t *testing.T) { server := httptest.NewServer(handler) item := &Simple{ - Name: "bar", + Other: "bar", } body, err := codec.Encode(item) if err != nil { @@ -464,7 +464,7 @@ func TestUpdateMissing(t *testing.T) { server := httptest.NewServer(handler) item := &Simple{ - Name: "bar", + Other: "bar", } body, err := codec.Encode(item) if err != nil { @@ -493,7 +493,7 @@ func TestCreate(t *testing.T) { client := http.Client{} simple := &Simple{ - Name: "foo", + Other: "foo", } data, _ := codec.Encode(simple) request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo", bytes.NewBuffer(data)) @@ -532,7 +532,7 @@ func TestCreateNotFound(t *testing.T) { server := httptest.NewServer(handler) client := http.Client{} - simple := &Simple{Name: "foo"} + simple := &Simple{Other: "foo"} data, _ := codec.Encode(simple) request, err := http.NewRequest("POST", server.URL+"/prefix/version/simple", bytes.NewBuffer(data)) if err != nil { @@ -597,7 +597,7 @@ func TestSyncCreate(t *testing.T) { client := http.Client{} simple := &Simple{ - Name: "bar", + Other: "bar", } data, _ := codec.Encode(simple) request, err := http.NewRequest("POST", server.URL+"/prefix/version/foo?sync=true", bytes.NewBuffer(data)) @@ -691,7 +691,7 @@ func TestAsyncCreateError(t *testing.T) { handler.(*defaultAPIServer).group.handler.asyncOpWait = 0 server := httptest.NewServer(handler) - simple := &Simple{Name: "bar"} + simple := &Simple{Other: "bar"} data, _ := codec.Encode(simple) status := expectApiStatus(t, "POST", fmt.Sprintf("%s/prefix/version/foo", server.URL), data, http.StatusAccepted) @@ -787,7 +787,7 @@ func TestSyncCreateTimeout(t *testing.T) { }, codec, "/prefix/version", selfLinker) server := httptest.NewServer(handler) - simple := &Simple{Name: "foo"} + simple := &Simple{Other: "foo"} data, _ := codec.Encode(simple) itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?sync=true&timeout=4ms", data, http.StatusAccepted) if itemOut.Status != api.StatusWorking || itemOut.Details == nil || itemOut.Details.ID == "" { diff --git a/pkg/apiserver/operation.go b/pkg/apiserver/operation.go index 60529fd8638..f1183038662 100644 --- a/pkg/apiserver/operation.go +++ b/pkg/apiserver/operation.go @@ -125,7 +125,7 @@ func (ops *Operations) List() *api.ServerOpList { sort.StringSlice(ids).Sort() ol := &api.ServerOpList{} for _, id := range ids { - ol.Items = append(ol.Items, api.ServerOp{TypeMeta: api.TypeMeta{ID: id}}) + ol.Items = append(ol.Items, api.ServerOp{TypeMeta: api.TypeMeta{Name: id}}) } return ol } diff --git a/pkg/apiserver/operation_test.go b/pkg/apiserver/operation_test.go index 8a01f5a78cc..da144dbcccd 100644 --- a/pkg/apiserver/operation_test.go +++ b/pkg/apiserver/operation_test.go @@ -43,7 +43,7 @@ func TestOperation(t *testing.T) { time.Sleep(time.Millisecond) go func() { time.Sleep(500 * time.Millisecond) - c <- &Simple{TypeMeta: api.TypeMeta{ID: "All done"}} + c <- &Simple{TypeMeta: api.TypeMeta{Name: "All done"}} }() if op.expired(time.Now().Add(-time.Minute)) { @@ -96,7 +96,7 @@ func TestOperation(t *testing.T) { t.Errorf("expire failed to remove the operation %#v", ops) } - if op.result.(*Simple).ID != "All done" { + if op.result.(*Simple).Name != "All done" { t.Errorf("Got unexpected result: %#v", op.result) } } @@ -119,7 +119,7 @@ func TestOperationsList(t *testing.T) { client := http.Client{} simple := &Simple{ - Name: "foo", + TypeMeta: api.TypeMeta{Name: "foo"}, } data, err := codec.Encode(simple) if err != nil { @@ -175,7 +175,7 @@ func TestOpGet(t *testing.T) { client := http.Client{} simple := &Simple{ - Name: "foo", + TypeMeta: api.TypeMeta{Name: "foo"}, } data, err := codec.Encode(simple) t.Log(string(data)) diff --git a/pkg/apiserver/watch_test.go b/pkg/apiserver/watch_test.go index 56d03b1c7e8..78308a158f5 100644 --- a/pkg/apiserver/watch_test.go +++ b/pkg/apiserver/watch_test.go @@ -39,9 +39,9 @@ var watchTestTable = []struct { t watch.EventType obj runtime.Object }{ - {watch.Added, &Simple{Name: "A Name"}}, - {watch.Modified, &Simple{Name: "Another Name"}}, - {watch.Deleted, &Simple{Name: "Another Name"}}, + {watch.Added, &Simple{Other: "A Name"}}, + {watch.Modified, &Simple{Other: "Another Name"}}, + {watch.Deleted, &Simple{Other: "Another Name"}}, } func TestWatchWebsocket(t *testing.T) { diff --git a/pkg/client/cache/reflector_test.go b/pkg/client/cache/reflector_test.go index 89f977c5dfc..4b21057fb31 100644 --- a/pkg/client/cache/reflector_test.go +++ b/pkg/client/cache/reflector_test.go @@ -54,13 +54,13 @@ func TestReflector_watchHandler(t *testing.T) { s := NewStore() g := NewReflector(&testLW{}, &api.Pod{}, s) fw := watch.NewFake() - s.Add("foo", &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}) - s.Add("bar", &api.Pod{TypeMeta: api.TypeMeta{ID: "bar"}}) + s.Add("foo", &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}) + s.Add("bar", &api.Pod{TypeMeta: api.TypeMeta{Name: "bar"}}) go func() { - fw.Add(&api.Service{TypeMeta: api.TypeMeta{ID: "rejected"}}) - fw.Delete(&api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}) - fw.Modify(&api.Pod{TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "55"}}) - fw.Add(&api.Pod{TypeMeta: api.TypeMeta{ID: "baz", ResourceVersion: "32"}}) + fw.Add(&api.Service{TypeMeta: api.TypeMeta{Name: "rejected"}}) + fw.Delete(&api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}) + fw.Modify(&api.Pod{TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "55"}}) + fw.Add(&api.Pod{TypeMeta: api.TypeMeta{Name: "baz", ResourceVersion: "32"}}) fw.Stop() }() var resumeRV string @@ -132,7 +132,7 @@ func TestReflector_listAndWatch(t *testing.T) { fw = <-createdFakes } sendingRV := strconv.FormatUint(uint64(i+2), 10) - fw.Add(&api.Pod{TypeMeta: api.TypeMeta{ID: id, ResourceVersion: sendingRV}}) + fw.Add(&api.Pod{TypeMeta: api.TypeMeta{Name: id, ResourceVersion: sendingRV}}) if sendingRV == "3" { // Inject a failure. fw.Stop() @@ -143,7 +143,7 @@ func TestReflector_listAndWatch(t *testing.T) { // Verify we received the right ids with the right resource versions. for i, id := range ids { pod := s.Pop().(*api.Pod) - if e, a := id, pod.ID; e != a { + if e, a := id, pod.Name; e != a { t.Errorf("%v: Expected %v, got %v", i, e, a) } if e, a := strconv.FormatUint(uint64(i+2), 10), pod.ResourceVersion; e != a { @@ -158,7 +158,7 @@ func TestReflector_listAndWatch(t *testing.T) { func TestReflector_listAndWatchWithErrors(t *testing.T) { mkPod := func(id string, rv string) *api.Pod { - return &api.Pod{TypeMeta: api.TypeMeta{ID: id, ResourceVersion: rv}} + return &api.Pod{TypeMeta: api.TypeMeta{Name: id, ResourceVersion: rv}} } mkList := func(rv string, pods ...*api.Pod) *api.PodList { list := &api.PodList{TypeMeta: api.TypeMeta{ResourceVersion: rv}} @@ -208,11 +208,11 @@ func TestReflector_listAndWatchWithErrors(t *testing.T) { checkMap := map[string]string{} for _, item := range current { pod := item.(*api.Pod) - checkMap[pod.ID] = pod.ResourceVersion + checkMap[pod.Name] = pod.ResourceVersion } for _, pod := range item.list.Items { - if e, a := pod.ResourceVersion, checkMap[pod.ID]; e != a { - t.Errorf("%v: expected %v, got %v for pod %v", line, e, a, pod.ID) + if e, a := pod.ResourceVersion, checkMap[pod.Name]; e != a { + t.Errorf("%v: expected %v, got %v for pod %v", line, e, a, pod.Name) } } if e, a := len(item.list.Items), len(checkMap); e != a { diff --git a/pkg/client/client.go b/pkg/client/client.go index 2cfa08683fe..2274f5df3b7 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -136,7 +136,7 @@ func (c *Client) UpdatePod(ctx api.Context, pod *api.Pod) (result *api.Pod, err err = fmt.Errorf("invalid update object, missing resource version: %v", pod) return } - err = c.Put().Namespace(api.Namespace(ctx)).Path("pods").Path(pod.ID).Body(pod).Do().Into(result) + err = c.Put().Namespace(api.Namespace(ctx)).Path("pods").Path(pod.Name).Body(pod).Do().Into(result) return } @@ -168,7 +168,7 @@ func (c *Client) UpdateReplicationController(ctx api.Context, controller *api.Re err = fmt.Errorf("invalid update object, missing resource version: %v", controller) return } - err = c.Put().Namespace(api.Namespace(ctx)).Path("replicationControllers").Path(controller.ID).Body(controller).Do().Into(result) + err = c.Put().Namespace(api.Namespace(ctx)).Path("replicationControllers").Path(controller.Name).Body(controller).Do().Into(result) return } @@ -217,7 +217,7 @@ func (c *Client) UpdateService(ctx api.Context, svc *api.Service) (result *api.S err = fmt.Errorf("invalid update object, missing resource version: %v", svc) return } - err = c.Put().Namespace(api.Namespace(ctx)).Path("services").Path(svc.ID).Body(svc).Do().Into(result) + err = c.Put().Namespace(api.Namespace(ctx)).Path("services").Path(svc.Name).Body(svc).Do().Into(result) return } @@ -280,7 +280,7 @@ func (c *Client) UpdateEndpoints(ctx api.Context, endpoints *api.Endpoints) (*ap err := c.Put(). Namespace(api.Namespace(ctx)). Path("endpoints"). - Path(endpoints.ID). + Path(endpoints.Name). Body(endpoints). Do(). Into(result) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index ede1f193c62..62f74e265ba 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -266,7 +266,7 @@ func TestCreatePod(t *testing.T) { func TestUpdatePod(t *testing.T) { requestPod := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, CurrentState: api.PodState{ Status: "Foobar", }, @@ -290,7 +290,7 @@ func TestListControllers(t *testing.T) { Body: &api.ReplicationControllerList{ Items: []api.ReplicationController{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.ReplicationControllerState{ Replicas: 2, }, @@ -314,7 +314,7 @@ func TestGetController(t *testing.T) { Response: Response{ StatusCode: 200, Body: &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.ReplicationControllerState{ Replicas: 2, }, @@ -331,14 +331,14 @@ func TestGetController(t *testing.T) { func TestUpdateController(t *testing.T) { requestController := &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, } c := &testClient{ Request: testRequest{Method: "PUT", Path: "/replicationControllers/foo"}, Response: Response{ StatusCode: 200, Body: &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.ReplicationControllerState{ Replicas: 2, }, @@ -364,14 +364,14 @@ func TestDeleteController(t *testing.T) { func TestCreateController(t *testing.T) { requestController := &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, } c := &testClient{ Request: testRequest{Method: "POST", Path: "/replicationControllers", Body: requestController}, Response: Response{ StatusCode: 200, Body: &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.ReplicationControllerState{ Replicas: 2, }, @@ -402,7 +402,7 @@ func TestListServices(t *testing.T) { Body: &api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "name"}, + TypeMeta: api.TypeMeta{Name: "name"}, Labels: map[string]string{ "foo": "bar", "name": "baz", @@ -426,7 +426,7 @@ func TestListServicesLabels(t *testing.T) { Body: &api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "name"}, + TypeMeta: api.TypeMeta{Name: "name"}, Labels: map[string]string{ "foo": "bar", "name": "baz", @@ -449,7 +449,7 @@ func TestListServicesLabels(t *testing.T) { func TestGetService(t *testing.T) { c := &testClient{ Request: testRequest{Method: "GET", Path: "/services/1"}, - Response: Response{StatusCode: 200, Body: &api.Service{TypeMeta: api.TypeMeta{ID: "service-1"}}}, + Response: Response{StatusCode: 200, Body: &api.Service{TypeMeta: api.TypeMeta{Name: "service-1"}}}, } response, err := c.Setup().GetService(api.NewDefaultContext(), "1") c.Validate(t, response, err) @@ -457,15 +457,15 @@ func TestGetService(t *testing.T) { func TestCreateService(t *testing.T) { c := &testClient{ - Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{TypeMeta: api.TypeMeta{ID: "service-1"}}}, - Response: Response{StatusCode: 200, Body: &api.Service{TypeMeta: api.TypeMeta{ID: "service-1"}}}, + Request: testRequest{Method: "POST", Path: "/services", Body: &api.Service{TypeMeta: api.TypeMeta{Name: "service-1"}}}, + Response: Response{StatusCode: 200, Body: &api.Service{TypeMeta: api.TypeMeta{Name: "service-1"}}}, } - response, err := c.Setup().CreateService(api.NewDefaultContext(), &api.Service{TypeMeta: api.TypeMeta{ID: "service-1"}}) + response, err := c.Setup().CreateService(api.NewDefaultContext(), &api.Service{TypeMeta: api.TypeMeta{Name: "service-1"}}) c.Validate(t, response, err) } func TestUpdateService(t *testing.T) { - svc := &api.Service{TypeMeta: api.TypeMeta{ID: "service-1", ResourceVersion: "1"}} + svc := &api.Service{TypeMeta: api.TypeMeta{Name: "service-1", ResourceVersion: "1"}} c := &testClient{ Request: testRequest{Method: "PUT", Path: "/services/service-1", Body: svc}, Response: Response{StatusCode: 200, Body: svc}, @@ -490,7 +490,7 @@ func TestListEndpooints(t *testing.T) { Body: &api.EndpointsList{ Items: []api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "endpoint-1"}, + TypeMeta: api.TypeMeta{Name: "endpoint-1"}, Endpoints: []string{"10.245.1.2:8080", "10.245.1.3:8080"}, }, }, @@ -504,7 +504,7 @@ func TestListEndpooints(t *testing.T) { func TestGetEndpoints(t *testing.T) { c := &testClient{ Request: testRequest{Method: "GET", Path: "/endpoints/endpoint-1"}, - Response: Response{StatusCode: 200, Body: &api.Endpoints{TypeMeta: api.TypeMeta{ID: "endpoint-1"}}}, + Response: Response{StatusCode: 200, Body: &api.Endpoints{TypeMeta: api.TypeMeta{Name: "endpoint-1"}}}, } response, err := c.Setup().GetEndpoints(api.NewDefaultContext(), "endpoint-1") c.Validate(t, response, err) @@ -540,7 +540,7 @@ func TestGetServerVersion(t *testing.T) { func TestListMinions(t *testing.T) { c := &testClient{ Request: testRequest{Method: "GET", Path: "/minions"}, - Response: Response{StatusCode: 200, Body: &api.MinionList{TypeMeta: api.TypeMeta{ID: "minion-1"}}}, + Response: Response{StatusCode: 200, Body: &api.MinionList{TypeMeta: api.TypeMeta{Name: "minion-1"}}}, } response, err := c.Setup().ListMinions() c.Validate(t, response, err) @@ -549,7 +549,7 @@ func TestListMinions(t *testing.T) { func TestCreateMinion(t *testing.T) { requestMinion := &api.Minion{ TypeMeta: api.TypeMeta{ - ID: "minion-1", + Name: "minion-1", }, HostIP: "123.321.456.654", NodeResources: api.NodeResources{ diff --git a/pkg/client/fake.go b/pkg/client/fake.go index 3cfeab1b071..d8956331ce5 100644 --- a/pkg/client/fake.go +++ b/pkg/client/fake.go @@ -64,7 +64,7 @@ func (c *Fake) CreatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error) { } func (c *Fake) UpdatePod(ctx api.Context, pod *api.Pod) (*api.Pod, error) { - c.Actions = append(c.Actions, FakeAction{Action: "update-pod", Value: pod.ID}) + c.Actions = append(c.Actions, FakeAction{Action: "update-pod", Value: pod.Name}) return &api.Pod{}, nil } @@ -166,7 +166,7 @@ func (c *Fake) DeleteMinion(id string) error { // CreateEvent makes a new event. Returns the copy of the event the server returns, or an error. func (c *Fake) CreateEvent(event *api.Event) (*api.Event, error) { - c.Actions = append(c.Actions, FakeAction{Action: "get-event", Value: event.ID}) + c.Actions = append(c.Actions, FakeAction{Action: "get-event", Value: event.Name}) return &api.Event{}, nil } diff --git a/pkg/client/record/event_test.go b/pkg/client/record/event_test.go index c0f1e10b21c..9c58b23ec18 100644 --- a/pkg/client/record/event_test.go +++ b/pkg/client/record/event_test.go @@ -56,7 +56,7 @@ func TestEventf(t *testing.T) { obj: &api.Pod{ TypeMeta: api.TypeMeta{ SelfLink: "/api/v1beta1/pods/foo", - ID: "foo", + Name: "foo", }, }, fieldPath: "desiredState.manifest.containers[2]", diff --git a/pkg/client/request_test.go b/pkg/client/request_test.go index c57aaf20b18..5cfff0e248d 100644 --- a/pkg/client/request_test.go +++ b/pkg/client/request_test.go @@ -72,7 +72,7 @@ func TestDoRequestNewWay(t *testing.T) { } func TestDoRequestNewWayReader(t *testing.T) { - reqObj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + reqObj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} reqBodyExpected, _ := v1beta1.Codec.Encode(reqObj) expectedObj := &api.Service{Port: 12345} expectedBody, _ := v1beta1.Codec.Encode(expectedObj) @@ -108,7 +108,7 @@ func TestDoRequestNewWayReader(t *testing.T) { } func TestDoRequestNewWayObj(t *testing.T) { - reqObj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + reqObj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} reqBodyExpected, _ := v1beta2.Codec.Encode(reqObj) expectedObj := &api.Service{Port: 12345} expectedBody, _ := v1beta2.Codec.Encode(expectedObj) @@ -143,7 +143,7 @@ func TestDoRequestNewWayObj(t *testing.T) { } func TestDoRequestNewWayFile(t *testing.T) { - reqObj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + reqObj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} reqBodyExpected, err := v1beta1.Codec.Encode(reqObj) if err != nil { t.Errorf("unexpected error: %v", err) @@ -380,9 +380,9 @@ func TestWatch(t *testing.T) { t watch.EventType obj runtime.Object }{ - {watch.Added, &api.Pod{TypeMeta: api.TypeMeta{ID: "first"}}}, - {watch.Modified, &api.Pod{TypeMeta: api.TypeMeta{ID: "second"}}}, - {watch.Deleted, &api.Pod{TypeMeta: api.TypeMeta{ID: "last"}}}, + {watch.Added, &api.Pod{TypeMeta: api.TypeMeta{Name: "first"}}}, + {watch.Modified, &api.Pod{TypeMeta: api.TypeMeta{Name: "second"}}}, + {watch.Deleted, &api.Pod{TypeMeta: api.TypeMeta{Name: "last"}}}, } auth := &Config{Username: "user", Password: "pass"} diff --git a/pkg/cloudprovider/controller/minioncontroller.go b/pkg/cloudprovider/controller/minioncontroller.go index 05bf0bba6d2..a0fbadb3cec 100644 --- a/pkg/cloudprovider/controller/minioncontroller.go +++ b/pkg/cloudprovider/controller/minioncontroller.go @@ -70,19 +70,19 @@ func (s *MinionController) Sync() error { } minionMap := make(map[string]*api.Minion) for _, minion := range minions.Items { - minionMap[minion.ID] = &minion + minionMap[minion.Name] = &minion } // Create or delete minions from registry. - for _, match := range matches.Items { - if _, ok := minionMap[match.ID]; !ok { - glog.Infof("Create minion in registry: %s", match.ID) - err = s.registry.CreateMinion(nil, &match) + for _, minion := range matches.Items { + if _, ok := minionMap[minion.Name]; !ok { + glog.Infof("Create minion in registry: %s", minion.Name) + err = s.registry.CreateMinion(nil, &minion) if err != nil { return err } } - delete(minionMap, match.ID) + delete(minionMap, minion.Name) } for minionID := range minionMap { @@ -109,7 +109,7 @@ func (s *MinionController) cloudMinions() (*api.MinionList, error) { Items: make([]api.Minion, len(matches)), } for i := range matches { - result.Items[i].ID = matches[i] + result.Items[i].Name = matches[i] resources, err := instances.GetNodeResources(matches[i]) if err != nil { return nil, err diff --git a/pkg/cloudprovider/controller/minioncontroller_test.go b/pkg/cloudprovider/controller/minioncontroller_test.go index ef117fc44cd..d43f2948cfa 100644 --- a/pkg/cloudprovider/controller/minioncontroller_test.go +++ b/pkg/cloudprovider/controller/minioncontroller_test.go @@ -45,8 +45,8 @@ func NewTestEtcdRegistry(client tools.EtcdClient) *etcdregistry.Registry { func TestSyncCreateMinion(t *testing.T) { ctx := api.NewContext() fakeClient := tools.NewFakeEtcdClient(t) - m1 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "m1"}}) - m2 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "m2"}}) + m1 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{Name: "m1"}}) + m2 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{Name: "m2"}}) fakeClient.Set("/registry/minions/m1", m1, 0) fakeClient.Set("/registry/minions/m2", m2, 0) fakeClient.ExpectNotFoundGet("/registry/minions/m3") @@ -88,9 +88,9 @@ func TestSyncCreateMinion(t *testing.T) { func TestSyncDeleteMinion(t *testing.T) { ctx := api.NewContext() fakeClient := tools.NewFakeEtcdClient(t) - m1 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "m1"}}) - m2 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "m2"}}) - m3 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{ID: "m3"}}) + m1 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{Name: "m1"}}) + m2 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{Name: "m2"}}) + m3 := runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{Name: "m3"}}) fakeClient.Set("/registry/minions/m1", m1, 0) fakeClient.Set("/registry/minions/m2", m2, 0) fakeClient.Set("/registry/minions/m3", m3, 0) diff --git a/pkg/controller/replication_controller.go b/pkg/controller/replication_controller.go index 43a7369e1b6..afae3ef9d6a 100644 --- a/pkg/controller/replication_controller.go +++ b/pkg/controller/replication_controller.go @@ -56,7 +56,7 @@ func (r RealPodControl) createReplica(ctx api.Context, controllerSpec api.Replic labels := controllerSpec.DesiredState.PodTemplate.Labels // TODO: don't fail to set this label just because the map isn't created. if labels != nil { - labels["replicationController"] = controllerSpec.ID + labels["replicationController"] = controllerSpec.Name } pod := &api.Pod{ DesiredState: controllerSpec.DesiredState.PodTemplate.DesiredState, @@ -127,7 +127,7 @@ func (rm *ReplicationManager) watchControllers(resourceVersion *string) { *resourceVersion = rc.ResourceVersion // Sync even if this is a deletion event, to ensure that we leave // it in the desired state. - glog.V(4).Infof("About to sync from watch: %v", rc.ID) + glog.V(4).Infof("About to sync from watch: %v", rc.Name) rm.syncHandler(*rc) } } @@ -171,7 +171,7 @@ func (rm *ReplicationManager) syncReplicationController(controllerSpec api.Repli for i := 0; i < diff; i++ { go func(ix int) { defer wait.Done() - rm.podControl.deletePod(ctx, filteredList[ix].ID) + rm.podControl.deletePod(ctx, filteredList[ix].Name) }(i) } wait.Wait() @@ -195,7 +195,7 @@ func (rm *ReplicationManager) synchronize() { for ix := range controllerSpecs { go func(ix int) { defer wg.Done() - glog.V(4).Infof("periodic sync of %v", controllerSpecs[ix].ID) + glog.V(4).Infof("periodic sync of %v", controllerSpecs[ix].Name) err := rm.syncHandler(controllerSpecs[ix]) if err != nil { glog.Errorf("Error synchronizing: %#v", err) diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index 3e51c38fdf7..48672bf7ec7 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -90,7 +90,7 @@ func newPodList(count int) *api.PodList { for i := 0; i < count; i++ { pods = append(pods, api.Pod{ TypeMeta: api.TypeMeta{ - ID: fmt.Sprintf("pod%d", i), + Name: fmt.Sprintf("pod%d", i), }, }) } @@ -345,7 +345,7 @@ func TestWatchControllers(t *testing.T) { go manager.watchControllers(&resourceVersion) // Test normal case - testControllerSpec.ID = "foo" + testControllerSpec.Name = "foo" client.w.Add(&testControllerSpec) select { diff --git a/pkg/kubecfg/kubecfg.go b/pkg/kubecfg/kubecfg.go index 271f9048383..3d2843c294b 100644 --- a/pkg/kubecfg/kubecfg.go +++ b/pkg/kubecfg/kubecfg.go @@ -153,7 +153,7 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod for _, pod := range podList.Items { // We delete the pod here, the controller will recreate it. This will result in pulling // a new Docker image. This isn't a full "update" but it's what we support for now. - err = client.DeletePod(ctx, pod.ID) + err = client.DeletePod(ctx, pod.Name) if err != nil { return err } @@ -246,7 +246,7 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli } controller := &api.ReplicationController{ TypeMeta: api.TypeMeta{ - ID: name, + Name: name, }, DesiredState: api.ReplicationControllerState{ Replicas: replicas, @@ -299,7 +299,7 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli func createService(ctx api.Context, name string, port int, client client.Interface) (*api.Service, error) { svc := &api.Service{ - TypeMeta: api.TypeMeta{ID: name}, + TypeMeta: api.TypeMeta{Name: name}, Port: port, Labels: map[string]string{ "simpleService": name, diff --git a/pkg/kubecfg/kubecfg_test.go b/pkg/kubecfg/kubecfg_test.go index 4082f0f1d02..1ffee430b86 100644 --- a/pkg/kubecfg/kubecfg_test.go +++ b/pkg/kubecfg/kubecfg_test.go @@ -38,8 +38,8 @@ func TestUpdateWithPods(t *testing.T) { fakeClient := client.Fake{ Pods: api.PodList{ Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "pod-1"}}, - {TypeMeta: api.TypeMeta{ID: "pod-2"}}, + {TypeMeta: api.TypeMeta{Name: "pod-1"}}, + {TypeMeta: api.TypeMeta{Name: "pod-2"}}, }, }, } @@ -69,8 +69,8 @@ func TestUpdateWithNewImage(t *testing.T) { fakeClient := client.Fake{ Pods: api.PodList{ Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "pod-1"}}, - {TypeMeta: api.TypeMeta{ID: "pod-2"}}, + {TypeMeta: api.TypeMeta{Name: "pod-1"}}, + {TypeMeta: api.TypeMeta{Name: "pod-2"}}, }, }, Ctrl: api.ReplicationController{ @@ -114,7 +114,7 @@ func TestRunController(t *testing.T) { t.Errorf("Unexpected actions: %#v", fakeClient.Actions) } controller := fakeClient.Actions[0].Value.(*api.ReplicationController) - if controller.ID != name || + if controller.Name != name || controller.DesiredState.Replicas != replicas || controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image != image { t.Errorf("Unexpected controller: %#v", controller) @@ -135,7 +135,7 @@ func TestRunControllerWithWrongArgs(t *testing.T) { t.Errorf("Unexpected actions: %#v", fakeClient.Actions) } controller := fakeClient.Actions[0].Value.(*api.ReplicationController) - if controller.ID != name || + if controller.Name != name || controller.DesiredState.Replicas != replicas || controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image != image { t.Errorf("Unexpected controller: %#v", controller) @@ -154,7 +154,7 @@ func TestRunControllerWithService(t *testing.T) { t.Errorf("Unexpected actions: %#v", fakeClient.Actions) } controller := fakeClient.Actions[0].Value.(*api.ReplicationController) - if controller.ID != name || + if controller.Name != name || controller.DesiredState.Replicas != replicas || controller.DesiredState.PodTemplate.DesiredState.Manifest.Containers[0].Image != image { t.Errorf("Unexpected controller: %#v", controller) diff --git a/pkg/kubecfg/parse_test.go b/pkg/kubecfg/parse_test.go index d9f8930b3d1..43c27e67c8c 100644 --- a/pkg/kubecfg/parse_test.go +++ b/pkg/kubecfg/parse_test.go @@ -69,7 +69,7 @@ var testParser = NewParser(map[string]runtime.Object{ func TestParsePod(t *testing.T) { DoParseTest(t, "pods", &api.Pod{ - TypeMeta: api.TypeMeta{APIVersion: "v1beta1", ID: "test pod", Kind: "Pod"}, + TypeMeta: api.TypeMeta{APIVersion: "v1beta1", Name: "test pod", Kind: "Pod"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ ID: "My manifest", @@ -86,7 +86,7 @@ func TestParsePod(t *testing.T) { func TestParseService(t *testing.T) { DoParseTest(t, "services", &api.Service{ - TypeMeta: api.TypeMeta{APIVersion: "v1beta1", ID: "my service", Kind: "Service"}, + TypeMeta: api.TypeMeta{APIVersion: "v1beta1", Name: "my service", Kind: "Service"}, Port: 8080, Labels: map[string]string{ "area": "staging", @@ -99,7 +99,7 @@ func TestParseService(t *testing.T) { func TestParseController(t *testing.T) { DoParseTest(t, "replicationControllers", &api.ReplicationController{ - TypeMeta: api.TypeMeta{APIVersion: "v1beta1", ID: "my controller", Kind: "ReplicationController"}, + TypeMeta: api.TypeMeta{APIVersion: "v1beta1", Name: "my controller", Kind: "ReplicationController"}, DesiredState: api.ReplicationControllerState{ Replicas: 9001, PodTemplate: api.PodTemplate{ @@ -134,7 +134,7 @@ func TestParseCustomType(t *testing.T) { "custom": &TestParseType{}, }) DoParseTest(t, "custom", &TestParseType{ - TypeMeta: api.TypeMeta{APIVersion: "", ID: "my custom object", Kind: "TestParseType"}, + TypeMeta: api.TypeMeta{APIVersion: "", Name: "my custom object", Kind: "TestParseType"}, Data: "test data", }, v1beta1.Codec, parser) } diff --git a/pkg/kubecfg/resource_printer.go b/pkg/kubecfg/resource_printer.go index e528f82177f..eb15f9e2ecc 100644 --- a/pkg/kubecfg/resource_printer.go +++ b/pkg/kubecfg/resource_printer.go @@ -194,7 +194,7 @@ func podHostString(host, ip string) string { func printPod(pod *api.Pod, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", - pod.ID, makeImageList(pod.DesiredState.Manifest), + pod.Name, makeImageList(pod.DesiredState.Manifest), podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP), labels.Set(pod.Labels), pod.CurrentState.Status) return err @@ -209,16 +209,16 @@ func printPodList(podList *api.PodList, w io.Writer) error { return nil } -func printReplicationController(ctrl *api.ReplicationController, w io.Writer) error { +func printReplicationController(controller *api.ReplicationController, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n", - ctrl.ID, makeImageList(ctrl.DesiredState.PodTemplate.DesiredState.Manifest), - labels.Set(ctrl.DesiredState.ReplicaSelector), ctrl.DesiredState.Replicas) + controller.Name, makeImageList(controller.DesiredState.PodTemplate.DesiredState.Manifest), + labels.Set(controller.DesiredState.ReplicaSelector), controller.DesiredState.Replicas) return err } func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer) error { - for _, ctrl := range list.Items { - if err := printReplicationController(&ctrl, w); err != nil { + for _, controller := range list.Items { + if err := printReplicationController(&controller, w); err != nil { return err } } @@ -226,7 +226,7 @@ func printReplicationControllerList(list *api.ReplicationControllerList, w io.Wr } func printService(svc *api.Service, w io.Writer) error { - _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", svc.ID, labels.Set(svc.Labels), + _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", svc.Name, labels.Set(svc.Labels), labels.Set(svc.Selector), svc.PortalIP, svc.Port) return err } @@ -241,7 +241,7 @@ func printServiceList(list *api.ServiceList, w io.Writer) error { } func printMinion(minion *api.Minion, w io.Writer) error { - _, err := fmt.Fprintf(w, "%s\n", minion.ID) + _, err := fmt.Fprintf(w, "%s\n", minion.Name) return err } diff --git a/pkg/kubecfg/resource_printer_test.go b/pkg/kubecfg/resource_printer_test.go index 81455014514..4057874bb39 100644 --- a/pkg/kubecfg/resource_printer_test.go +++ b/pkg/kubecfg/resource_printer_test.go @@ -68,7 +68,7 @@ func TestYAMLPrinterPrint(t *testing.T) { } obj := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, } buf.Reset() printer.PrintObj(obj, buf) @@ -92,7 +92,7 @@ func TestIdentityPrinter(t *testing.T) { } obj := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, } buff.Reset() printer.PrintObj(obj, buff) diff --git a/pkg/kubectl/describe.go b/pkg/kubectl/describe.go index 0387a87c2ee..ed3990a1bdf 100644 --- a/pkg/kubectl/describe.go +++ b/pkg/kubectl/describe.go @@ -61,7 +61,7 @@ func describePod(w io.Writer, c client.Interface, id string) (string, error) { } return tabbedString(func(out *tabwriter.Writer) error { - fmt.Fprintf(out, "ID:\t%s\n", pod.ID) + fmt.Fprintf(out, "Name:\t%s\n", pod.Name) fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(pod.DesiredState.Manifest)) fmt.Fprintf(out, "Host:\t%s\n", pod.CurrentState.Host+"/"+pod.CurrentState.HostIP) fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(pod.Labels)) @@ -72,50 +72,50 @@ func describePod(w io.Writer, c client.Interface, id string) (string, error) { } func describeReplicationController(w io.Writer, c client.Interface, id string) (string, error) { - rc, err := c.GetReplicationController(api.NewDefaultContext(), id) + controller, err := c.GetReplicationController(api.NewDefaultContext(), id) if err != nil { return "", err } - running, waiting, terminated, err := getPodStatusForReplicationController(c, rc) + running, waiting, terminated, err := getPodStatusForReplicationController(c, controller) if err != nil { return "", err } return tabbedString(func(out *tabwriter.Writer) error { - fmt.Fprintf(out, "ID:\t%s\n", rc.ID) - fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(rc.DesiredState.PodTemplate.DesiredState.Manifest)) - fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(rc.DesiredState.ReplicaSelector)) - fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(rc.Labels)) - fmt.Fprintf(out, "Replicas:\t%d current / %d desired\n", rc.CurrentState.Replicas, rc.DesiredState.Replicas) + fmt.Fprintf(out, "Name:\t%s\n", controller.Name) + fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(controller.DesiredState.PodTemplate.DesiredState.Manifest)) + fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(controller.DesiredState.ReplicaSelector)) + fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(controller.Labels)) + fmt.Fprintf(out, "Replicas:\t%d current / %d desired\n", controller.CurrentState.Replicas, controller.DesiredState.Replicas) fmt.Fprintf(out, "Pods Status:\t%d Running / %d Waiting / %d Terminated\n", running, waiting, terminated) return nil }) } func describeService(w io.Writer, c client.Interface, id string) (string, error) { - s, err := c.GetService(api.NewDefaultContext(), id) + service, err := c.GetService(api.NewDefaultContext(), id) if err != nil { return "", err } return tabbedString(func(out *tabwriter.Writer) error { - fmt.Fprintf(out, "ID:\t%s\n", s.ID) - fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(s.Labels)) - fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(s.Selector)) - fmt.Fprintf(out, "Port:\t%d\n", s.Port) + fmt.Fprintf(out, "Name:\t%s\n", service.Name) + fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(service.Labels)) + fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(service.Selector)) + fmt.Fprintf(out, "Port:\t%d\n", service.Port) return nil }) } func describeMinion(w io.Writer, c client.Interface, id string) (string, error) { - m, err := getMinion(c, id) + minion, err := getMinion(c, id) if err != nil { return "", err } return tabbedString(func(out *tabwriter.Writer) error { - fmt.Fprintf(out, "ID:\t%s\n", m.ID) + fmt.Fprintf(out, "Name:\t%s\n", minion.Name) return nil }) } @@ -127,9 +127,9 @@ func getMinion(c client.Interface, id string) (*api.Minion, error) { glog.Fatalf("Error getting minion info: %v\n", err) } - for _, m := range minionList.Items { - if id == m.TypeMeta.ID { - return &m, nil + for _, minion := range minionList.Items { + if id == minion.Name { + return &minion, nil } } return nil, fmt.Errorf("Minion %s not found", id) @@ -148,17 +148,17 @@ func getReplicationControllersForLabels(c client.Interface, labelsToMatch labels // Find the ones that match labelsToMatch. var matchingRCs []api.ReplicationController - for _, rc := range rcs.Items { - selector := labels.SelectorFromSet(rc.DesiredState.ReplicaSelector) + for _, controller := range rcs.Items { + selector := labels.SelectorFromSet(controller.DesiredState.ReplicaSelector) if selector.Matches(labelsToMatch) { - matchingRCs = append(matchingRCs, rc) + matchingRCs = append(matchingRCs, controller) } } // Format the matching RC's into strings. var rcStrings []string - for _, rc := range matchingRCs { - rcStrings = append(rcStrings, fmt.Sprintf("%s (%d/%d replicas created)", rc.ID, rc.CurrentState.Replicas, rc.DesiredState.Replicas)) + for _, controller := range matchingRCs { + rcStrings = append(rcStrings, fmt.Sprintf("%s (%d/%d replicas created)", controller.Name, controller.CurrentState.Replicas, controller.DesiredState.Replicas)) } list := strings.Join(rcStrings, ", ") @@ -168,8 +168,8 @@ func getReplicationControllersForLabels(c client.Interface, labelsToMatch labels return list } -func getPodStatusForReplicationController(kubeClient client.Interface, rc *api.ReplicationController) (running, waiting, terminated int, err error) { - rcPods, err := kubeClient.ListPods(api.NewDefaultContext(), labels.SelectorFromSet(rc.DesiredState.ReplicaSelector)) +func getPodStatusForReplicationController(kubeClient client.Interface, controller *api.ReplicationController) (running, waiting, terminated int, err error) { + rcPods, err := kubeClient.ListPods(api.NewDefaultContext(), labels.SelectorFromSet(controller.DesiredState.ReplicaSelector)) if err != nil { return } diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index 0dfa7af23f1..1a6429b88be 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -194,7 +194,7 @@ func podHostString(host, ip string) string { func printPod(pod *api.Pod, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", - pod.ID, makeImageList(pod.DesiredState.Manifest), + pod.Name, makeImageList(pod.DesiredState.Manifest), podHostString(pod.CurrentState.Host, pod.CurrentState.HostIP), labels.Set(pod.Labels), pod.CurrentState.Status) return err @@ -209,16 +209,16 @@ func printPodList(podList *api.PodList, w io.Writer) error { return nil } -func printReplicationController(ctrl *api.ReplicationController, w io.Writer) error { +func printReplicationController(controller *api.ReplicationController, w io.Writer) error { _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n", - ctrl.ID, makeImageList(ctrl.DesiredState.PodTemplate.DesiredState.Manifest), - labels.Set(ctrl.DesiredState.ReplicaSelector), ctrl.DesiredState.Replicas) + controller.Name, makeImageList(controller.DesiredState.PodTemplate.DesiredState.Manifest), + labels.Set(controller.DesiredState.ReplicaSelector), controller.DesiredState.Replicas) return err } func printReplicationControllerList(list *api.ReplicationControllerList, w io.Writer) error { - for _, ctrl := range list.Items { - if err := printReplicationController(&ctrl, w); err != nil { + for _, controller := range list.Items { + if err := printReplicationController(&controller, w); err != nil { return err } } @@ -226,7 +226,7 @@ func printReplicationControllerList(list *api.ReplicationControllerList, w io.Wr } func printService(svc *api.Service, w io.Writer) error { - _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", svc.ID, labels.Set(svc.Labels), + _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", svc.Name, labels.Set(svc.Labels), labels.Set(svc.Selector), svc.PortalIP, svc.Port) return err } @@ -241,7 +241,7 @@ func printServiceList(list *api.ServiceList, w io.Writer) error { } func printMinion(minion *api.Minion, w io.Writer) error { - _, err := fmt.Fprintf(w, "%s\n", minion.ID) + _, err := fmt.Fprintf(w, "%s\n", minion.Name) return err } diff --git a/pkg/kubectl/resource_printer_test.go b/pkg/kubectl/resource_printer_test.go index 4fb1d56470c..284d56f4465 100644 --- a/pkg/kubectl/resource_printer_test.go +++ b/pkg/kubectl/resource_printer_test.go @@ -69,7 +69,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data } obj := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, } buf.Reset() printer.PrintObj(obj, buf) diff --git a/pkg/kubelet/config/config.go b/pkg/kubelet/config/config.go index 9c57ccc52d8..d2868c71af2 100644 --- a/pkg/kubelet/config/config.go +++ b/pkg/kubelet/config/config.go @@ -260,7 +260,7 @@ func filterInvalidPods(pods []api.BoundPod, source string) (filtered []*api.Boun var errors []error name := podUniqueName(&pods[i]) if names.Has(name) { - errors = append(errors, apierrs.NewFieldDuplicate("name", pods[i].ID)) + errors = append(errors, apierrs.NewFieldDuplicate("name", pods[i].Name)) } else { names.Insert(name) } @@ -268,7 +268,7 @@ func filterInvalidPods(pods []api.BoundPod, source string) (filtered []*api.Boun errors = append(errors, errs...) } if len(errors) > 0 { - glog.Warningf("Pod %d (%s) from %s failed validation, ignoring: %v", i+1, pods[i].ID, source, errors) + glog.Warningf("Pod %d (%s) from %s failed validation, ignoring: %v", i+1, pods[i].Name, source, errors) continue } filtered = append(filtered, &pods[i]) @@ -307,5 +307,5 @@ func podUniqueName(pod *api.BoundPod) string { if len(namespace) == 0 { namespace = api.NamespaceDefault } - return fmt.Sprintf("%s.%s", pod.ID, namespace) + return fmt.Sprintf("%s.%s", pod.Name, namespace) } diff --git a/pkg/kubelet/config/config_test.go b/pkg/kubelet/config/config_test.go index 2d961e2c476..48c9501d627 100644 --- a/pkg/kubelet/config/config_test.go +++ b/pkg/kubelet/config/config_test.go @@ -45,13 +45,13 @@ func (s sortedPods) Less(i, j int) bool { if s[i].Namespace < s[j].Namespace { return true } - return s[i].ID < s[j].ID + return s[i].Name < s[j].Name } func CreateValidPod(name, namespace, source string) api.BoundPod { return api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: name, + Name: name, Namespace: namespace, Annotations: map[string]string{kubelet.ConfigSourceAnnotationKey: source}, }, @@ -158,7 +158,7 @@ func TestInvalidPodFiltered(t *testing.T) { expectPodUpdate(t, ch, CreatePodUpdate(kubelet.ADD, CreateValidPod("foo", "new", "test"))) // add an invalid update - podUpdate = CreatePodUpdate(kubelet.UPDATE, api.BoundPod{TypeMeta: api.TypeMeta{ID: "foo"}}) + podUpdate = CreatePodUpdate(kubelet.UPDATE, api.BoundPod{TypeMeta: api.TypeMeta{Name: "foo"}}) channel <- podUpdate expectNoPodUpdate(t, ch) } @@ -217,7 +217,7 @@ func TestNewPodAddedUpdatedRemoved(t *testing.T) { channel <- podUpdate expectPodUpdate(t, ch, CreatePodUpdate(kubelet.UPDATE, pod)) - podUpdate = CreatePodUpdate(kubelet.REMOVE, api.BoundPod{TypeMeta: api.TypeMeta{ID: "foo", Namespace: "new"}}) + podUpdate = CreatePodUpdate(kubelet.REMOVE, api.BoundPod{TypeMeta: api.TypeMeta{Name: "foo", Namespace: "new"}}) channel <- podUpdate expectPodUpdate(t, ch, CreatePodUpdate(kubelet.REMOVE, pod)) } diff --git a/pkg/kubelet/config/etcd.go b/pkg/kubelet/config/etcd.go index aae9d07d2d6..0ba08f70372 100644 --- a/pkg/kubelet/config/etcd.go +++ b/pkg/kubelet/config/etcd.go @@ -95,8 +95,8 @@ func eventToPods(ev watch.Event) ([]api.BoundPod, error) { } for i, pod := range boundPods.Items { - if len(pod.ID) == 0 { - pod.ID = fmt.Sprintf("%d", i+1) + if len(pod.Name) == 0 { + pod.Name = fmt.Sprintf("%d", i+1) } // TODO: generate random UID if not present if pod.UID == "" && !pod.CreationTimestamp.IsZero() { diff --git a/pkg/kubelet/config/etcd_test.go b/pkg/kubelet/config/etcd_test.go index 6e3cb10126e..3cb6d5a0cca 100644 --- a/pkg/kubelet/config/etcd_test.go +++ b/pkg/kubelet/config/etcd_test.go @@ -44,14 +44,14 @@ func TestEventToPods(t *testing.T) { input: watch.Event{ Object: &api.BoundPods{ Items: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, - {TypeMeta: api.TypeMeta{ID: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, }, }, }, pods: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "foo", Namespace: "default"}, Spec: api.PodSpec{}}, - {TypeMeta: api.TypeMeta{ID: "bar", Namespace: "default"}, Spec: api.PodSpec{}}, + {TypeMeta: api.TypeMeta{Name: "foo", Namespace: "default"}, Spec: api.PodSpec{}}, + {TypeMeta: api.TypeMeta{Name: "bar", Namespace: "default"}, Spec: api.PodSpec{}}, }, fail: false, }, @@ -59,14 +59,14 @@ func TestEventToPods(t *testing.T) { input: watch.Event{ Object: &api.BoundPods{ Items: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "1"}}, - {TypeMeta: api.TypeMeta{ID: "2", Namespace: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "1"}}, + {TypeMeta: api.TypeMeta{Name: "2", Namespace: "foo"}}, }, }, }, pods: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "1", Namespace: "default"}, Spec: api.PodSpec{}}, - {TypeMeta: api.TypeMeta{ID: "2", Namespace: "foo"}, Spec: api.PodSpec{}}, + {TypeMeta: api.TypeMeta{Name: "1", Namespace: "default"}, Spec: api.PodSpec{}}, + {TypeMeta: api.TypeMeta{Name: "2", Namespace: "foo"}, Spec: api.PodSpec{}}, }, fail: false, }, diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index ffc900c069b..89871095620 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -153,7 +153,7 @@ func extractFromFile(filename string) (api.BoundPod, error) { return pod, fmt.Errorf("can't convert pod from file %q: %v", filename, err) } - pod.ID = simpleSubdomainSafeHash(filename) + pod.Name = simpleSubdomainSafeHash(filename) if len(pod.UID) == 0 { pod.UID = simpleSubdomainSafeHash(filename) } @@ -164,7 +164,7 @@ func extractFromFile(filename string) (api.BoundPod, error) { if glog.V(4) { glog.Infof("Got pod from file %q: %#v", filename, pod) } else { - glog.V(1).Infof("Got pod from file %q: %s.%s (%s)", filename, pod.Namespace, pod.ID, pod.UID) + glog.V(1).Infof("Got pod from file %q: %s.%s (%s)", filename, pod.Namespace, pod.Name, pod.UID) } return pod, nil } diff --git a/pkg/kubelet/config/file_test.go b/pkg/kubelet/config/file_test.go index 0e280f49e7e..77b27dec22a 100644 --- a/pkg/kubelet/config/file_test.go +++ b/pkg/kubelet/config/file_test.go @@ -53,7 +53,7 @@ func ExampleManifestAndPod(id string) (api.ContainerManifest, api.BoundPod) { } expectedPod := api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: id, + Name: id, UID: "uid", Namespace: "default", }, @@ -119,7 +119,7 @@ func TestReadFromFile(t *testing.T) { update := got.(kubelet.PodUpdate) expected := CreatePodUpdate(kubelet.SET, api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: simpleSubdomainSafeHash(file.Name()), + Name: simpleSubdomainSafeHash(file.Name()), UID: simpleSubdomainSafeHash(file.Name()), Namespace: "default", }, @@ -159,7 +159,7 @@ func TestExtractFromValidDataFile(t *testing.T) { file := writeTestFile(t, os.TempDir(), "test_pod_config", string(text)) defer os.Remove(file.Name()) - expectedPod.ID = simpleSubdomainSafeHash(file.Name()) + expectedPod.Name = simpleSubdomainSafeHash(file.Name()) ch := make(chan interface{}, 1) c := SourceFile{file.Name(), ch} @@ -226,7 +226,7 @@ func TestExtractFromDir(t *testing.T) { } ioutil.WriteFile(name, data, 0755) files[i] = file - pods[i].ID = simpleSubdomainSafeHash(name) + pods[i].Name = simpleSubdomainSafeHash(name) } ch := make(chan interface{}, 1) diff --git a/pkg/kubelet/config/http.go b/pkg/kubelet/config/http.go index 455201b13b3..4ca0e9c3959 100644 --- a/pkg/kubelet/config/http.go +++ b/pkg/kubelet/config/http.go @@ -92,8 +92,8 @@ func (s *SourceURL) extractFromURL() error { if err := api.Scheme.Convert(&manifest, &pod); err != nil { return err } - if len(pod.ID) == 0 { - pod.ID = "1" + if len(pod.Name) == 0 { + pod.Name = "1" } if len(pod.Namespace) == 0 { pod.Namespace = api.NamespaceDefault @@ -132,8 +132,8 @@ func (s *SourceURL) extractFromURL() error { } for i := range boundPods.Items { pod := &boundPods.Items[i] - if len(pod.ID) == 0 { - pod.ID = fmt.Sprintf("%d", i+1) + if len(pod.Name) == 0 { + pod.Name = fmt.Sprintf("%d", i+1) } if len(pod.Namespace) == 0 { pod.Namespace = api.NamespaceDefault diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index 13a08aeaf41..76cf2b2768c 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -125,7 +125,7 @@ func TestExtractFromHTTP(t *testing.T) { expected: CreatePodUpdate(kubelet.SET, api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "default", }, Spec: api.PodSpec{ @@ -142,14 +142,14 @@ func TestExtractFromHTTP(t *testing.T) { expected: CreatePodUpdate(kubelet.SET, api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "1", + Name: "1", Namespace: "default", }, Spec: api.PodSpec{Containers: []api.Container{{Name: "1", Image: "foo"}}}, }, api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "bar", + Name: "bar", Namespace: "default", }, Spec: api.PodSpec{Containers: []api.Container{{Name: "1", Image: "foo"}}}, diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index c55622f839c..7938e086bda 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -279,7 +279,7 @@ func milliCPUToShares(milliCPU int) int { func (kl *Kubelet) mountExternalVolumes(pod *api.BoundPod) (volumeMap, error) { podVolumes := make(volumeMap) for _, vol := range pod.Spec.Volumes { - extVolume, err := volume.CreateVolumeBuilder(&vol, pod.ID, kl.rootDirectory) + extVolume, err := volume.CreateVolumeBuilder(&vol, pod.Name, kl.rootDirectory) if err != nil { return nil, err } @@ -334,7 +334,7 @@ func (kl *Kubelet) runContainer(pod *api.BoundPod, container *api.Container, pod Cmd: container.Command, Env: envVariables, ExposedPorts: exposedPorts, - Hostname: pod.ID, + Hostname: pod.Name, Image: container.Image, Memory: int64(container.Memory), CpuShares: int64(milliCPUToShares(container.CPU)), @@ -609,7 +609,7 @@ func getDesiredVolumes(pods []api.BoundPod) map[string]api.Volume { desiredVolumes := make(map[string]api.Volume) for _, pod := range pods { for _, volume := range pod.Spec.Volumes { - identifier := path.Join(pod.ID, volume.Name) + identifier := path.Join(pod.Name, volume.Name) desiredVolumes[identifier] = volume } } diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index b0dff6f9705..0ca6174dfa3 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -114,7 +114,7 @@ func TestKillContainer(t *testing.T) { }, } fakeDocker.Container = &docker.Container{ - ID: "foobar", + Name: "foobar", } err := kubelet.killContainer(&fakeDocker.ContainerList[0]) @@ -168,7 +168,7 @@ func TestSyncPodsDoesNothing(t *testing.T) { err := kubelet.SyncPods([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -214,7 +214,7 @@ func TestSyncPodsCreatesNetAndContainer(t *testing.T) { err := kubelet.SyncPods([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -262,7 +262,7 @@ func TestSyncPodsCreatesNetAndContainerPullsImage(t *testing.T) { err := kubelet.SyncPods([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -307,7 +307,7 @@ func TestSyncPodsWithNetCreatesContainer(t *testing.T) { err := kubelet.SyncPods([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -348,7 +348,7 @@ func TestSyncPodsWithNetCreatesContainerCallsHandler(t *testing.T) { err := kubelet.SyncPods([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -401,7 +401,7 @@ func TestSyncPodsDeletesWithNoNetContainer(t *testing.T) { err := kubelet.SyncPods([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -496,7 +496,7 @@ func TestSyncPodDeletesDuplicate(t *testing.T) { } err := kubelet.syncPod(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "bar", + Name: "bar", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -545,7 +545,7 @@ func TestSyncPodBadHash(t *testing.T) { } err := kubelet.syncPod(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -589,7 +589,7 @@ func TestSyncPodUnhealthy(t *testing.T) { } err := kubelet.syncPod(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -649,7 +649,7 @@ func TestMountExternalVolumes(t *testing.T) { kubelet, _, _ := newTestKubelet(t) pod := api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "test", }, Spec: api.PodSpec{ @@ -704,7 +704,7 @@ func TestMakeVolumesAndBinds(t *testing.T) { pod := api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "pod", + Name: "pod", Namespace: "test", }, } @@ -991,7 +991,7 @@ func TestRunInContainerNoSuchPod(t *testing.T) { podNamespace := "etcd" containerName := "containerFoo" output, err := kubelet.RunInContainer( - GetPodFullName(&api.BoundPod{TypeMeta: api.TypeMeta{ID: podName, Namespace: podNamespace}}), + GetPodFullName(&api.BoundPod{TypeMeta: api.TypeMeta{Name: podName, Namespace: podNamespace}}), "", containerName, []string{"ls"}) @@ -1024,7 +1024,7 @@ func TestRunInContainer(t *testing.T) { _, err := kubelet.RunInContainer( GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: podName, + Name: podName, Namespace: podNamespace, Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -1033,7 +1033,7 @@ func TestRunInContainer(t *testing.T) { containerName, cmd) if fakeCommandRunner.ID != containerID { - t.Errorf("unexected ID: %s", fakeCommandRunner.ID) + t.Errorf("unexected Name: %s", fakeCommandRunner.ID) } if !reflect.DeepEqual(fakeCommandRunner.Cmd, cmd) { t.Errorf("unexpected commnd: %s", fakeCommandRunner.Cmd) @@ -1166,7 +1166,7 @@ func TestSyncPodEventHandlerFails(t *testing.T) { } err := kubelet.syncPod(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, diff --git a/pkg/kubelet/runonce.go b/pkg/kubelet/runonce.go index 0f45aa87cb2..0179c31e0ee 100644 --- a/pkg/kubelet/runonce.go +++ b/pkg/kubelet/runonce.go @@ -73,10 +73,10 @@ func (kl *Kubelet) runOnce(pods []api.BoundPod) (results []RunPodResult, err err results = append(results, res) if res.Err != nil { // TODO(proppy): report which containers failed the pod. - glog.Infof("failed to start pod %q: %v", res.Pod.ID, res.Err) - failedPods = append(failedPods, res.Pod.ID) + glog.Infof("failed to start pod %q: %v", res.Pod.Name, res.Err) + failedPods = append(failedPods, res.Pod.Name) } else { - glog.Infof("started pod %q", res.Pod.ID) + glog.Infof("started pod %q", res.Pod.Name) } } if len(failedPods) > 0 { @@ -100,18 +100,18 @@ func (kl *Kubelet) runPod(pod api.BoundPod) error { return fmt.Errorf("failed to check pod status: %v", err) } if running { - glog.Infof("pod %q containers running", pod.ID) + glog.Infof("pod %q containers running", pod.Name) return nil } - glog.Infof("pod %q containers not running: syncing", pod.ID) + glog.Infof("pod %q containers not running: syncing", pod.Name) if err = kl.syncPod(&pod, dockerContainers); err != nil { return fmt.Errorf("error syncing pod: %v", err) } if retry >= RunOnceMaxRetries { - return fmt.Errorf("timeout error: pod %q containers not running after %d retries", pod.ID, RunOnceMaxRetries) + return fmt.Errorf("timeout error: pod %q containers not running after %d retries", pod.Name, RunOnceMaxRetries) } // TODO(proppy): health checking would be better than waiting + checking the state at the next iteration. - glog.Infof("pod %q containers synced, waiting for %v", pod.ID, delay) + glog.Infof("pod %q containers synced, waiting for %v", pod.Name, delay) <-time.After(delay) retry++ delay *= RunOnceRetryDelayBackoff diff --git a/pkg/kubelet/runonce_test.go b/pkg/kubelet/runonce_test.go index e23be900585..287c0be1d8c 100644 --- a/pkg/kubelet/runonce_test.go +++ b/pkg/kubelet/runonce_test.go @@ -109,7 +109,7 @@ func TestRunOnce(t *testing.T) { results, err := kb.runOnce([]api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", Namespace: "new", Annotations: map[string]string{ConfigSourceAnnotationKey: "test"}, }, @@ -126,7 +126,7 @@ func TestRunOnce(t *testing.T) { if results[0].Err != nil { t.Errorf("unexpected run pod error: %v", results[0].Err) } - if results[0].Pod.ID != "foo" { - t.Errorf("unexpected pod: %q", results[0].Pod.ID) + if results[0].Pod.Name != "foo" { + t.Errorf("unexpected pod: %q", results[0].Pod.Name) } } diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index bce646081cc..238bbe1f254 100644 --- a/pkg/kubelet/server.go +++ b/pkg/kubelet/server.go @@ -126,14 +126,14 @@ func (s *Server) handleContainer(w http.ResponseWriter, req *http.Request) { s.error(w, err) return } - pod.ID = containerManifest.ID + pod.Name = containerManifest.ID pod.UID = containerManifest.UUID pod.Spec.Containers = containerManifest.Containers pod.Spec.Volumes = containerManifest.Volumes pod.Spec.RestartPolicy = containerManifest.RestartPolicy //TODO: sha1 of manifest? - if pod.ID == "" { - pod.ID = "1" + if pod.Name == "" { + pod.Name = "1" } if pod.UID == "" { pod.UID = "1" @@ -158,7 +158,7 @@ func (s *Server) handleContainers(w http.ResponseWriter, req *http.Request) { } pods := make([]api.BoundPod, len(specs)) for i := range specs { - pods[i].ID = fmt.Sprintf("%d", i+1) + pods[i].Name = fmt.Sprintf("%d", i+1) pods[i].Spec = specs[i] } s.updates <- PodUpdate{pods, SET} @@ -205,7 +205,7 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) { podFullName := GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: podID, + Name: podID, Namespace: podNamespace, Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"}, }, @@ -249,7 +249,7 @@ func (s *Server) handlePodInfo(w http.ResponseWriter, req *http.Request) { // TODO: backwards compatibility with existing API, needs API change podFullName := GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: podID, + Name: podID, Namespace: podNamespace, Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"}, }, @@ -324,7 +324,7 @@ func (s *Server) handleRun(w http.ResponseWriter, req *http.Request) { } podFullName := GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: podID, + Name: podID, Namespace: podNamespace, Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"}, }, @@ -374,7 +374,7 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) { // Backward compatibility without uuid information podFullName := GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: components[1], + Name: components[1], // TODO: I am broken Namespace: api.NamespaceDefault, Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"}, @@ -384,7 +384,7 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) { case 4: podFullName := GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: components[1], + Name: components[1], // TODO: I am broken Namespace: "", Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"}, diff --git a/pkg/kubelet/server_test.go b/pkg/kubelet/server_test.go index 9d53cff7653..d8d31194e50 100644 --- a/pkg/kubelet/server_test.go +++ b/pkg/kubelet/server_test.go @@ -133,8 +133,8 @@ func TestContainer(t *testing.T) { expectedPods := []api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "test_manifest", - UID: "value", + Name: "test_manifest", + UID: "value", }, Spec: api.PodSpec{ Containers: []api.Container{ @@ -208,7 +208,7 @@ func TestContainers(t *testing.T) { expectedPods := []api.BoundPod{ { TypeMeta: api.TypeMeta{ - ID: "1", + Name: "1", }, Spec: api.PodSpec{ Containers: []api.Container{ @@ -228,7 +228,7 @@ func TestContainers(t *testing.T) { }, { TypeMeta: api.TypeMeta{ - ID: "2", + Name: "2", }, Spec: api.PodSpec{ Containers: []api.Container{ diff --git a/pkg/kubelet/types.go b/pkg/kubelet/types.go index d8f167f909d..818104a9a12 100644 --- a/pkg/kubelet/types.go +++ b/pkg/kubelet/types.go @@ -50,5 +50,5 @@ type PodUpdate struct { // GetPodFullName returns a name that uniquely identifies a pod across all config sources. func GetPodFullName(pod *api.BoundPod) string { - return fmt.Sprintf("%s.%s.%s", pod.ID, pod.Namespace, pod.Annotations[ConfigSourceAnnotationKey]) + return fmt.Sprintf("%s.%s.%s", pod.Name, pod.Namespace, pod.Annotations[ConfigSourceAnnotationKey]) } diff --git a/pkg/master/master.go b/pkg/master/master.go index 8f1f5a6c305..fdc02ce49b2 100644 --- a/pkg/master/master.go +++ b/pkg/master/master.go @@ -126,7 +126,7 @@ func (m *Master) init(c *Config) { } else { for _, minionID := range c.Minions { m.minionRegistry.CreateMinion(nil, &api.Minion{ - TypeMeta: api.TypeMeta{ID: minionID}, + TypeMeta: api.TypeMeta{Name: minionID}, NodeResources: c.NodeResources, }) } diff --git a/pkg/master/pod_cache.go b/pkg/master/pod_cache.go index 45bae7a79ff..36a7616d44b 100644 --- a/pkg/master/pod_cache.go +++ b/pkg/master/pod_cache.go @@ -87,7 +87,7 @@ func (p *PodCache) UpdateAllContainers() { if pod.CurrentState.Host == "" { continue } - err := p.updatePodInfo(pod.CurrentState.Host, pod.Namespace, pod.ID) + err := p.updatePodInfo(pod.CurrentState.Host, pod.Namespace, pod.Name) if err != nil && err != client.ErrPodInfoNotAvailable { glog.Errorf("Error synchronizing container: %v", err) } diff --git a/pkg/master/pod_cache_test.go b/pkg/master/pod_cache_test.go index a67f52de014..ac3b096fb39 100644 --- a/pkg/master/pod_cache_test.go +++ b/pkg/master/pod_cache_test.go @@ -124,7 +124,7 @@ func TestPodGetPodInfoGetter(t *testing.T) { func TestPodUpdateAllContainers(t *testing.T) { pod := api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", Namespace: api.NamespaceDefault}, + TypeMeta: api.TypeMeta{Name: "foo", Namespace: api.NamespaceDefault}, CurrentState: api.PodState{ Host: "machine", }, diff --git a/pkg/proxy/config/api_test.go b/pkg/proxy/config/api_test.go index e7944d28d37..bba7dbc4da9 100644 --- a/pkg/proxy/config/api_test.go +++ b/pkg/proxy/config/api_test.go @@ -27,7 +27,7 @@ import ( ) func TestServices(t *testing.T) { - service := api.Service{TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}} + service := api.Service{TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}} fakeWatch := watch.NewFake() fakeClient := &client.Fake{Watch: fakeWatch} @@ -72,7 +72,7 @@ func TestServices(t *testing.T) { } func TestServicesFromZero(t *testing.T) { - service := api.Service{TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}} + service := api.Service{TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}} fakeWatch := watch.NewFake() fakeWatch.Stop() @@ -152,7 +152,7 @@ func TestServicesFromZeroError(t *testing.T) { } func TestEndpoints(t *testing.T) { - endpoint := api.Endpoints{TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}, Endpoints: []string{"127.0.0.1:9000"}} + endpoint := api.Endpoints{TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}, Endpoints: []string{"127.0.0.1:9000"}} fakeWatch := watch.NewFake() fakeClient := &client.Fake{Watch: fakeWatch} @@ -197,7 +197,7 @@ func TestEndpoints(t *testing.T) { } func TestEndpointsFromZero(t *testing.T) { - endpoint := api.Endpoints{TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}, Endpoints: []string{"127.0.0.1:9000"}} + endpoint := api.Endpoints{TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}, Endpoints: []string{"127.0.0.1:9000"}} fakeWatch := watch.NewFake() fakeWatch.Stop() diff --git a/pkg/proxy/config/config.go b/pkg/proxy/config/config.go index 007aa91991e..2fd8b8d47c7 100644 --- a/pkg/proxy/config/config.go +++ b/pkg/proxy/config/config.go @@ -127,19 +127,19 @@ func (s *endpointsStore) Merge(source string, change interface{}) error { case ADD: glog.V(4).Infof("Adding new endpoint from source %s : %v", source, update.Endpoints) for _, value := range update.Endpoints { - endpoints[value.ID] = value + endpoints[value.Name] = value } case REMOVE: glog.V(4).Infof("Removing an endpoint %v", update) for _, value := range update.Endpoints { - delete(endpoints, value.ID) + delete(endpoints, value.Name) } case SET: glog.V(4).Infof("Setting endpoints %v", update) // Clear the old map entries by just creating a new map endpoints = make(map[string]api.Endpoints) for _, value := range update.Endpoints { - endpoints[value.ID] = value + endpoints[value.Name] = value } default: glog.V(4).Infof("Received invalid update type: %v", update) @@ -222,19 +222,19 @@ func (s *serviceStore) Merge(source string, change interface{}) error { case ADD: glog.V(4).Infof("Adding new service from source %s : %v", source, update.Services) for _, value := range update.Services { - services[value.ID] = value + services[value.Name] = value } case REMOVE: glog.V(4).Infof("Removing a service %v", update) for _, value := range update.Services { - delete(services, value.ID) + delete(services, value.Name) } case SET: glog.V(4).Infof("Setting services %v", update) // Clear the old map entries by just creating a new map services = make(map[string]api.Service) for _, value := range update.Services { - services[value.ID] = value + services[value.Name] = value } default: glog.V(4).Infof("Received invalid update type: %v", update) diff --git a/pkg/proxy/config/config_test.go b/pkg/proxy/config/config_test.go index 5a8f89674be..95d0bebb1ce 100644 --- a/pkg/proxy/config/config_test.go +++ b/pkg/proxy/config/config_test.go @@ -45,7 +45,7 @@ func (s sortedServices) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s sortedServices) Less(i, j int) bool { - return s[i].TypeMeta.ID < s[j].TypeMeta.ID + return s[i].Name < s[j].Name } type ServiceHandlerMock struct { @@ -83,7 +83,7 @@ func (s sortedEndpoints) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s sortedEndpoints) Less(i, j int) bool { - return s[i].ID < s[j].ID + return s[i].Name < s[j].Name } type EndpointsHandlerMock struct { @@ -136,7 +136,7 @@ func TestNewServiceAddedAndNotified(t *testing.T) { handler := NewServiceHandlerMock() handler.Wait(1) config.RegisterHandler(handler) - serviceUpdate := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "foo"}, Port: 10}) + serviceUpdate := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "foo"}, Port: 10}) channel <- serviceUpdate handler.ValidateServices(t, serviceUpdate.Services) @@ -147,24 +147,24 @@ func TestServiceAddedRemovedSetAndNotified(t *testing.T) { channel := config.Channel("one") handler := NewServiceHandlerMock() config.RegisterHandler(handler) - serviceUpdate := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "foo"}, Port: 10}) + serviceUpdate := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "foo"}, Port: 10}) handler.Wait(1) channel <- serviceUpdate handler.ValidateServices(t, serviceUpdate.Services) - serviceUpdate2 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "bar"}, Port: 20}) + serviceUpdate2 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "bar"}, Port: 20}) handler.Wait(1) channel <- serviceUpdate2 services := []api.Service{serviceUpdate2.Services[0], serviceUpdate.Services[0]} handler.ValidateServices(t, services) - serviceUpdate3 := CreateServiceUpdate(REMOVE, api.Service{TypeMeta: api.TypeMeta{ID: "foo"}}) + serviceUpdate3 := CreateServiceUpdate(REMOVE, api.Service{TypeMeta: api.TypeMeta{Name: "foo"}}) handler.Wait(1) channel <- serviceUpdate3 services = []api.Service{serviceUpdate2.Services[0]} handler.ValidateServices(t, services) - serviceUpdate4 := CreateServiceUpdate(SET, api.Service{TypeMeta: api.TypeMeta{ID: "foobar"}, Port: 99}) + serviceUpdate4 := CreateServiceUpdate(SET, api.Service{TypeMeta: api.TypeMeta{Name: "foobar"}, Port: 99}) handler.Wait(1) channel <- serviceUpdate4 services = []api.Service{serviceUpdate4.Services[0]} @@ -180,8 +180,8 @@ func TestNewMultipleSourcesServicesAddedAndNotified(t *testing.T) { } handler := NewServiceHandlerMock() config.RegisterHandler(handler) - serviceUpdate1 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "foo"}, Port: 10}) - serviceUpdate2 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "bar"}, Port: 20}) + serviceUpdate1 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "foo"}, Port: 10}) + serviceUpdate2 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "bar"}, Port: 20}) handler.Wait(2) channelOne <- serviceUpdate1 channelTwo <- serviceUpdate2 @@ -197,8 +197,8 @@ func TestNewMultipleSourcesServicesMultipleHandlersAddedAndNotified(t *testing.T handler2 := NewServiceHandlerMock() config.RegisterHandler(handler) config.RegisterHandler(handler2) - serviceUpdate1 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "foo"}, Port: 10}) - serviceUpdate2 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{ID: "bar"}, Port: 20}) + serviceUpdate1 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "foo"}, Port: 10}) + serviceUpdate2 := CreateServiceUpdate(ADD, api.Service{TypeMeta: api.TypeMeta{Name: "bar"}, Port: 20}) handler.Wait(2) handler2.Wait(2) channelOne <- serviceUpdate1 @@ -217,11 +217,11 @@ func TestNewMultipleSourcesEndpointsMultipleHandlersAddedAndNotified(t *testing. config.RegisterHandler(handler) config.RegisterHandler(handler2) endpointsUpdate1 := CreateEndpointsUpdate(ADD, api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint1", "endpoint2"}, }) endpointsUpdate2 := CreateEndpointsUpdate(ADD, api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, Endpoints: []string{"endpoint3", "endpoint4"}, }) handler.Wait(2) @@ -243,11 +243,11 @@ func TestNewMultipleSourcesEndpointsMultipleHandlersAddRemoveSetAndNotified(t *t config.RegisterHandler(handler) config.RegisterHandler(handler2) endpointsUpdate1 := CreateEndpointsUpdate(ADD, api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint1", "endpoint2"}, }) endpointsUpdate2 := CreateEndpointsUpdate(ADD, api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, Endpoints: []string{"endpoint3", "endpoint4"}, }) handler.Wait(2) @@ -261,7 +261,7 @@ func TestNewMultipleSourcesEndpointsMultipleHandlersAddRemoveSetAndNotified(t *t // Add one more endpointsUpdate3 := CreateEndpointsUpdate(ADD, api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foobar"}, + TypeMeta: api.TypeMeta{Name: "foobar"}, Endpoints: []string{"endpoint5", "endpoint6"}, }) handler.Wait(1) @@ -273,7 +273,7 @@ func TestNewMultipleSourcesEndpointsMultipleHandlersAddRemoveSetAndNotified(t *t // Update the "foo" service with new endpoints endpointsUpdate1 = CreateEndpointsUpdate(ADD, api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint77"}, }) handler.Wait(1) @@ -284,7 +284,7 @@ func TestNewMultipleSourcesEndpointsMultipleHandlersAddRemoveSetAndNotified(t *t handler2.ValidateEndpoints(t, endpoints) // Remove "bar" service - endpointsUpdate2 = CreateEndpointsUpdate(REMOVE, api.Endpoints{TypeMeta: api.TypeMeta{ID: "bar"}}) + endpointsUpdate2 = CreateEndpointsUpdate(REMOVE, api.Endpoints{TypeMeta: api.TypeMeta{Name: "bar"}}) handler.Wait(1) handler2.Wait(1) channelTwo <- endpointsUpdate2 diff --git a/pkg/proxy/config/etcd.go b/pkg/proxy/config/etcd.go index 012465f686b..13d69cb5809 100644 --- a/pkg/proxy/config/etcd.go +++ b/pkg/proxy/config/etcd.go @@ -140,15 +140,15 @@ func (s ConfigSourceEtcd) decodeServices(node *etcd.Node, retServices []api.Serv // so we got a service we can handle, and now get endpoints retServices = append(retServices, svc) // get the endpoints - endpoints, err := s.GetEndpoints(svc.Namespace, svc.ID) + endpoints, err := s.GetEndpoints(svc.Namespace, svc.Name) if err != nil { if tools.IsEtcdNotFound(err) { - glog.V(4).Infof("Unable to get endpoints for %s %s : %v", svc.Namespace, svc.ID, err) + glog.V(4).Infof("Unable to get endpoints for %s %s : %v", svc.Namespace, svc.Name, err) } - glog.Errorf("Couldn't get endpoints for %s %s : %v skipping", svc.Namespace, svc.ID, err) + glog.Errorf("Couldn't get endpoints for %s %s : %v skipping", svc.Namespace, svc.Name, err) endpoints = api.Endpoints{} } else { - glog.V(3).Infof("Got service: %s %s on localport %d mapping to: %s", svc.Namespace, svc.ID, svc.Port, endpoints) + glog.V(3).Infof("Got service: %s %s on localport %d mapping to: %s", svc.Namespace, svc.Name, svc.Port, endpoints) } retEndpoints = append(retEndpoints, endpoints) } @@ -243,7 +243,7 @@ func (s ConfigSourceEtcd) ProcessChange(response *etcd.Response) { parts := strings.Split(response.Node.Key[1:], "/") if len(parts) == 4 { glog.V(4).Infof("Deleting service: %s", parts[3]) - serviceUpdate := ServiceUpdate{Op: REMOVE, Services: []api.Service{{TypeMeta: api.TypeMeta{ID: parts[3]}}}} + serviceUpdate := ServiceUpdate{Op: REMOVE, Services: []api.Service{{TypeMeta: api.TypeMeta{Name: parts[3]}}}} s.serviceChannel <- serviceUpdate return } diff --git a/pkg/proxy/proxier.go b/pkg/proxy/proxier.go index 539691a0979..3e6479085f7 100644 --- a/pkg/proxy/proxier.go +++ b/pkg/proxy/proxier.go @@ -433,35 +433,35 @@ func (proxier *Proxier) OnUpdate(services []api.Service) { glog.V(4).Infof("Received update notice: %+v", services) activeServices := util.StringSet{} for _, service := range services { - activeServices.Insert(service.ID) - info, exists := proxier.getServiceInfo(service.ID) + activeServices.Insert(service.Name) + info, exists := proxier.getServiceInfo(service.Name) serviceIP := net.ParseIP(service.PortalIP) // TODO: check health of the socket? What if ProxyLoop exited? if exists && info.isActive() && info.portalPort == service.Port && info.portalIP.Equal(serviceIP) { continue } if exists && (info.portalPort != service.Port || !info.portalIP.Equal(serviceIP)) { - glog.V(4).Infof("Something changed for service %q: stopping it", service.ID) - err := proxier.closePortal(service.ID, info) + glog.V(4).Infof("Something changed for service %q: stopping it", service.Name) + err := proxier.closePortal(service.Name, info) if err != nil { - glog.Errorf("Failed to close portal for %q: %s", service.ID, err) + glog.Errorf("Failed to close portal for %q: %s", service.Name, err) } - err = proxier.stopProxy(service.ID, info) + err = proxier.stopProxy(service.Name, info) if err != nil { - glog.Errorf("Failed to stop service %q: %s", service.ID, err) + glog.Errorf("Failed to stop service %q: %s", service.Name, err) } } - glog.V(1).Infof("Adding new service %q at %s:%d/%s (local :%d)", service.ID, serviceIP, service.Port, service.Protocol, service.ProxyPort) - info, err := proxier.addServiceOnPort(service.ID, service.Protocol, service.ProxyPort, udpIdleTimeout) + glog.V(1).Infof("Adding new service %q at %s:%d/%s (local :%d)", service.Name, serviceIP, service.Port, service.Protocol, service.ProxyPort) + info, err := proxier.addServiceOnPort(service.Name, service.Protocol, service.ProxyPort, udpIdleTimeout) if err != nil { - glog.Errorf("Failed to start proxy for %q: %+v", service.ID, err) + glog.Errorf("Failed to start proxy for %q: %+v", service.Name, err) continue } info.portalIP = serviceIP info.portalPort = service.Port - err = proxier.openPortal(service.ID, info) + err = proxier.openPortal(service.Name, info) if err != nil { - glog.Errorf("Failed to open portal for %q: %s", service.ID, err) + glog.Errorf("Failed to open portal for %q: %s", service.Name, err) } } proxier.mu.Lock() diff --git a/pkg/proxy/proxier_test.go b/pkg/proxy/proxier_test.go index 809d7c5de75..1684b50f850 100644 --- a/pkg/proxy/proxier_test.go +++ b/pkg/proxy/proxier_test.go @@ -163,7 +163,7 @@ func TestTCPProxy(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)}, }, }) @@ -181,7 +181,7 @@ func TestUDPProxy(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)}, }, }) @@ -208,7 +208,7 @@ func TestTCPProxyStop(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)}, }, }) @@ -236,7 +236,7 @@ func TestUDPProxyStop(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)}, }, }) @@ -264,7 +264,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)}, }, }) @@ -291,7 +291,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)}, }, }) @@ -318,7 +318,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)}, }, }) @@ -340,7 +340,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) { t.Fatalf(err.Error()) } p.OnUpdate([]api.Service{ - {TypeMeta: api.TypeMeta{ID: "echo"}, Port: svcInfo.proxyPort, ProxyPort: svcInfo.proxyPort, Protocol: "TCP"}, + {TypeMeta: api.TypeMeta{Name: "echo"}, Port: svcInfo.proxyPort, ProxyPort: svcInfo.proxyPort, Protocol: "TCP"}, }) testEchoTCP(t, "127.0.0.1", svcInfo.proxyPort) } @@ -349,7 +349,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)}, }, }) @@ -371,7 +371,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) { t.Fatalf(err.Error()) } p.OnUpdate([]api.Service{ - {TypeMeta: api.TypeMeta{ID: "echo"}, Port: svcInfo.proxyPort, ProxyPort: svcInfo.proxyPort, Protocol: "UDP"}, + {TypeMeta: api.TypeMeta{Name: "echo"}, Port: svcInfo.proxyPort, ProxyPort: svcInfo.proxyPort, Protocol: "UDP"}, }) testEchoUDP(t, "127.0.0.1", svcInfo.proxyPort) } @@ -380,7 +380,7 @@ func TestTCPProxyUpdatePort(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)}, }, }) @@ -406,7 +406,7 @@ func TestTCPProxyUpdatePort(t *testing.T) { t.Errorf("expected difference, got %d %d", newPort, svcInfo.proxyPort) } p.OnUpdate([]api.Service{ - {TypeMeta: api.TypeMeta{ID: "echo"}, Port: newPort, ProxyPort: newPort, Protocol: "TCP"}, + {TypeMeta: api.TypeMeta{Name: "echo"}, Port: newPort, ProxyPort: newPort, Protocol: "TCP"}, }) if err := waitForClosedPortTCP(p, svcInfo.proxyPort); err != nil { t.Fatalf(err.Error()) @@ -425,7 +425,7 @@ func TestUDPProxyUpdatePort(t *testing.T) { lb := NewLoadBalancerRR() lb.OnUpdate([]api.Endpoints{ { - TypeMeta: api.TypeMeta{ID: "echo"}, + TypeMeta: api.TypeMeta{Name: "echo"}, Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)}, }, }) @@ -451,7 +451,7 @@ func TestUDPProxyUpdatePort(t *testing.T) { t.Errorf("expected difference, got %d %d", newPort, svcInfo.proxyPort) } p.OnUpdate([]api.Service{ - {TypeMeta: api.TypeMeta{ID: "echo"}, Port: newPort, ProxyPort: newPort, Protocol: "UDP"}, + {TypeMeta: api.TypeMeta{Name: "echo"}, Port: newPort, ProxyPort: newPort, Protocol: "UDP"}, }) if err := waitForClosedPortUDP(p, svcInfo.proxyPort); err != nil { t.Fatalf(err.Error()) diff --git a/pkg/proxy/roundrobin.go b/pkg/proxy/roundrobin.go index 1a8c43b6408..a2db5616275 100644 --- a/pkg/proxy/roundrobin.go +++ b/pkg/proxy/roundrobin.go @@ -98,15 +98,15 @@ func (lb *LoadBalancerRR) OnUpdate(endpoints []api.Endpoints) { defer lb.lock.Unlock() // Update endpoints for services. for _, endpoint := range endpoints { - existingEndpoints, exists := lb.endpointsMap[endpoint.ID] + existingEndpoints, exists := lb.endpointsMap[endpoint.Name] validEndpoints := filterValidEndpoints(endpoint.Endpoints) if !exists || !reflect.DeepEqual(existingEndpoints, validEndpoints) { - glog.V(3).Infof("LoadBalancerRR: Setting endpoints for %s to %+v", endpoint.ID, endpoint.Endpoints) - lb.endpointsMap[endpoint.ID] = validEndpoints + glog.V(3).Infof("LoadBalancerRR: Setting endpoints for %s to %+v", endpoint.Name, endpoint.Endpoints) + lb.endpointsMap[endpoint.Name] = validEndpoints // Reset the round-robin index. - lb.rrIndex[endpoint.ID] = 0 + lb.rrIndex[endpoint.Name] = 0 } - registeredEndpoints[endpoint.ID] = true + registeredEndpoints[endpoint.Name] = true } // Remove endpoints missing from the update. for k, v := range lb.endpointsMap { diff --git a/pkg/proxy/roundrobin_test.go b/pkg/proxy/roundrobin_test.go index 522ebf445b3..08cf789573b 100644 --- a/pkg/proxy/roundrobin_test.go +++ b/pkg/proxy/roundrobin_test.go @@ -86,7 +86,7 @@ func TestLoadBalanceWorksWithSingleEndpoint(t *testing.T) { } endpoints := make([]api.Endpoints, 1) endpoints[0] = api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint1:40"}, } loadBalancer.OnUpdate(endpoints) @@ -104,7 +104,7 @@ func TestLoadBalanceWorksWithMultipleEndpoints(t *testing.T) { } endpoints := make([]api.Endpoints, 1) endpoints[0] = api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint:1", "endpoint:2", "endpoint:3"}, } loadBalancer.OnUpdate(endpoints) @@ -122,7 +122,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) { } endpoints := make([]api.Endpoints, 1) endpoints[0] = api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint:1", "endpoint:2", "endpoint:3"}, } loadBalancer.OnUpdate(endpoints) @@ -133,7 +133,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) { expectEndpoint(t, loadBalancer, "foo", "endpoint:2") // Then update the configuration with one fewer endpoints, make sure // we start in the beginning again - endpoints[0] = api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, + endpoints[0] = api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint:8", "endpoint:9"}, } loadBalancer.OnUpdate(endpoints) @@ -142,7 +142,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) { expectEndpoint(t, loadBalancer, "foo", "endpoint:8") expectEndpoint(t, loadBalancer, "foo", "endpoint:9") // Clear endpoints - endpoints[0] = api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}} + endpoints[0] = api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{}} loadBalancer.OnUpdate(endpoints) endpoint, err = loadBalancer.NextEndpoint("foo", nil) @@ -159,11 +159,11 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) { } endpoints := make([]api.Endpoints, 2) endpoints[0] = api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"endpoint:1", "endpoint:2", "endpoint:3"}, } endpoints[1] = api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, Endpoints: []string{"endpoint:4", "endpoint:5"}, } loadBalancer.OnUpdate(endpoints) diff --git a/pkg/registry/controller/rest.go b/pkg/registry/controller/rest.go index 98aa2cac522..d73c282c6b6 100644 --- a/pkg/registry/controller/rest.go +++ b/pkg/registry/controller/rest.go @@ -63,13 +63,13 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context")) } - if len(controller.ID) == 0 { - controller.ID = uuid.NewUUID().String() + if len(controller.Name) == 0 { + controller.Name = uuid.NewUUID().String() } // Pod Manifest ID should be assigned by the pod API controller.DesiredState.PodTemplate.DesiredState.Manifest.ID = "" if errs := validation.ValidateReplicationController(controller); len(errs) > 0 { - return nil, errors.NewInvalid("replicationController", controller.ID, errs) + return nil, errors.NewInvalid("replicationController", controller.Name, errs) } controller.CreationTimestamp = util.Now() @@ -79,7 +79,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if err != nil { return nil, err } - return rs.registry.GetController(ctx, controller.ID) + return rs.registry.GetController(ctx, controller.Name) }), nil } @@ -136,14 +136,14 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context")) } if errs := validation.ValidateReplicationController(controller); len(errs) > 0 { - return nil, errors.NewInvalid("replicationController", controller.ID, errs) + return nil, errors.NewInvalid("replicationController", controller.Name, errs) } return apiserver.MakeAsync(func() (runtime.Object, error) { err := rs.registry.UpdateController(ctx, controller) if err != nil { return nil, err } - return rs.registry.GetController(ctx, controller.ID) + return rs.registry.GetController(ctx, controller.Name) }), nil } diff --git a/pkg/registry/controller/rest_test.go b/pkg/registry/controller/rest_test.go index 32d6d9b31f1..02d84e15be4 100644 --- a/pkg/registry/controller/rest_test.go +++ b/pkg/registry/controller/rest_test.go @@ -75,12 +75,12 @@ func TestListControllerList(t *testing.T) { Items: []api.ReplicationController{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, }, { TypeMeta: api.TypeMeta{ - ID: "bar", + Name: "bar", }, }, }, @@ -99,10 +99,10 @@ func TestListControllerList(t *testing.T) { if len(controllers.Items) != 2 { t.Errorf("Unexpected controller list: %#v", controllers) } - if controllers.Items[0].ID != "foo" { + if controllers.Items[0].Name != "foo" { t.Errorf("Unexpected controller: %#v", controllers.Items[0]) } - if controllers.Items[1].ID != "bar" { + if controllers.Items[1].Name != "bar" { t.Errorf("Unexpected controller: %#v", controllers.Items[1]) } } @@ -114,7 +114,7 @@ func TestControllerDecode(t *testing.T) { } controller := &api.ReplicationController{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, } body, err := latest.Codec.Encode(controller) @@ -135,7 +135,7 @@ func TestControllerDecode(t *testing.T) { func TestControllerParsing(t *testing.T) { expectedController := api.ReplicationController{ TypeMeta: api.TypeMeta{ - ID: "nginxController", + Name: "nginxController", }, DesiredState: api.ReplicationControllerState{ Replicas: 2, @@ -225,7 +225,7 @@ func TestCreateController(t *testing.T) { Pods: &api.PodList{ Items: []api.Pod{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Labels: map[string]string{"a": "b"}, }, }, @@ -237,7 +237,7 @@ func TestCreateController(t *testing.T) { pollPeriod: time.Millisecond * 1, } controller := &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "test"}, + TypeMeta: api.TypeMeta{Name: "test"}, DesiredState: api.ReplicationControllerState{ Replicas: 2, ReplicaSelector: map[string]string{"a": "b"}, @@ -270,13 +270,13 @@ func TestControllerStorageValidatesCreate(t *testing.T) { } failureCases := map[string]api.ReplicationController{ "empty ID": { - TypeMeta: api.TypeMeta{ID: ""}, + TypeMeta: api.TypeMeta{Name: ""}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: map[string]string{"bar": "baz"}, }, }, "empty selector": { - TypeMeta: api.TypeMeta{ID: "abc"}, + TypeMeta: api.TypeMeta{Name: "abc"}, DesiredState: api.ReplicationControllerState{}, }, } @@ -301,13 +301,13 @@ func TestControllerStorageValidatesUpdate(t *testing.T) { } failureCases := map[string]api.ReplicationController{ "empty ID": { - TypeMeta: api.TypeMeta{ID: ""}, + TypeMeta: api.TypeMeta{Name: ""}, DesiredState: api.ReplicationControllerState{ ReplicaSelector: map[string]string{"bar": "baz"}, }, }, "empty selector": { - TypeMeta: api.TypeMeta{ID: "abc"}, + TypeMeta: api.TypeMeta{Name: "abc"}, DesiredState: api.ReplicationControllerState{}, }, } @@ -338,8 +338,8 @@ func TestFillCurrentState(t *testing.T) { fakeLister := fakePodLister{ l: api.PodList{ Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, - {TypeMeta: api.TypeMeta{ID: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, }, }, } @@ -368,7 +368,7 @@ func TestFillCurrentState(t *testing.T) { func TestCreateControllerWithConflictingNamespace(t *testing.T) { storage := REST{} controller := &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"}, + TypeMeta: api.TypeMeta{Name: "test", Namespace: "not-default"}, } ctx := api.NewDefaultContext() @@ -386,7 +386,7 @@ func TestCreateControllerWithConflictingNamespace(t *testing.T) { func TestUpdateControllerWithConflictingNamespace(t *testing.T) { storage := REST{} controller := &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"}, + TypeMeta: api.TypeMeta{Name: "test", Namespace: "not-default"}, } ctx := api.NewDefaultContext() diff --git a/pkg/registry/endpoint/rest.go b/pkg/registry/endpoint/rest.go index 51c945bcf8e..7a2c15e8e78 100644 --- a/pkg/registry/endpoint/rest.go +++ b/pkg/registry/endpoint/rest.go @@ -65,7 +65,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if !ok { return nil, fmt.Errorf("not an endpoints: %#v", obj) } - if len(endpoints.ID) == 0 { + if len(endpoints.Name) == 0 { return nil, fmt.Errorf("id is required: %#v", obj) } endpoints.CreationTimestamp = util.Now() @@ -74,7 +74,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if err != nil { return nil, err } - return rs.registry.GetEndpoints(ctx, endpoints.ID) + return rs.registry.GetEndpoints(ctx, endpoints.Name) }), nil } @@ -89,7 +89,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if err != nil { return nil, err } - return rs.registry.GetEndpoints(ctx, endpoints.ID) + return rs.registry.GetEndpoints(ctx, endpoints.Name) }), nil } diff --git a/pkg/registry/endpoint/rest_test.go b/pkg/registry/endpoint/rest_test.go index 282cd80622e..aaa0284bd17 100644 --- a/pkg/registry/endpoint/rest_test.go +++ b/pkg/registry/endpoint/rest_test.go @@ -29,7 +29,7 @@ import ( func TestGetEndpoints(t *testing.T) { registry := ®istrytest.ServiceRegistry{ Endpoints: api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"127.0.0.1:9000"}, }, } @@ -59,7 +59,7 @@ func TestGetEndpointsMissingService(t *testing.T) { // returns empty endpoints registry.Err = nil registry.Service = &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, } obj, err := storage.Get(ctx, "foo") if err != nil { @@ -76,8 +76,8 @@ func TestEndpointsRegistryList(t *testing.T) { registry.EndpointsList = api.EndpointsList{ TypeMeta: api.TypeMeta{ResourceVersion: "1"}, Items: []api.Endpoints{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, - {TypeMeta: api.TypeMeta{ID: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, }, } ctx := api.NewContext() @@ -86,10 +86,10 @@ func TestEndpointsRegistryList(t *testing.T) { if len(sl.Items) != 2 { t.Fatalf("Expected 2 endpoints, but got %v", len(sl.Items)) } - if e, a := "foo", sl.Items[0].ID; e != a { + if e, a := "foo", sl.Items[0].Name; e != a { t.Errorf("Expected %v, but got %v", e, a) } - if e, a := "bar", sl.Items[1].ID; e != a { + if e, a := "bar", sl.Items[1].Name; e != a { t.Errorf("Expected %v, but got %v", e, a) } if sl.ResourceVersion != "1" { diff --git a/pkg/registry/etcd/etcd.go b/pkg/registry/etcd/etcd.go index 93d31063b9f..9f2ee557f90 100644 --- a/pkg/registry/etcd/etcd.go +++ b/pkg/registry/etcd/etcd.go @@ -188,12 +188,12 @@ func (r *Registry) CreatePod(ctx api.Context, pod *api.Pod) error { // DesiredState.Host == "" is a signal to the scheduler that this pod needs scheduling. pod.DesiredState.Status = api.PodRunning pod.DesiredState.Host = "" - key, err := makePodKey(ctx, pod.ID) + key, err := makePodKey(ctx, pod.Name) if err != nil { return err } err = r.CreateObj(key, pod, 0) - return etcderr.InterpretCreateError(err, "pod", pod.ID) + return etcderr.InterpretCreateError(err, "pod", pod.Name) } // ApplyBinding implements binding's registry @@ -214,7 +214,7 @@ func (r *Registry) setPodHostTo(ctx api.Context, podID, oldMachine, machine stri return nil, fmt.Errorf("unexpected object: %#v", obj) } if pod.DesiredState.Host != oldMachine { - return nil, fmt.Errorf("pod %v is already assigned to host %v", pod.ID, pod.DesiredState.Host) + return nil, fmt.Errorf("pod %v is already assigned to host %v", pod.Name, pod.DesiredState.Host) } pod.DesiredState.Host = machine finalPod = pod @@ -255,7 +255,7 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro func (r *Registry) UpdatePod(ctx api.Context, pod *api.Pod) error { var podOut api.Pod - podKey, err := makePodKey(ctx, pod.ID) + podKey, err := makePodKey(ctx, pod.Name) if err != nil { return err } @@ -269,7 +269,7 @@ func (r *Registry) UpdatePod(ctx api.Context, pod *api.Pod) error { // If it's already been scheduled, limit the types of updates we'll accept. errs := validation.ValidatePodUpdate(pod, &podOut) if len(errs) != 0 { - return errors.NewInvalid("Pod", pod.ID, errs) + return errors.NewInvalid("Pod", pod.Name, errs) } } // There's no race with the scheduler, because either this write will fail because the host @@ -286,14 +286,14 @@ func (r *Registry) UpdatePod(ctx api.Context, pod *api.Pod) error { return r.AtomicUpdate(containerKey, &api.ContainerManifestList{}, func(in runtime.Object) (runtime.Object, error) { manifests := in.(*api.ContainerManifestList) for ix := range manifests.Items { - if manifests.Items[ix].ID == pod.ID { + if manifests.Items[ix].ID == pod.Name { manifests.Items[ix] = pod.DesiredState.Manifest return manifests, nil } } // This really shouldn't happen - glog.Warningf("Couldn't find: %s in %#v", pod.ID, manifests) - return manifests, fmt.Errorf("Failed to update pod, couldn't find %s in %#v", pod.ID, manifests) + glog.Warningf("Couldn't find: %s in %#v", pod.Name, manifests) + return manifests, fmt.Errorf("Failed to update pod, couldn't find %s in %#v", pod.Name, manifests) }) } @@ -326,7 +326,7 @@ func (r *Registry) DeletePod(ctx api.Context, podID string) error { newPods := make([]api.BoundPod, 0, len(pods.Items)) found := false for _, pod := range pods.Items { - if pod.ID != podID { + if pod.Name != podID { newPods = append(newPods, pod) } else { found = true @@ -387,22 +387,22 @@ func (r *Registry) GetController(ctx api.Context, controllerID string) (*api.Rep // CreateController creates a new ReplicationController. func (r *Registry) CreateController(ctx api.Context, controller *api.ReplicationController) error { - key, err := makeControllerKey(ctx, controller.ID) + key, err := makeControllerKey(ctx, controller.Name) if err != nil { return err } err = r.CreateObj(key, controller, 0) - return etcderr.InterpretCreateError(err, "replicationController", controller.ID) + return etcderr.InterpretCreateError(err, "replicationController", controller.Name) } // UpdateController replaces an existing ReplicationController. func (r *Registry) UpdateController(ctx api.Context, controller *api.ReplicationController) error { - key, err := makeControllerKey(ctx, controller.ID) + key, err := makeControllerKey(ctx, controller.Name) if err != nil { return err } err = r.SetObj(key, controller) - return etcderr.InterpretUpdateError(err, "replicationController", controller.ID) + return etcderr.InterpretUpdateError(err, "replicationController", controller.Name) } // DeleteController deletes a ReplicationController specified by its ID. @@ -434,12 +434,12 @@ func (r *Registry) ListServices(ctx api.Context) (*api.ServiceList, error) { // CreateService creates a new Service. func (r *Registry) CreateService(ctx api.Context, svc *api.Service) error { - key, err := makeServiceKey(ctx, svc.ID) + key, err := makeServiceKey(ctx, svc.Name) if err != nil { return err } err = r.CreateObj(key, svc, 0) - return etcderr.InterpretCreateError(err, "service", svc.ID) + return etcderr.InterpretCreateError(err, "service", svc.Name) } // GetService obtains a Service specified by its name. @@ -505,12 +505,12 @@ func (r *Registry) DeleteService(ctx api.Context, name string) error { // UpdateService replaces an existing Service. func (r *Registry) UpdateService(ctx api.Context, svc *api.Service) error { - key, err := makeServiceKey(ctx, svc.ID) + key, err := makeServiceKey(ctx, svc.Name) if err != nil { return err } err = r.SetObj(key, svc) - return etcderr.InterpretUpdateError(err, "service", svc.ID) + return etcderr.InterpretUpdateError(err, "service", svc.Name) } // WatchServices begins watching for new, changed, or deleted service configurations. @@ -544,8 +544,8 @@ func (r *Registry) ListEndpoints(ctx api.Context) (*api.EndpointsList, error) { } // UpdateEndpoints update Endpoints of a Service. -func (r *Registry) UpdateEndpoints(ctx api.Context, e *api.Endpoints) error { - key, err := makeServiceEndpointsKey(ctx, e.ID) +func (r *Registry) UpdateEndpoints(ctx api.Context, endpoints *api.Endpoints) error { + key, err := makeServiceEndpointsKey(ctx, endpoints.Name) if err != nil { return err } @@ -553,9 +553,9 @@ func (r *Registry) UpdateEndpoints(ctx api.Context, e *api.Endpoints) error { err = r.AtomicUpdate(key, &api.Endpoints{}, func(input runtime.Object) (runtime.Object, error) { // TODO: racy - label query is returning different results for two simultaneous updaters - return e, nil + return endpoints, nil }) - return etcderr.InterpretUpdateError(err, "endpoints", e.ID) + return etcderr.InterpretUpdateError(err, "endpoints", endpoints.Name) } // WatchEndpoints begins watching for new, changed, or deleted endpoint configurations. @@ -592,8 +592,8 @@ func (r *Registry) ListMinions(ctx api.Context) (*api.MinionList, error) { func (r *Registry) CreateMinion(ctx api.Context, minion *api.Minion) error { // TODO: Add some validations. - err := r.CreateObj(makeMinionKey(minion.ID), minion, 0) - return etcderr.InterpretCreateError(err, "minion", minion.ID) + err := r.CreateObj(makeMinionKey(minion.Name), minion, 0) + return etcderr.InterpretCreateError(err, "minion", minion.Name) } func (r *Registry) GetMinion(ctx api.Context, minionID string) (*api.Minion, error) { @@ -601,7 +601,7 @@ func (r *Registry) GetMinion(ctx api.Context, minionID string) (*api.Minion, err key := makeMinionKey(minionID) err := r.ExtractObj(key, &minion, false) if err != nil { - return nil, etcderr.InterpretGetError(err, "minion", minion.ID) + return nil, etcderr.InterpretGetError(err, "minion", minion.Name) } return &minion, nil } diff --git a/pkg/registry/etcd/etcd_test.go b/pkg/registry/etcd/etcd_test.go index 4cd2b5e41e9..e1a97f27611 100644 --- a/pkg/registry/etcd/etcd_test.go +++ b/pkg/registry/etcd/etcd_test.go @@ -87,8 +87,8 @@ func TestEtcdGetPodDifferentNamespace(t *testing.T) { key1, _ := makePodKey(ctx1, "foo") key2, _ := makePodKey(ctx2, "foo") - fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{Namespace: "default", ID: "foo"}}), 0) - fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{Namespace: "other", ID: "foo"}}), 0) + fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{Namespace: "default", Name: "foo"}}), 0) + fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{Namespace: "other", Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) @@ -96,7 +96,7 @@ func TestEtcdGetPodDifferentNamespace(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if pod1.ID != "foo" { + if pod1.Name != "foo" { t.Errorf("Unexpected pod: %#v", pod1) } if pod1.Namespace != "default" { @@ -107,7 +107,7 @@ func TestEtcdGetPodDifferentNamespace(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if pod2.ID != "foo" { + if pod2.Name != "foo" { t.Errorf("Unexpected pod: %#v", pod2) } if pod2.Namespace != "other" { @@ -120,14 +120,14 @@ func TestEtcdGetPod(t *testing.T) { ctx := api.NewDefaultContext() fakeClient := tools.NewFakeEtcdClient(t) key, _ := makePodKey(ctx, "foo") - fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) pod, err := registry.GetPod(ctx, "foo") if err != nil { t.Errorf("unexpected error: %v", err) } - if pod.ID != "foo" { + if pod.Name != "foo" { t.Errorf("Unexpected pod: %#v", pod) } } @@ -164,7 +164,7 @@ func TestEtcdCreatePod(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(ctx, &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ @@ -196,7 +196,7 @@ func TestEtcdCreatePod(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if pod.ID != "foo" { + if pod.Name != "foo" { t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value) } var boundPods api.BoundPods @@ -206,7 +206,7 @@ func TestEtcdCreatePod(t *testing.T) { } err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &boundPods) - if len(boundPods.Items) != 1 || boundPods.Items[0].ID != "foo" { + if len(boundPods.Items) != 1 || boundPods.Items[0].Name != "foo" { t.Errorf("Unexpected boundPod list: %#v", boundPods) } } @@ -217,7 +217,7 @@ func TestEtcdCreatePodFailsWithoutNamespace(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(api.NewContext(), &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ @@ -242,7 +242,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) { fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ - Value: runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}), }, }, E: nil, @@ -250,7 +250,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(ctx, &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, }) if !errors.IsAlreadyExists(err) { @@ -278,7 +278,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(ctx, &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, }) if err != nil { @@ -320,7 +320,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(ctx, &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ @@ -353,7 +353,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if pod.ID != "foo" { + if pod.Name != "foo" { t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value) } var boundPods api.BoundPods @@ -363,7 +363,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { } err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &boundPods) - if len(boundPods.Items) != 1 || boundPods.Items[0].ID != "foo" { + if len(boundPods.Items) != 1 || boundPods.Items[0].Name != "foo" { t.Errorf("Unexpected boundPod list: %#v", boundPods) } } @@ -381,13 +381,13 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { } fakeClient.Set("/registry/nodes/machine/boundpods", runtime.EncodeOrDie(latest.Codec, &api.BoundPods{ Items: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, }, }), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreatePod(ctx, &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ @@ -420,7 +420,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if pod.ID != "foo" { + if pod.Name != "foo" { t.Errorf("Unexpected pod: %#v %s", pod, resp.Node.Value) } var boundPods api.BoundPods @@ -430,7 +430,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { } err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &boundPods) - if len(boundPods.Items) != 2 || boundPods.Items[1].ID != "foo" { + if len(boundPods.Items) != 2 || boundPods.Items[1].Name != "foo" { t.Errorf("Unexpected boundPod list: %#v", boundPods) } } @@ -448,7 +448,7 @@ func TestEtcdUpdatePodNotFound(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) podIn := api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, Labels: map[string]string{ "foo": "bar", }, @@ -466,12 +466,12 @@ func TestEtcdUpdatePodNotScheduled(t *testing.T) { key, _ := makePodKey(ctx, "foo") fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }), 1) registry := NewTestEtcdRegistry(fakeClient) podIn := api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, Labels: map[string]string{ "foo": "bar", }, @@ -498,7 +498,7 @@ func TestEtcdUpdatePodScheduled(t *testing.T) { key, _ := makePodKey(ctx, "foo") fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{ Host: "machine", Manifest: api.ContainerManifest{ @@ -536,7 +536,7 @@ func TestEtcdUpdatePodScheduled(t *testing.T) { registry := NewTestEtcdRegistry(fakeClient) podIn := api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ ID: "foo", @@ -584,12 +584,12 @@ func TestEtcdDeletePod(t *testing.T) { key, _ := makePodKey(ctx, "foo") fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine"}, }), 0) fakeClient.Set("/registry/nodes/machine/boundpods", runtime.EncodeOrDie(latest.Codec, &api.BoundPods{ Items: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, }, }), 0) registry := NewTestEtcdRegistry(fakeClient) @@ -620,13 +620,13 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { fakeClient.TestIndex = true key, _ := makePodKey(ctx, "foo") fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine"}, }), 0) fakeClient.Set("/registry/nodes/machine/boundpods", runtime.EncodeOrDie(latest.Codec, &api.BoundPods{ Items: []api.BoundPod{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, - {TypeMeta: api.TypeMeta{ID: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, }, }), 0) registry := NewTestEtcdRegistry(fakeClient) @@ -650,7 +650,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { if len(boundPods.Items) != 1 { t.Fatalf("Unexpected boundPod set: %#v, expected empty", boundPods) } - if boundPods.Items[0].ID != "bar" { + if boundPods.Items[0].Name != "bar" { t.Errorf("Deleted wrong boundPod: %#v", boundPods) } } @@ -706,13 +706,13 @@ func TestEtcdListPods(t *testing.T) { Nodes: []*etcd.Node{ { Value: runtime.EncodeOrDie(latest.Codec, &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine"}, }), }, { Value: runtime.EncodeOrDie(latest.Codec, &api.Pod{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, DesiredState: api.PodState{Host: "machine"}, }), }, @@ -727,7 +727,7 @@ func TestEtcdListPods(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if len(pods.Items) != 2 || pods.Items[0].ID != "foo" || pods.Items[1].ID != "bar" { + if len(pods.Items) != 2 || pods.Items[0].Name != "foo" || pods.Items[1].Name != "bar" { t.Errorf("Unexpected pod list: %#v", pods) } if pods.Items[0].CurrentState.Host != "machine" || @@ -783,10 +783,10 @@ func TestEtcdListControllers(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{ID: "foo"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Name: "foo"}}), }, { - Value: runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{ID: "bar"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Name: "bar"}}), }, }, }, @@ -799,7 +799,7 @@ func TestEtcdListControllers(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if len(controllers.Items) != 2 || controllers.Items[0].ID != "foo" || controllers.Items[1].ID != "bar" { + if len(controllers.Items) != 2 || controllers.Items[0].Name != "foo" || controllers.Items[1].Name != "bar" { t.Errorf("Unexpected controller list: %#v", controllers) } } @@ -814,8 +814,8 @@ func TestEtcdGetControllerDifferentNamespace(t *testing.T) { key1, _ := makeControllerKey(ctx1, "foo") key2, _ := makeControllerKey(ctx2, "foo") - fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "default", ID: "foo"}}), 0) - fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "other", ID: "foo"}}), 0) + fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "default", Name: "foo"}}), 0) + fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "other", Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) @@ -823,7 +823,7 @@ func TestEtcdGetControllerDifferentNamespace(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if ctrl1.ID != "foo" { + if ctrl1.Name != "foo" { t.Errorf("Unexpected controller: %#v", ctrl1) } if ctrl1.Namespace != "default" { @@ -834,7 +834,7 @@ func TestEtcdGetControllerDifferentNamespace(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if ctrl2.ID != "foo" { + if ctrl2.Name != "foo" { t.Errorf("Unexpected controller: %#v", ctrl2) } if ctrl2.Namespace != "other" { @@ -847,14 +847,14 @@ func TestEtcdGetController(t *testing.T) { ctx := api.NewDefaultContext() fakeClient := tools.NewFakeEtcdClient(t) key, _ := makeControllerKey(ctx, "foo") - fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) ctrl, err := registry.GetController(ctx, "foo") if err != nil { t.Errorf("unexpected error: %v", err) } - if ctrl.ID != "foo" { + if ctrl.Name != "foo" { t.Errorf("Unexpected controller: %#v", ctrl) } } @@ -904,7 +904,7 @@ func TestEtcdCreateController(t *testing.T) { key, _ := makeControllerKey(ctx, "foo") err := registry.CreateController(ctx, &api.ReplicationController{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, }) if err != nil { @@ -920,7 +920,7 @@ func TestEtcdCreateController(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if ctrl.ID != "foo" { + if ctrl.Name != "foo" { t.Errorf("Unexpected pod: %#v %s", ctrl, resp.Node.Value) } } @@ -929,12 +929,12 @@ func TestEtcdCreateControllerAlreadyExisting(t *testing.T) { ctx := api.NewDefaultContext() fakeClient := tools.NewFakeEtcdClient(t) key, _ := makeControllerKey(ctx, "foo") - fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreateController(ctx, &api.ReplicationController{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, }) if !errors.IsAlreadyExists(err) { @@ -947,10 +947,10 @@ func TestEtcdUpdateController(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true key, _ := makeControllerKey(ctx, "foo") - resp, _ := fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + resp, _ := fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.ReplicationController{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.UpdateController(ctx, &api.ReplicationController{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)}, DesiredState: api.ReplicationControllerState{ Replicas: 2, }, @@ -974,10 +974,10 @@ func TestEtcdListServices(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{ID: "foo"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Name: "foo"}}), }, { - Value: runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{ID: "bar"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Name: "bar"}}), }, }, }, @@ -990,7 +990,7 @@ func TestEtcdListServices(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if len(services.Items) != 2 || services.Items[0].ID != "foo" || services.Items[1].ID != "bar" { + if len(services.Items) != 2 || services.Items[0].Name != "foo" || services.Items[1].Name != "bar" { t.Errorf("Unexpected service list: %#v", services) } } @@ -1000,7 +1000,7 @@ func TestEtcdCreateService(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreateService(ctx, &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }) if err != nil { t.Errorf("unexpected error: %v", err) @@ -1018,7 +1018,7 @@ func TestEtcdCreateService(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if service.ID != "foo" { + if service.Name != "foo" { t.Errorf("Unexpected service: %#v %s", service, resp.Node.Value) } } @@ -1027,10 +1027,10 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) { ctx := api.NewDefaultContext() fakeClient := tools.NewFakeEtcdClient(t) key, _ := makeServiceKey(ctx, "foo") - fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreateService(ctx, &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }) if !errors.IsAlreadyExists(err) { t.Errorf("expected already exists err, got %#v", err) @@ -1047,8 +1047,8 @@ func TestEtcdGetServiceDifferentNamespace(t *testing.T) { key1, _ := makeServiceKey(ctx1, "foo") key2, _ := makeServiceKey(ctx2, "foo") - fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Namespace: "default", ID: "foo"}}), 0) - fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Namespace: "other", ID: "foo"}}), 0) + fakeClient.Set(key1, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Namespace: "default", Name: "foo"}}), 0) + fakeClient.Set(key2, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Namespace: "other", Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) @@ -1056,7 +1056,7 @@ func TestEtcdGetServiceDifferentNamespace(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if service1.ID != "foo" { + if service1.Name != "foo" { t.Errorf("Unexpected service: %#v", service1) } if service1.Namespace != "default" { @@ -1067,7 +1067,7 @@ func TestEtcdGetServiceDifferentNamespace(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } - if service2.ID != "foo" { + if service2.Name != "foo" { t.Errorf("Unexpected service: %#v", service2) } if service2.Namespace != "other" { @@ -1080,14 +1080,14 @@ func TestEtcdGetService(t *testing.T) { ctx := api.NewDefaultContext() fakeClient := tools.NewFakeEtcdClient(t) key, _ := makeServiceKey(ctx, "foo") - fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) service, err := registry.GetService(ctx, "foo") if err != nil { t.Errorf("unexpected error: %v", err) } - if service.ID != "foo" { + if service.Name != "foo" { t.Errorf("Unexpected service: %#v", service) } } @@ -1136,10 +1136,10 @@ func TestEtcdUpdateService(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true key, _ := makeServiceKey(ctx, "foo") - resp, _ := fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + resp, _ := fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) testService := api.Service{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: strconv.FormatUint(resp.Node.ModifiedIndex, 10)}, Labels: map[string]string{ "baz": "bar", }, @@ -1174,10 +1174,10 @@ func TestEtcdListEndpoints(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{"127.0.0.1:8345"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"127.0.0.1:8345"}}), }, { - Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "bar"}}), + Value: runtime.EncodeOrDie(latest.Codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "bar"}}), }, }, }, @@ -1190,7 +1190,7 @@ func TestEtcdListEndpoints(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if len(services.Items) != 2 || services.Items[0].ID != "foo" || services.Items[1].ID != "bar" { + if len(services.Items) != 2 || services.Items[0].Name != "foo" || services.Items[1].Name != "bar" { t.Errorf("Unexpected endpoints list: %#v", services) } } @@ -1200,7 +1200,7 @@ func TestEtcdGetEndpoints(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) registry := NewTestEtcdRegistry(fakeClient) endpoints := &api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"127.0.0.1:34855"}, } @@ -1223,7 +1223,7 @@ func TestEtcdUpdateEndpoints(t *testing.T) { fakeClient.TestIndex = true registry := NewTestEtcdRegistry(fakeClient) endpoints := api.Endpoints{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"baz", "bar"}, } @@ -1392,12 +1392,12 @@ func TestEtcdListMinions(t *testing.T) { Nodes: []*etcd.Node{ { Value: runtime.EncodeOrDie(latest.Codec, &api.Minion{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }), }, { Value: runtime.EncodeOrDie(latest.Codec, &api.Minion{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, }), }, }, @@ -1411,7 +1411,7 @@ func TestEtcdListMinions(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if len(minions.Items) != 2 || minions.Items[0].ID != "foo" || minions.Items[1].ID != "bar" { + if len(minions.Items) != 2 || minions.Items[0].Name != "foo" || minions.Items[1].Name != "bar" { t.Errorf("Unexpected minion list: %#v", minions) } } @@ -1421,7 +1421,7 @@ func TestEtcdCreateMinion(t *testing.T) { fakeClient := tools.NewFakeEtcdClient(t) registry := NewTestEtcdRegistry(fakeClient) err := registry.CreateMinion(ctx, &api.Minion{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }) if err != nil { t.Errorf("unexpected error: %v", err) @@ -1438,7 +1438,7 @@ func TestEtcdCreateMinion(t *testing.T) { t.Errorf("unexpected error: %v", err) } - if minion.ID != "foo" { + if minion.Name != "foo" { t.Errorf("Unexpected minion: %#v %s", minion, resp.Node.Value) } } @@ -1446,14 +1446,14 @@ 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{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + fakeClient.Set("/registry/minions/foo", runtime.EncodeOrDie(latest.Codec, &api.Minion{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) registry := NewTestEtcdRegistry(fakeClient) minion, err := registry.GetMinion(ctx, "foo") if err != nil { t.Errorf("unexpected error: %v", err) } - if minion.ID != "foo" { + if minion.Name != "foo" { t.Errorf("Unexpected minion: %#v", minion) } } diff --git a/pkg/registry/event/registry_test.go b/pkg/registry/event/registry_test.go index db08b7e0bcc..cc163f41640 100644 --- a/pkg/registry/event/registry_test.go +++ b/pkg/registry/event/registry_test.go @@ -42,11 +42,11 @@ func NewTestEventEtcdRegistry(t *testing.T) (*tools.FakeEtcdClient, generic.Regi func TestEventCreate(t *testing.T) { eventA := &api.Event{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Reason: "forTesting", } eventB := &api.Event{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Reason: "forTesting", } diff --git a/pkg/registry/event/rest.go b/pkg/registry/event/rest.go index 83031f6cdb1..b5da79baa44 100644 --- a/pkg/registry/event/rest.go +++ b/pkg/registry/event/rest.go @@ -49,11 +49,11 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje event.CreationTimestamp = util.Now() return apiserver.MakeAsync(func() (runtime.Object, error) { - err := rs.registry.Create(ctx, event.ID, event) + err := rs.registry.Create(ctx, event.Name, event) if err != nil { return nil, err } - return rs.registry.Get(ctx, event.ID) + return rs.registry.Get(ctx, event.Name) }), nil } diff --git a/pkg/registry/event/rest_test.go b/pkg/registry/event/rest_test.go index 820562485ca..e41519630e9 100644 --- a/pkg/registry/event/rest_test.go +++ b/pkg/registry/event/rest_test.go @@ -40,7 +40,7 @@ func NewTestREST() (testRegistry, *REST) { func TestRESTCreate(t *testing.T) { _, rest := NewTestREST() eventA := &api.Event{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Reason: "forTesting", } c, err := rest.Create(api.NewContext(), eventA) @@ -55,7 +55,7 @@ func TestRESTCreate(t *testing.T) { func TestRESTDelete(t *testing.T) { _, rest := NewTestREST() eventA := &api.Event{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Reason: "forTesting", } c, err := rest.Create(api.NewContext(), eventA) @@ -63,7 +63,7 @@ func TestRESTDelete(t *testing.T) { t.Fatalf("Unexpected error %v", err) } <-c - c, err = rest.Delete(api.NewContext(), eventA.ID) + c, err = rest.Delete(api.NewContext(), eventA.Name) if err != nil { t.Fatalf("Unexpected error %v", err) } @@ -75,7 +75,7 @@ func TestRESTDelete(t *testing.T) { func TestRESTGet(t *testing.T) { _, rest := NewTestREST() eventA := &api.Event{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Reason: "forTesting", } c, err := rest.Create(api.NewContext(), eventA) @@ -83,7 +83,7 @@ func TestRESTGet(t *testing.T) { t.Fatalf("Unexpected error %v", err) } <-c - got, err := rest.Get(api.NewContext(), eventA.ID) + got, err := rest.Get(api.NewContext(), eventA.Name) if err != nil { t.Fatalf("Unexpected error %v", err) } @@ -131,7 +131,7 @@ func TestRESTgetAttrs(t *testing.T) { func TestRESTUpdate(t *testing.T) { _, rest := NewTestREST() eventA := &api.Event{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Reason: "forTesting", } c, err := rest.Create(api.NewContext(), eventA) diff --git a/pkg/registry/generic/etcd/etcd_test.go b/pkg/registry/generic/etcd/etcd_test.go index 0772bd96fc6..172317d75d0 100644 --- a/pkg/registry/generic/etcd/etcd_test.go +++ b/pkg/registry/generic/etcd/etcd_test.go @@ -60,7 +60,7 @@ func (sm SetMatcher) Matches(obj runtime.Object) (bool, error) { if !ok { return false, fmt.Errorf("wrong object") } - return sm.Has(pod.ID), nil + return sm.Has(pod.Name), nil } // EverythingMatcher matches everything @@ -72,11 +72,11 @@ func (EverythingMatcher) Matches(obj runtime.Object) (bool, error) { func TestEtcdList(t *testing.T) { podA := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine"}, } podB := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, DesiredState: api.PodState{Host: "machine"}, } @@ -154,11 +154,11 @@ func TestEtcdList(t *testing.T) { func TestEtcdCreate(t *testing.T) { podA := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine"}, } podB := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine2"}, } @@ -217,11 +217,11 @@ func TestEtcdCreate(t *testing.T) { func TestEtcdUpdate(t *testing.T) { podA := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: api.PodState{Host: "machine"}, } podB := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, DesiredState: api.PodState{Host: "machine2"}, } @@ -292,7 +292,7 @@ func TestEtcdUpdate(t *testing.T) { func TestEtcdGet(t *testing.T) { podA := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, DesiredState: api.PodState{Host: "machine"}, } @@ -348,7 +348,7 @@ func TestEtcdGet(t *testing.T) { func TestEtcdDelete(t *testing.T) { podA := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, DesiredState: api.PodState{Host: "machine"}, } @@ -404,7 +404,7 @@ func TestEtcdDelete(t *testing.T) { func TestEtcdWatch(t *testing.T) { podA := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}, + TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}, DesiredState: api.PodState{Host: "machine"}, } respWithPodA := &etcd.Response{ diff --git a/pkg/registry/minion/healthy_registry.go b/pkg/registry/minion/healthy_registry.go index c04f115dc1c..39f339fe82e 100644 --- a/pkg/registry/minion/healthy_registry.go +++ b/pkg/registry/minion/healthy_registry.go @@ -73,7 +73,7 @@ func (r *HealthyRegistry) ListMinions(ctx api.Context) (currentMinions *api.Mini return result, err } for _, minion := range list.Items { - status, err := health.DoHTTPCheck(r.makeMinionURL(minion.ID), r.client) + status, err := health.DoHTTPCheck(r.makeMinionURL(minion.Name), r.client) if err != nil { glog.V(1).Infof("%#v failed health check with error: %s", minion, err) continue diff --git a/pkg/registry/minion/healthy_registry_test.go b/pkg/registry/minion/healthy_registry_test.go index d71f02f5314..838ea0d5019 100644 --- a/pkg/registry/minion/healthy_registry_test.go +++ b/pkg/registry/minion/healthy_registry_test.go @@ -55,7 +55,7 @@ func TestBasicDelegation(t *testing.T) { t.Errorf("Expected %v, Got %v", mockMinionRegistry.Minions, list) } err = healthy.CreateMinion(ctx, &api.Minion{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }) if err != nil { t.Errorf("unexpected error: %v", err) diff --git a/pkg/registry/minion/rest.go b/pkg/registry/minion/rest.go index 68f63365af9..01b7f17783b 100644 --- a/pkg/registry/minion/rest.go +++ b/pkg/registry/minion/rest.go @@ -50,7 +50,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if !ok { return nil, fmt.Errorf("not a minion: %#v", obj) } - if minion.ID == "" { + if minion.Name == "" { return nil, fmt.Errorf("ID should not be empty: %#v", minion) } @@ -61,7 +61,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if err != nil { return nil, err } - minion, err := rs.registry.GetMinion(ctx, minion.ID) + minion, err := rs.registry.GetMinion(ctx, minion.Name) if minion == nil { return nil, ErrDoesNotExist } @@ -106,7 +106,7 @@ func (rs *REST) Update(ctx api.Context, minion runtime.Object) (<-chan runtime.O } func (rs *REST) toApiMinion(name string) *api.Minion { - return &api.Minion{TypeMeta: api.TypeMeta{ID: name}} + return &api.Minion{TypeMeta: api.TypeMeta{Name: name}} } // ResourceLocation returns a URL to which one can send traffic for the specified minion. @@ -117,7 +117,7 @@ func (rs *REST) ResourceLocation(ctx api.Context, id string) (string, error) { } host := minion.HostIP if host == "" { - host = minion.ID + host = minion.Name } // TODO: Minion webservers should be secure! return "http://" + net.JoinHostPort(host, strconv.Itoa(ports.KubeletPort)), nil diff --git a/pkg/registry/minion/rest_test.go b/pkg/registry/minion/rest_test.go index ad95be27d65..e9aa1236125 100644 --- a/pkg/registry/minion/rest_test.go +++ b/pkg/registry/minion/rest_test.go @@ -27,25 +27,25 @@ 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).ID != "foo" { + if obj, err := ms.Get(ctx, "foo"); err != nil || obj.(*api.Minion).Name != "foo" { t.Errorf("missing expected object") } - if obj, err := ms.Get(ctx, "bar"); err != nil || obj.(*api.Minion).ID != "bar" { + if obj, err := ms.Get(ctx, "bar"); err != nil || obj.(*api.Minion).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{TypeMeta: api.TypeMeta{ID: "baz"}}) + c, err := ms.Create(ctx, &api.Minion{TypeMeta: api.TypeMeta{Name: "baz"}}) if err != nil { t.Errorf("insert failed") } obj := <-c - if m, ok := obj.(*api.Minion); !ok || m.ID != "baz" { + if m, ok := obj.(*api.Minion); !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).ID != "baz" { + if obj, err := ms.Get(ctx, "baz"); err != nil || obj.(*api.Minion).Name != "baz" { t.Errorf("insert didn't actually insert") } @@ -72,9 +72,9 @@ func TestMinionREST(t *testing.T) { } expect := []api.Minion{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }, { - TypeMeta: api.TypeMeta{ID: "baz"}, + TypeMeta: api.TypeMeta{Name: "baz"}, }, } nodeList := list.(*api.MinionList) @@ -85,7 +85,7 @@ func TestMinionREST(t *testing.T) { func contains(nodes *api.MinionList, nodeID string) bool { for _, node := range nodes.Items { - if node.ID == nodeID { + if node.Name == nodeID { return true } } diff --git a/pkg/registry/pod/bound_pod_factory_test.go b/pkg/registry/pod/bound_pod_factory_test.go index 6fb0a96ca2f..ed20b2fea74 100644 --- a/pkg/registry/pod/bound_pod_factory_test.go +++ b/pkg/registry/pod/bound_pod_factory_test.go @@ -32,7 +32,7 @@ func TestMakeBoundPodNoServices(t *testing.T) { } pod, err := factory.MakeBoundPod("machine", &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foobar"}, + TypeMeta: api.TypeMeta{Name: "foobar"}, DesiredState: api.PodState{ Manifest: api.ContainerManifest{ Containers: []api.Container{ @@ -51,8 +51,8 @@ func TestMakeBoundPodNoServices(t *testing.T) { if len(container.Env) != 0 { t.Errorf("Expected zero env vars, got: %#v", pod) } - if pod.ID != "foobar" { - t.Errorf("Failed to assign ID to pod: %#v", pod.ID) + if pod.Name != "foobar" { + t.Errorf("Failed to assign ID to pod: %#v", pod.Name) } } @@ -61,7 +61,7 @@ func TestMakeBoundPodServices(t *testing.T) { List: api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "test"}, + TypeMeta: api.TypeMeta{Name: "test"}, Port: 8080, ContainerPort: util.IntOrString{ Kind: util.IntstrInt, @@ -137,7 +137,7 @@ func TestMakeBoundPodServicesExistingEnvVar(t *testing.T) { List: api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "test"}, + TypeMeta: api.TypeMeta{Name: "test"}, Port: 8080, ContainerPort: util.IntOrString{ Kind: util.IntstrInt, diff --git a/pkg/registry/pod/rest.go b/pkg/registry/pod/rest.go index fae5f1c3721..bc806ae8978 100644 --- a/pkg/registry/pod/rest.go +++ b/pkg/registry/pod/rest.go @@ -94,12 +94,12 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context")) } pod.DesiredState.Manifest.UUID = uuid.NewUUID().String() - if len(pod.ID) == 0 { - pod.ID = pod.DesiredState.Manifest.UUID + if len(pod.Name) == 0 { + pod.Name = pod.DesiredState.Manifest.UUID } - pod.DesiredState.Manifest.ID = pod.ID + pod.DesiredState.Manifest.ID = pod.Name if errs := validation.ValidatePod(pod); len(errs) > 0 { - return nil, errors.NewInvalid("pod", pod.ID, errs) + return nil, errors.NewInvalid("pod", pod.Name, errs) } pod.CreationTimestamp = util.Now() @@ -107,7 +107,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if err := rs.registry.CreatePod(ctx, pod); err != nil { return nil, err } - return rs.registry.GetPod(ctx, pod.ID) + return rs.registry.GetPod(ctx, pod.Name) }), nil } @@ -141,7 +141,7 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) { func (rs *REST) podToSelectableFields(pod *api.Pod) labels.Set { return labels.Set{ - "ID": pod.ID, + "ID": pod.Name, "DesiredState.Status": string(pod.DesiredState.Status), "DesiredState.Host": pod.DesiredState.Host, } @@ -190,13 +190,13 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context")) } if errs := validation.ValidatePod(pod); len(errs) > 0 { - return nil, errors.NewInvalid("pod", pod.ID, errs) + return nil, errors.NewInvalid("pod", pod.Name, errs) } return apiserver.MakeAsync(func() (runtime.Object, error) { if err := rs.registry.UpdatePod(ctx, pod); err != nil { return nil, err } - return rs.registry.GetPod(ctx, pod.ID) + return rs.registry.GetPod(ctx, pod.Name) }), nil } @@ -208,13 +208,13 @@ func (rs *REST) fillPodInfo(pod *api.Pod) { // Get cached info for the list currently. // TODO: Optionally use fresh info if rs.podCache != nil { - info, err := rs.podCache.GetPodInfo(pod.CurrentState.Host, pod.Namespace, pod.ID) + info, err := rs.podCache.GetPodInfo(pod.CurrentState.Host, pod.Namespace, pod.Name) if err != nil { if err != client.ErrPodInfoNotAvailable { glog.Errorf("Error getting container info from cache: %#v", err) } if rs.podInfoGetter != nil { - info, err = rs.podInfoGetter.GetPodInfo(pod.CurrentState.Host, pod.Namespace, pod.ID) + info, err = rs.podInfoGetter.GetPodInfo(pod.CurrentState.Host, pod.Namespace, pod.Name) } if err != nil { if err != client.ErrPodInfoNotAvailable { @@ -232,7 +232,7 @@ func (rs *REST) fillPodInfo(pod *api.Pod) { glog.Warningf("No network settings: %#v", netContainerInfo) } } else { - glog.Warningf("Couldn't find network container for %s in %v", pod.ID, info) + glog.Warningf("Couldn't find network container for %s in %v", pod.Name, info) } } } @@ -280,7 +280,7 @@ func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodStatus, } found := false for _, minion := range res.Items { - if minion.ID == pod.CurrentState.Host { + if minion.Name == pod.CurrentState.Host { found = true break } diff --git a/pkg/registry/pod/rest_test.go b/pkg/registry/pod/rest_test.go index aaae3bfded6..3670bae69ac 100644 --- a/pkg/registry/pod/rest_test.go +++ b/pkg/registry/pod/rest_test.go @@ -95,10 +95,10 @@ func TestCreatePodSetsIds(t *testing.T) { } expectApiStatusError(t, ch, podRegistry.Err.Error()) - if len(podRegistry.Pod.ID) == 0 { + if len(podRegistry.Pod.Name) == 0 { t.Errorf("Expected pod ID to be set, Got %#v", pod) } - if podRegistry.Pod.DesiredState.Manifest.ID != podRegistry.Pod.ID { + if podRegistry.Pod.DesiredState.Manifest.ID != podRegistry.Pod.Name { t.Errorf("Expected manifest ID to be equal to pod ID, Got %#v", pod) } } @@ -176,12 +176,12 @@ func TestListPodList(t *testing.T) { Items: []api.Pod{ { TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, }, { TypeMeta: api.TypeMeta{ - ID: "bar", + Name: "bar", }, }, }, @@ -201,10 +201,10 @@ func TestListPodList(t *testing.T) { if len(pods.Items) != 2 { t.Errorf("Unexpected pod list: %#v", pods) } - if pods.Items[0].ID != "foo" { + if pods.Items[0].Name != "foo" { t.Errorf("Unexpected pod: %#v", pods.Items[0]) } - if pods.Items[1].ID != "bar" { + if pods.Items[1].Name != "bar" { t.Errorf("Unexpected pod: %#v", pods.Items[1]) } } @@ -214,18 +214,18 @@ func TestListPodListSelection(t *testing.T) { podRegistry.Pods = &api.PodList{ Items: []api.Pod{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, }, { - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, DesiredState: api.PodState{Host: "barhost"}, }, { - TypeMeta: api.TypeMeta{ID: "baz"}, + TypeMeta: api.TypeMeta{Name: "baz"}, DesiredState: api.PodState{Status: "bazstatus"}, }, { - TypeMeta: api.TypeMeta{ID: "qux"}, + TypeMeta: api.TypeMeta{Name: "qux"}, Labels: map[string]string{"label": "qux"}, }, { - TypeMeta: api.TypeMeta{ID: "zot"}, + TypeMeta: api.TypeMeta{Name: "zot"}, }, }, } @@ -284,10 +284,10 @@ func TestListPodListSelection(t *testing.T) { t.Errorf("%v: Expected %v, got %v", index, e, a) } for _, pod := range pods.Items { - if !item.expectedIDs.Has(pod.ID) { - t.Errorf("%v: Unexpected pod %v", index, pod.ID) + if !item.expectedIDs.Has(pod.Name) { + t.Errorf("%v: Unexpected pod %v", index, pod.Name) } - t.Logf("%v: Got pod ID: %v", index, pod.ID) + t.Logf("%v: Got pod Name: %v", index, pod.Name) } } } @@ -299,7 +299,7 @@ func TestPodDecode(t *testing.T) { } expected := &api.Pod{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", }, } body, err := latest.Codec.Encode(expected) @@ -319,7 +319,7 @@ func TestPodDecode(t *testing.T) { func TestGetPod(t *testing.T) { podRegistry := registrytest.NewPodRegistry(nil) - podRegistry.Pod = &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + podRegistry.Pod = &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} storage := REST{ registry: podRegistry, ipCache: ipCache{}, @@ -340,7 +340,7 @@ func TestGetPod(t *testing.T) { func TestGetPodCloud(t *testing.T) { fakeCloud := &fake_cloud.FakeCloud{} podRegistry := registrytest.NewPodRegistry(nil) - podRegistry.Pod = &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}, CurrentState: api.PodState{Host: "machine"}} + podRegistry.Pod = &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}, CurrentState: api.PodState{Host: "machine"}} clock := &fakeClock{t: time.Now()} @@ -386,7 +386,7 @@ func TestMakePodStatus(t *testing.T) { Minions: api.MinionList{ Items: []api.Minion{ { - TypeMeta: api.TypeMeta{ID: "machine"}, + TypeMeta: api.TypeMeta{Name: "machine"}, }, }, }, @@ -561,7 +561,7 @@ func TestPodStorageValidatesUpdate(t *testing.T) { func TestCreatePod(t *testing.T) { podRegistry := registrytest.NewPodRegistry(nil) podRegistry.Pod = &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, CurrentState: api.PodState{ Host: "machine", }, @@ -576,7 +576,7 @@ func TestCreatePod(t *testing.T) { }, } pod := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, DesiredState: desiredState, } ctx := api.NewDefaultContext() @@ -656,7 +656,7 @@ func TestFillPodInfoNoData(t *testing.T) { func TestCreatePodWithConflictingNamespace(t *testing.T) { storage := REST{} pod := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"}, + TypeMeta: api.TypeMeta{Name: "test", Namespace: "not-default"}, } ctx := api.NewDefaultContext() @@ -674,7 +674,7 @@ func TestCreatePodWithConflictingNamespace(t *testing.T) { func TestUpdatePodWithConflictingNamespace(t *testing.T) { storage := REST{} pod := &api.Pod{ - TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"}, + TypeMeta: api.TypeMeta{Name: "test", Namespace: "not-default"}, } ctx := api.NewDefaultContext() diff --git a/pkg/registry/registrytest/minion.go b/pkg/registry/registrytest/minion.go index 158e785b608..d0ccf3b13d6 100644 --- a/pkg/registry/registrytest/minion.go +++ b/pkg/registry/registrytest/minion.go @@ -34,7 +34,7 @@ func MakeMinionList(minions []string, nodeResources api.NodeResources) *api.Mini Items: make([]api.Minion, len(minions)), } for i := range minions { - list.Items[i].ID = minions[i] + list.Items[i].Name = minions[i] list.Items[i].NodeResources = nodeResources } return &list @@ -55,7 +55,7 @@ func (r *MinionRegistry) ListMinions(ctx api.Context) (*api.MinionList, error) { func (r *MinionRegistry) CreateMinion(ctx api.Context, minion *api.Minion) error { r.Lock() defer r.Unlock() - r.Minion = minion.ID + r.Minion = minion.Name r.Minions.Items = append(r.Minions.Items, *minion) return r.Err } @@ -64,7 +64,7 @@ func (r *MinionRegistry) GetMinion(ctx api.Context, minionID string) (*api.Minio r.Lock() defer r.Unlock() for _, node := range r.Minions.Items { - if node.ID == minionID { + if node.Name == minionID { return &node, r.Err } } @@ -76,8 +76,8 @@ func (r *MinionRegistry) DeleteMinion(ctx api.Context, minionID string) error { defer r.Unlock() var newList []api.Minion for _, node := range r.Minions.Items { - if node.ID != minionID { - newList = append(newList, api.Minion{TypeMeta: api.TypeMeta{ID: node.ID}}) + if node.Name != minionID { + newList = append(newList, api.Minion{TypeMeta: api.TypeMeta{Name: node.Name}}) } } r.Minions.Items = newList diff --git a/pkg/registry/registrytest/service.go b/pkg/registry/registrytest/service.go index 2871620c752..d2a0c194f00 100644 --- a/pkg/registry/registrytest/service.go +++ b/pkg/registry/registrytest/service.go @@ -82,7 +82,7 @@ func (r *ServiceRegistry) UpdateService(ctx api.Context, svc *api.Service) error r.mu.Lock() defer r.mu.Unlock() - r.UpdatedID = svc.ID + r.UpdatedID = svc.Name r.Service = svc return r.Err } diff --git a/pkg/registry/service/rest.go b/pkg/registry/service/rest.go index dce10514825..68f6c599f21 100644 --- a/pkg/registry/service/rest.go +++ b/pkg/registry/service/rest.go @@ -67,40 +67,40 @@ func reloadIPsFromStorage(ipa *ipAllocator, registry Registry) { return } for i := range services.Items { - s := &services.Items[i] - if s.PortalIP == "" { - glog.Warningf("service %q has no PortalIP", s.ID) + service := &services.Items[i] + if service.PortalIP == "" { + glog.Warningf("service %q has no PortalIP", service.Name) continue } - if err := ipa.Allocate(net.ParseIP(s.PortalIP)); err != nil { + if err := ipa.Allocate(net.ParseIP(service.PortalIP)); err != nil { // This is really bad. - glog.Errorf("service %q PortalIP %s could not be allocated: %s", s.ID, s.PortalIP, err) + glog.Errorf("service %q PortalIP %s could not be allocated: %s", service.Name, service.PortalIP, err) } } } func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { - srv := obj.(*api.Service) - if !api.ValidNamespace(ctx, &srv.TypeMeta) { - return nil, errors.NewConflict("service", srv.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) + service := obj.(*api.Service) + if !api.ValidNamespace(ctx, &service.TypeMeta) { + return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) } - if errs := validation.ValidateService(srv); len(errs) > 0 { - return nil, errors.NewInvalid("service", srv.ID, errs) + if errs := validation.ValidateService(service); len(errs) > 0 { + return nil, errors.NewInvalid("service", service.Name, errs) } - srv.CreationTimestamp = util.Now() + service.CreationTimestamp = util.Now() if ip, err := rs.portalMgr.AllocateNext(); err != nil { return nil, err } else { - srv.PortalIP = ip.String() + service.PortalIP = ip.String() } return apiserver.MakeAsync(func() (runtime.Object, error) { // TODO: Consider moving this to a rectification loop, so that we make/remove external load balancers // correctly no matter what http operations happen. - srv.ProxyPort = 0 - if srv.CreateExternalLoadBalancer { + service.ProxyPort = 0 + if service.CreateExternalLoadBalancer { if rs.cloud == nil { return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.") } @@ -120,26 +120,26 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje if err != nil { return nil, err } - err = balancer.CreateTCPLoadBalancer(srv.ID, zone.Region, srv.Port, hostsFromMinionList(hosts)) + err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, service.Port, hostsFromMinionList(hosts)) if err != nil { return nil, err } // External load-balancers require a known port for the service proxy. // TODO: If we end up brokering HostPorts between Pods and Services, this can be any port. - srv.ProxyPort = srv.Port + service.ProxyPort = service.Port } - err := rs.registry.CreateService(ctx, srv) + err := rs.registry.CreateService(ctx, service) if err != nil { return nil, err } - return rs.registry.GetService(ctx, srv.ID) + return rs.registry.GetService(ctx, service.Name) }), nil } func hostsFromMinionList(list *api.MinionList) []string { result := make([]string, len(list.Items)) for ix := range list.Items { - result[ix] = list.Items[ix].ID + result[ix] = list.Items[ix].Name } return result } @@ -157,11 +157,11 @@ func (rs *REST) Delete(ctx api.Context, id string) (<-chan runtime.Object, error } func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) { - s, err := rs.registry.GetService(ctx, id) + service, err := rs.registry.GetService(ctx, id) if err != nil { return nil, err } - return s, err + return service, err } // TODO: implement field selector? @@ -200,10 +200,10 @@ func GetServiceEnvironmentVariables(ctx api.Context, registry Registry, machine } for _, service := range services.Items { // Host - name := makeEnvVariableName(service.ID) + "_SERVICE_HOST" + name := makeEnvVariableName(service.Name) + "_SERVICE_HOST" result = append(result, api.EnvVar{Name: name, Value: service.PortalIP}) // Port - name = makeEnvVariableName(service.ID) + "_SERVICE_PORT" + name = makeEnvVariableName(service.Name) + "_SERVICE_PORT" result = append(result, api.EnvVar{Name: name, Value: strconv.Itoa(service.Port)}) // Docker-compatible vars. result = append(result, makeLinkVariables(service)...) @@ -212,27 +212,27 @@ func GetServiceEnvironmentVariables(ctx api.Context, registry Registry, machine } func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) { - srv := obj.(*api.Service) - if !api.ValidNamespace(ctx, &srv.TypeMeta) { - return nil, errors.NewConflict("service", srv.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) + service := obj.(*api.Service) + if !api.ValidNamespace(ctx, &service.TypeMeta) { + return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context")) } - if errs := validation.ValidateService(srv); len(errs) > 0 { - return nil, errors.NewInvalid("service", srv.ID, errs) + if errs := validation.ValidateService(service); len(errs) > 0 { + return nil, errors.NewInvalid("service", service.Name, errs) } return apiserver.MakeAsync(func() (runtime.Object, error) { - cur, err := rs.registry.GetService(ctx, srv.ID) + cur, err := rs.registry.GetService(ctx, service.Name) if err != nil { return nil, err } // Copy over non-user fields. - srv.PortalIP = cur.PortalIP - srv.ProxyPort = cur.ProxyPort + service.PortalIP = cur.PortalIP + service.ProxyPort = cur.ProxyPort // TODO: check to see if external load balancer status changed - err = rs.registry.UpdateService(ctx, srv) + err = rs.registry.UpdateService(ctx, service) if err != nil { return nil, err } - return rs.registry.GetService(ctx, srv.ID) + return rs.registry.GetService(ctx, service.Name) }), nil } @@ -270,7 +270,7 @@ func (rs *REST) deleteExternalLoadBalancer(service *api.Service) error { if err != nil { return err } - if err := balancer.DeleteTCPLoadBalancer(service.TypeMeta.ID, zone.Region); err != nil { + if err := balancer.DeleteTCPLoadBalancer(service.Name, zone.Region); err != nil { return err } return nil @@ -281,7 +281,7 @@ func makeEnvVariableName(str string) string { } func makeLinkVariables(service api.Service) []api.EnvVar { - prefix := makeEnvVariableName(service.ID) + prefix := makeEnvVariableName(service.Name) protocol := string(api.ProtocolTCP) if service.Protocol != "" { protocol = string(service.Protocol) diff --git a/pkg/registry/service/rest_test.go b/pkg/registry/service/rest_test.go index 7aeb02ee429..ad8659587b9 100644 --- a/pkg/registry/service/rest_test.go +++ b/pkg/registry/service/rest_test.go @@ -46,15 +46,15 @@ func TestServiceRegistryCreate(t *testing.T) { storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) svc := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } ctx := api.NewDefaultContext() c, _ := storage.Create(ctx, svc) created_svc := <-c created_service := created_svc.(*api.Service) - if created_service.ID != "foo" { - t.Errorf("Expected foo, but got %v", created_service.ID) + if created_service.Name != "foo" { + t.Errorf("Expected foo, but got %v", created_service.Name) } if created_service.CreationTimestamp.IsZero() { t.Errorf("Expected timestamp to be set, got: %v", created_service.CreationTimestamp) @@ -68,12 +68,12 @@ func TestServiceRegistryCreate(t *testing.T) { if len(fakeCloud.Calls) != 0 { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) } - srv, err := registry.GetService(ctx, svc.ID) + srv, err := registry.GetService(ctx, svc.Name) if err != nil { t.Errorf("unexpected error: %v", err) } if srv == nil { - t.Errorf("Failed to find service: %s", svc.ID) + t.Errorf("Failed to find service: %s", svc.Name) } } @@ -83,11 +83,11 @@ func TestServiceStorageValidatesCreate(t *testing.T) { failureCases := map[string]api.Service{ "empty ID": { Port: 6502, - TypeMeta: api.TypeMeta{ID: ""}, + TypeMeta: api.TypeMeta{Name: ""}, Selector: map[string]string{"bar": "baz"}, }, "empty selector": { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{}, }, } @@ -109,13 +109,13 @@ func TestServiceRegistryUpdate(t *testing.T) { registry := registrytest.NewServiceRegistry() registry.CreateService(ctx, &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz1"}, }) storage := NewREST(registry, nil, nil, makeIPNet(t)) c, err := storage.Update(ctx, &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz2"}, }) if c == nil { @@ -126,8 +126,8 @@ func TestServiceRegistryUpdate(t *testing.T) { } updated_svc := <-c updated_service := updated_svc.(*api.Service) - if updated_service.ID != "foo" { - t.Errorf("Expected foo, but got %v", updated_service.ID) + if updated_service.Name != "foo" { + t.Errorf("Expected foo, but got %v", updated_service.Name) } if e, a := "foo", registry.UpdatedID; e != a { t.Errorf("Expected %v, but got %v", e, a) @@ -139,19 +139,19 @@ func TestServiceStorageValidatesUpdate(t *testing.T) { registry := registrytest.NewServiceRegistry() registry.CreateService(ctx, &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, }) storage := NewREST(registry, nil, nil, makeIPNet(t)) failureCases := map[string]api.Service{ "empty ID": { Port: 6502, - TypeMeta: api.TypeMeta{ID: ""}, + TypeMeta: api.TypeMeta{Name: ""}, Selector: map[string]string{"bar": "baz"}, }, "empty selector": { Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{}, }, } @@ -174,7 +174,7 @@ func TestServiceRegistryExternalService(t *testing.T) { storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) svc := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, CreateExternalLoadBalancer: true, } @@ -183,12 +183,12 @@ func TestServiceRegistryExternalService(t *testing.T) { if len(fakeCloud.Calls) != 2 || fakeCloud.Calls[0] != "get-zone" || fakeCloud.Calls[1] != "create" { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) } - srv, err := registry.GetService(ctx, svc.ID) + srv, err := registry.GetService(ctx, svc.Name) if err != nil { t.Errorf("Unexpected error: %v", err) } if srv == nil { - t.Errorf("Failed to find service: %s", svc.ID) + t.Errorf("Failed to find service: %s", svc.Name) } } @@ -201,7 +201,7 @@ func TestServiceRegistryExternalServiceError(t *testing.T) { storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) svc := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, CreateExternalLoadBalancer: true, } @@ -223,11 +223,11 @@ func TestServiceRegistryDelete(t *testing.T) { machines := []string{"foo", "bar", "baz"} storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) svc := &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } registry.CreateService(ctx, svc) - c, _ := storage.Delete(ctx, svc.ID) + c, _ := storage.Delete(ctx, svc.Name) <-c if len(fakeCloud.Calls) != 0 { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) @@ -244,12 +244,12 @@ func TestServiceRegistryDeleteExternal(t *testing.T) { machines := []string{"foo", "bar", "baz"} storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) svc := &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, CreateExternalLoadBalancer: true, } registry.CreateService(ctx, svc) - c, _ := storage.Delete(ctx, svc.ID) + c, _ := storage.Delete(ctx, svc.Name) <-c if len(fakeCloud.Calls) != 2 || fakeCloud.Calls[0] != "get-zone" || fakeCloud.Calls[1] != "delete" { t.Errorf("Unexpected call(s): %#v", fakeCloud.Calls) @@ -265,21 +265,21 @@ func TestServiceRegistryMakeLinkVariables(t *testing.T) { registry.List = api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "foo-bar"}, + TypeMeta: api.TypeMeta{Name: "foo-bar"}, Selector: map[string]string{"bar": "baz"}, Port: 8080, Protocol: "TCP", PortalIP: "1.2.3.4", }, { - TypeMeta: api.TypeMeta{ID: "abc-123"}, + TypeMeta: api.TypeMeta{Name: "abc-123"}, Selector: map[string]string{"bar": "baz"}, Port: 8081, Protocol: "UDP", PortalIP: "5.6.7.8", }, { - TypeMeta: api.TypeMeta{ID: "q-u-u-x"}, + TypeMeta: api.TypeMeta{Name: "q-u-u-x"}, Selector: map[string]string{"bar": "baz"}, Port: 8082, Protocol: "", @@ -333,7 +333,7 @@ func TestServiceRegistryGet(t *testing.T) { machines := []string{"foo", "bar", "baz"} storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) registry.CreateService(ctx, &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, }) storage.Get(ctx, "foo") @@ -353,7 +353,7 @@ func TestServiceRegistryResourceLocation(t *testing.T) { machines := []string{"foo", "bar", "baz"} storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) registry.CreateService(ctx, &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, }) redirector := apiserver.Redirector(storage) @@ -382,11 +382,11 @@ func TestServiceRegistryList(t *testing.T) { machines := []string{"foo", "bar", "baz"} storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t)) registry.CreateService(ctx, &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, }) registry.CreateService(ctx, &api.Service{ - TypeMeta: api.TypeMeta{ID: "foo2"}, + TypeMeta: api.TypeMeta{Name: "foo2"}, Selector: map[string]string{"bar2": "baz2"}, }) registry.List.ResourceVersion = "1" @@ -398,10 +398,10 @@ func TestServiceRegistryList(t *testing.T) { if len(sl.Items) != 2 { t.Fatalf("Expected 2 services, but got %v", len(sl.Items)) } - if e, a := "foo", sl.Items[0].ID; e != a { + if e, a := "foo", sl.Items[0].Name; e != a { t.Errorf("Expected %v, but got %v", e, a) } - if e, a := "foo2", sl.Items[1].ID; e != a { + if e, a := "foo2", sl.Items[1].Name; e != a { t.Errorf("Expected %v, but got %v", e, a) } if sl.ResourceVersion != "1" { @@ -417,15 +417,15 @@ func TestServiceRegistryIPAllocation(t *testing.T) { svc1 := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } ctx := api.NewDefaultContext() c1, _ := rest.Create(ctx, svc1) created_svc1 := <-c1 created_service_1 := created_svc1.(*api.Service) - if created_service_1.ID != "foo" { - t.Errorf("Expected foo, but got %v", created_service_1.ID) + if created_service_1.Name != "foo" { + t.Errorf("Expected foo, but got %v", created_service_1.Name) } if created_service_1.PortalIP != "1.2.3.1" { t.Errorf("Unexpected PortalIP: %s", created_service_1.PortalIP) @@ -433,15 +433,15 @@ func TestServiceRegistryIPAllocation(t *testing.T) { svc2 := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, Selector: map[string]string{"bar": "baz"}, } ctx = api.NewDefaultContext() c2, _ := rest.Create(ctx, svc2) created_svc2 := <-c2 created_service_2 := created_svc2.(*api.Service) - if created_service_2.ID != "bar" { - t.Errorf("Expected bar, but got %v", created_service_2.ID) + if created_service_2.Name != "bar" { + t.Errorf("Expected bar, but got %v", created_service_2.Name) } if created_service_2.PortalIP != "1.2.3.2" { // new IP t.Errorf("Unexpected PortalIP: %s", created_service_2.PortalIP) @@ -456,34 +456,34 @@ func TestServiceRegistryIPReallocation(t *testing.T) { svc1 := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } ctx := api.NewDefaultContext() c1, _ := rest.Create(ctx, svc1) created_svc1 := <-c1 created_service_1 := created_svc1.(*api.Service) - if created_service_1.ID != "foo" { - t.Errorf("Expected foo, but got %v", created_service_1.ID) + if created_service_1.Name != "foo" { + t.Errorf("Expected foo, but got %v", created_service_1.Name) } if created_service_1.PortalIP != "1.2.3.1" { t.Errorf("Unexpected PortalIP: %s", created_service_1.PortalIP) } - c, _ := rest.Delete(ctx, created_service_1.ID) + c, _ := rest.Delete(ctx, created_service_1.Name) <-c svc2 := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "bar"}, + TypeMeta: api.TypeMeta{Name: "bar"}, Selector: map[string]string{"bar": "baz"}, } ctx = api.NewDefaultContext() c2, _ := rest.Create(ctx, svc2) created_svc2 := <-c2 created_service_2 := created_svc2.(*api.Service) - if created_service_2.ID != "bar" { - t.Errorf("Expected bar, but got %v", created_service_2.ID) + if created_service_2.Name != "bar" { + t.Errorf("Expected bar, but got %v", created_service_2.Name) } if created_service_2.PortalIP != "1.2.3.1" { // same IP as before t.Errorf("Unexpected PortalIP: %s", created_service_2.PortalIP) @@ -498,7 +498,7 @@ func TestServiceRegistryIPUpdate(t *testing.T) { svc := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } ctx := api.NewDefaultContext() @@ -543,7 +543,7 @@ func TestServiceRegistryIPExternalLoadBalancer(t *testing.T) { svc := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, CreateExternalLoadBalancer: true, } @@ -570,7 +570,7 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) { svc := &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } ctx := api.NewDefaultContext() @@ -578,7 +578,7 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) { <-c svc = &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } c, _ = rest1.Create(ctx, svc) @@ -589,7 +589,7 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) { svc = &api.Service{ Port: 6502, - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{"bar": "baz"}, } c, _ = rest2.Create(ctx, svc) @@ -603,7 +603,7 @@ func TestServiceRegistryIPReloadFromStorage(t *testing.T) { func TestCreateServiceWithConflictingNamespace(t *testing.T) { storage := REST{} service := &api.Service{ - TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"}, + TypeMeta: api.TypeMeta{Name: "test", Namespace: "not-default"}, } ctx := api.NewDefaultContext() @@ -621,7 +621,7 @@ func TestCreateServiceWithConflictingNamespace(t *testing.T) { func TestUpdateServiceWithConflictingNamespace(t *testing.T) { storage := REST{} service := &api.Service{ - TypeMeta: api.TypeMeta{ID: "test", Namespace: "not-default"}, + TypeMeta: api.TypeMeta{Name: "test", Namespace: "not-default"}, } ctx := api.NewDefaultContext() diff --git a/pkg/runtime/embedded_test.go b/pkg/runtime/embedded_test.go index 164f3102855..6fca4c41db0 100644 --- a/pkg/runtime/embedded_test.go +++ b/pkg/runtime/embedded_test.go @@ -48,10 +48,10 @@ func TestEmbeddedObject(t *testing.T) { s.AddKnownTypeWithName("v1test", "EmbeddedTest", &EmbeddedTestExternal{}) outer := &EmbeddedTest{ - TypeMeta: runtime.TypeMeta{ID: "outer"}, + TypeMeta: runtime.TypeMeta{Name: "outer"}, Object: runtime.EmbeddedObject{ &EmbeddedTest{ - TypeMeta: runtime.TypeMeta{ID: "inner"}, + TypeMeta: runtime.TypeMeta{Name: "inner"}, }, }, } @@ -79,7 +79,7 @@ func TestEmbeddedObject(t *testing.T) { if err != nil { t.Fatalf("Unexpected decode error %v", err) } - if externalViaJSON.Kind == "" || externalViaJSON.APIVersion == "" || externalViaJSON.ID != "outer" { + if externalViaJSON.Kind == "" || externalViaJSON.APIVersion == "" || externalViaJSON.Name != "outer" { t.Errorf("Expected objects to have type info set, got %#v", externalViaJSON) } if !reflect.DeepEqual(externalViaJSON.EmptyObject.RawJSON, []byte("null")) || len(externalViaJSON.Object.RawJSON) == 0 { diff --git a/pkg/runtime/helper_test.go b/pkg/runtime/helper_test.go index 834babc3028..0ccf44176b2 100644 --- a/pkg/runtime/helper_test.go +++ b/pkg/runtime/helper_test.go @@ -29,9 +29,9 @@ import ( func TestExtractList(t *testing.T) { pl := &api.PodList{ Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "1"}}, - {TypeMeta: api.TypeMeta{ID: "2"}}, - {TypeMeta: api.TypeMeta{ID: "3"}}, + {TypeMeta: api.TypeMeta{Name: "1"}}, + {TypeMeta: api.TypeMeta{Name: "2"}}, + {TypeMeta: api.TypeMeta{Name: "3"}}, }, } list, err := runtime.ExtractList(pl) @@ -42,7 +42,7 @@ func TestExtractList(t *testing.T) { t.Fatalf("Expected %v, got %v", e, a) } for i := range list { - if e, a := list[i].(*api.Pod).ID, pl.Items[i].ID; e != a { + if e, a := list[i].(*api.Pod).Name, pl.Items[i].Name; e != a { t.Fatalf("Expected %v, got %v", e, a) } } @@ -51,9 +51,9 @@ func TestExtractList(t *testing.T) { func TestSetList(t *testing.T) { pl := &api.PodList{} list := []runtime.Object{ - &api.Pod{TypeMeta: api.TypeMeta{ID: "1"}}, - &api.Pod{TypeMeta: api.TypeMeta{ID: "2"}}, - &api.Pod{TypeMeta: api.TypeMeta{ID: "3"}}, + &api.Pod{TypeMeta: api.TypeMeta{Name: "1"}}, + &api.Pod{TypeMeta: api.TypeMeta{Name: "2"}}, + &api.Pod{TypeMeta: api.TypeMeta{Name: "3"}}, } err := runtime.SetList(pl, list) if err != nil { @@ -63,7 +63,7 @@ func TestSetList(t *testing.T) { t.Fatalf("Expected %v, got %v", e, a) } for i := range list { - if e, a := list[i].(*api.Pod).ID, pl.Items[i].ID; e != a { + if e, a := list[i].(*api.Pod).Name, pl.Items[i].Name; e != a { t.Fatalf("Expected %v, got %v", e, a) } } diff --git a/pkg/runtime/typemeta.go b/pkg/runtime/typemeta.go index 0cecbbb5ec0..6dc616bd6fc 100644 --- a/pkg/runtime/typemeta.go +++ b/pkg/runtime/typemeta.go @@ -195,7 +195,7 @@ func fieldPtr(v reflect.Value, fieldName string, dest interface{}) error { // Returns an error if this isn't the case. func newGenericTypeMeta(v reflect.Value) (genericTypeMeta, error) { g := genericTypeMeta{} - if err := fieldPtr(v, "ID", &g.id); err != nil { + if err := fieldPtr(v, "Name", &g.id); err != nil { return g, err } if err := fieldPtr(v, "APIVersion", &g.apiVersion); err != nil { diff --git a/pkg/runtime/typemeta_test.go b/pkg/runtime/typemeta_test.go index 33664739347..bd4375048d5 100644 --- a/pkg/runtime/typemeta_test.go +++ b/pkg/runtime/typemeta_test.go @@ -26,14 +26,14 @@ import ( func TestGenericTypeMeta(t *testing.T) { type TypeMeta struct { Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` - ID string `json:"id,omitempty" yaml:"id,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"` APIVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"` } j := TypeMeta{ - ID: "foo", + Name: "foo", APIVersion: "a", Kind: "b", ResourceVersion: "1", @@ -68,7 +68,7 @@ func TestGenericTypeMeta(t *testing.T) { jbi.SetSelfLink("google.com") // Prove that jbi changes the original object. - if e, a := "bar", j.ID; e != a { + if e, a := "bar", j.Name; e != a { t.Errorf("expected %v, got %v", e, a) } if e, a := "c", j.APIVersion; e != a { diff --git a/pkg/runtime/types.go b/pkg/runtime/types.go index 717550041f1..f657861f7a8 100644 --- a/pkg/runtime/types.go +++ b/pkg/runtime/types.go @@ -36,7 +36,7 @@ import ( // type TypeMeta struct { Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` - ID string `json:"id,omitempty" yaml:"id,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"` diff --git a/pkg/scheduler/generic_scheduler.go b/pkg/scheduler/generic_scheduler.go index d121de4ba81..1c4c5639576 100644 --- a/pkg/scheduler/generic_scheduler.go +++ b/pkg/scheduler/generic_scheduler.go @@ -72,7 +72,7 @@ func findNodesThatFit(pod api.Pod, podLister PodLister, predicates []FitPredicat for _, node := range nodes.Items { fits := true for _, predicate := range predicates { - fit, err := predicate(pod, machineToPods[node.ID], node.ID) + fit, err := predicate(pod, machineToPods[node.Name], node.Name) if err != nil { return api.MinionList{}, err } @@ -111,7 +111,7 @@ func EqualPriority(pod api.Pod, podLister PodLister, minionLister MinionLister) } for _, minion := range nodes.Items { result = append(result, HostPriority{ - host: minion.ID, + host: minion.Name, score: 1, }) } diff --git a/pkg/scheduler/generic_scheduler_test.go b/pkg/scheduler/generic_scheduler_test.go index 4696001819f..26881bf1e74 100644 --- a/pkg/scheduler/generic_scheduler_test.go +++ b/pkg/scheduler/generic_scheduler_test.go @@ -34,7 +34,7 @@ func truePredicate(pod api.Pod, existingPods []api.Pod, node string) (bool, erro } func matchesPredicate(pod api.Pod, existingPods []api.Pod, node string) (bool, error) { - return pod.ID == node, nil + return pod.Name == node, nil } func numericPriority(pod api.Pod, podLister PodLister, minionLister MinionLister) (HostPriorityList, error) { @@ -46,12 +46,12 @@ func numericPriority(pod api.Pod, podLister PodLister, minionLister MinionLister return nil, err } for _, minion := range nodes.Items { - score, err := strconv.Atoi(minion.ID) + score, err := strconv.Atoi(minion.Name) if err != nil { return nil, err } result = append(result, HostPriority{ - host: minion.ID, + host: minion.Name, score: score, }) } @@ -63,7 +63,7 @@ func makeMinionList(nodeNames []string) api.MinionList { Items: make([]api.Minion, len(nodeNames)), } for ix := range nodeNames { - result.Items[ix].ID = nodeNames[ix] + result.Items[ix].Name = nodeNames[ix] } return result } @@ -95,7 +95,7 @@ func TestGenericScheduler(t *testing.T) { predicates: []FitPredicate{matchesPredicate}, prioritizer: EqualPriority, nodes: []string{"machine1", "machine2"}, - pod: api.Pod{TypeMeta: api.TypeMeta{ID: "machine2"}}, + pod: api.Pod{TypeMeta: api.TypeMeta{Name: "machine2"}}, expectedHost: "machine2", }, { @@ -108,7 +108,7 @@ func TestGenericScheduler(t *testing.T) { predicates: []FitPredicate{matchesPredicate}, prioritizer: numericPriority, nodes: []string{"3", "2", "1"}, - pod: api.Pod{TypeMeta: api.TypeMeta{ID: "2"}}, + pod: api.Pod{TypeMeta: api.TypeMeta{Name: "2"}}, expectedHost: "2", }, { diff --git a/pkg/scheduler/predicates.go b/pkg/scheduler/predicates.go index d9137ac2bea..9f3b15fa60b 100644 --- a/pkg/scheduler/predicates.go +++ b/pkg/scheduler/predicates.go @@ -36,7 +36,7 @@ type StaticNodeInfo struct { func (nodes StaticNodeInfo) GetNodeInfo(nodeID string) (*api.Minion, error) { for ix := range nodes.Items { - if nodes.Items[ix].ID == nodeID { + if nodes.Items[ix].Name == nodeID { return &nodes.Items[ix], nil } } diff --git a/pkg/scheduler/priorities.go b/pkg/scheduler/priorities.go index b338fa30842..f2782c9cfc2 100644 --- a/pkg/scheduler/priorities.go +++ b/pkg/scheduler/priorities.go @@ -47,7 +47,7 @@ func calculateOccupancy(node api.Minion, pods []api.Pod) HostPriority { glog.V(4).Infof("Least Requested Priority, AbsoluteRequested: (%d, %d) Percentage:(%d\\%m, %d\\%)", totalCPU, totalMemory, percentageCPU, percentageMemory) return HostPriority{ - host: node.ID, + host: node.Name, score: int((percentageCPU + percentageMemory) / 2), } } @@ -65,7 +65,7 @@ func LeastRequestedPriority(pod api.Pod, podLister PodLister, minionLister Minio list := HostPriorityList{} for _, node := range nodes.Items { - list = append(list, calculateOccupancy(node, podsToMachines[node.ID])) + list = append(list, calculateOccupancy(node, podsToMachines[node.Name])) } return list, nil } diff --git a/pkg/scheduler/priorities_test.go b/pkg/scheduler/priorities_test.go index 49bc1dcfab6..2a65cdcd477 100644 --- a/pkg/scheduler/priorities_test.go +++ b/pkg/scheduler/priorities_test.go @@ -27,7 +27,7 @@ import ( func makeMinion(node string, cpu, memory int) api.Minion { return api.Minion{ - TypeMeta: api.TypeMeta{ID: node}, + TypeMeta: api.TypeMeta{Name: node}, NodeResources: api.NodeResources{ Capacity: api.ResourceList{ resources.CPU: util.NewIntOrStringFromInt(cpu), diff --git a/pkg/scheduler/spreading.go b/pkg/scheduler/spreading.go index 28422b42226..907047c1453 100644 --- a/pkg/scheduler/spreading.go +++ b/pkg/scheduler/spreading.go @@ -44,7 +44,7 @@ func CalculateSpreadPriority(pod api.Pod, podLister PodLister, minionLister Mini result := []HostPriority{} for _, minion := range minions.Items { - result = append(result, HostPriority{host: minion.ID, score: counts[minion.ID]}) + result = append(result, HostPriority{host: minion.Name, score: counts[minion.Name]}) } return result, nil } diff --git a/pkg/service/endpoints_controller.go b/pkg/service/endpoints_controller.go index 1c408d10f37..03defdee676 100644 --- a/pkg/service/endpoints_controller.go +++ b/pkg/service/endpoints_controller.go @@ -72,13 +72,13 @@ func (e *EndpointController) SyncServiceEndpoints() error { } endpoints = append(endpoints, net.JoinHostPort(pod.CurrentState.PodIP, strconv.Itoa(port))) } - currentEndpoints, err := e.client.GetEndpoints(nsCtx, service.ID) + currentEndpoints, err := e.client.GetEndpoints(nsCtx, service.Name) if err != nil { // TODO this is brittle as all get out, refactor the client libraries to return a structured error. if errors.IsNotFound(err) { currentEndpoints = &api.Endpoints{ TypeMeta: api.TypeMeta{ - ID: service.ID, + Name: service.Name, }, } } else { @@ -96,7 +96,7 @@ func (e *EndpointController) SyncServiceEndpoints() error { } else { // Pre-existing if endpointsEqual(currentEndpoints, endpoints) { - glog.V(2).Infof("endpoints are equal for %s, skipping update", service.ID) + glog.V(2).Infof("endpoints are equal for %s, skipping update", service.Name) continue } _, err = e.client.UpdateEndpoints(nsCtx, newEndpoints) diff --git a/pkg/service/endpoints_controller_test.go b/pkg/service/endpoints_controller_test.go index fd074cc24ab..00362172e7b 100644 --- a/pkg/service/endpoints_controller_test.go +++ b/pkg/service/endpoints_controller_test.go @@ -35,7 +35,7 @@ func newPodList(count int) api.PodList { for i := 0; i < count; i++ { pods = append(pods, api.Pod{ TypeMeta: api.TypeMeta{ - ID: fmt.Sprintf("pod%d", i), + Name: fmt.Sprintf("pod%d", i), APIVersion: testapi.Version(), }, DesiredState: api.PodState{ @@ -181,7 +181,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) { serviceList := api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{ "foo": "bar", }, @@ -193,7 +193,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) { serverResponse{http.StatusOK, serviceList}, serverResponse{http.StatusOK, api.Endpoints{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", ResourceVersion: "1", }, Endpoints: []string{"6.7.8.9:1000"}, @@ -205,7 +205,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) { } data := runtime.EncodeOrDie(testapi.Codec(), &api.Endpoints{ TypeMeta: api.TypeMeta{ - ID: "foo", + Name: "foo", ResourceVersion: "1", }, Endpoints: []string{"1.2.3.4:8080"}, @@ -217,7 +217,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) { serviceList := api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{ "foo": "bar", }, @@ -245,7 +245,7 @@ func TestSyncEndpointsItems(t *testing.T) { serviceList := api.ServiceList{ Items: []api.Service{ { - TypeMeta: api.TypeMeta{ID: "foo"}, + TypeMeta: api.TypeMeta{Name: "foo"}, Selector: map[string]string{ "foo": "bar", }, diff --git a/pkg/tools/etcd_tools_test.go b/pkg/tools/etcd_tools_test.go index 1cfee63db54..f899befb7c9 100644 --- a/pkg/tools/etcd_tools_test.go +++ b/pkg/tools/etcd_tools_test.go @@ -73,15 +73,15 @@ func TestExtractToList(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: `{"id":"foo"}`, + Value: `{"name":"foo"}`, ModifiedIndex: 1, }, { - Value: `{"id":"bar"}`, + Value: `{"name":"bar"}`, ModifiedIndex: 2, }, { - Value: `{"id":"baz"}`, + Value: `{"name":"baz"}`, ModifiedIndex: 3, }, }, @@ -91,9 +91,9 @@ func TestExtractToList(t *testing.T) { expect := api.PodList{ TypeMeta: api.TypeMeta{ResourceVersion: "10"}, Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}}, - {TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}}, - {TypeMeta: api.TypeMeta{ID: "baz", ResourceVersion: "3"}}, + {TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}}, + {TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}}, + {TypeMeta: api.TypeMeta{Name: "baz", ResourceVersion: "3"}}, }, } @@ -117,21 +117,21 @@ func TestExtractToListAcrossDirectories(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: `{"id": "directory1"}`, + Value: `{"name": "directory1"}`, Dir: true, Nodes: []*etcd.Node{ { - Value: `{"id":"foo"}`, + Value: `{"name":"foo"}`, ModifiedIndex: 1, }, }, }, { - Value: `{"id": "directory2"}`, + Value: `{"name": "directory2"}`, Dir: true, Nodes: []*etcd.Node{ { - Value: `{"id":"bar"}`, + Value: `{"name":"bar"}`, ModifiedIndex: 2, }, }, @@ -143,8 +143,8 @@ func TestExtractToListAcrossDirectories(t *testing.T) { expect := api.PodList{ TypeMeta: api.TypeMeta{ResourceVersion: "10"}, Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}}, - {TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}}, + {TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}}, + {TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}}, }, } @@ -167,19 +167,19 @@ func TestExtractToListExcludesDirectories(t *testing.T) { Node: &etcd.Node{ Nodes: []*etcd.Node{ { - Value: `{"id":"foo"}`, + Value: `{"name":"foo"}`, ModifiedIndex: 1, }, { - Value: `{"id":"bar"}`, + Value: `{"name":"bar"}`, ModifiedIndex: 2, }, { - Value: `{"id":"baz"}`, + Value: `{"name":"baz"}`, ModifiedIndex: 3, }, { - Value: `{"id": "directory"}`, + Value: `{"name": "directory"}`, Dir: true, }, }, @@ -189,9 +189,9 @@ func TestExtractToListExcludesDirectories(t *testing.T) { expect := api.PodList{ TypeMeta: api.TypeMeta{ResourceVersion: "10"}, Items: []api.Pod{ - {TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}}, - {TypeMeta: api.TypeMeta{ID: "bar", ResourceVersion: "2"}}, - {TypeMeta: api.TypeMeta{ID: "baz", ResourceVersion: "3"}}, + {TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}}, + {TypeMeta: api.TypeMeta{Name: "bar", ResourceVersion: "2"}}, + {TypeMeta: api.TypeMeta{Name: "baz", ResourceVersion: "3"}}, }, } @@ -208,7 +208,7 @@ func TestExtractToListExcludesDirectories(t *testing.T) { func TestExtractObj(t *testing.T) { fakeClient := NewFakeEtcdClient(t) - expect := api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + expect := api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} fakeClient.Set("/some/key", util.EncodeJSON(expect), 0) helper := EtcdHelper{fakeClient, latest.Codec, versioner} var got api.Pod @@ -262,7 +262,7 @@ func TestExtractObjNotFoundErr(t *testing.T) { } func TestCreateObj(t *testing.T) { - obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + obj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} fakeClient := NewFakeEtcdClient(t) helper := EtcdHelper{fakeClient, latest.Codec, versioner} err := helper.CreateObj("/some/key", obj, 5) @@ -283,7 +283,7 @@ func TestCreateObj(t *testing.T) { } func TestSetObj(t *testing.T) { - obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + obj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} fakeClient := NewFakeEtcdClient(t) helper := EtcdHelper{fakeClient, latest.Codec, versioner} err := helper.SetObj("/some/key", obj) @@ -302,7 +302,7 @@ func TestSetObj(t *testing.T) { } func TestSetObjWithVersion(t *testing.T) { - obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo", ResourceVersion: "1"}} + obj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo", ResourceVersion: "1"}} fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true fakeClient.Data["/some/key"] = EtcdResponseWithError{ @@ -331,7 +331,7 @@ func TestSetObjWithVersion(t *testing.T) { } func TestSetObjWithoutResourceVersioner(t *testing.T) { - obj := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + obj := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} fakeClient := NewFakeEtcdClient(t) helper := EtcdHelper{fakeClient, latest.Codec, nil} err := helper.SetObj("/some/key", obj) @@ -356,7 +356,7 @@ func TestAtomicUpdate(t *testing.T) { // Create a new node. fakeClient.ExpectNotFoundGet("/some/key") - obj := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 1} + obj := &TestResource{TypeMeta: api.TypeMeta{Name: "foo"}, Value: 1} err := helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) { return obj, nil }) @@ -375,7 +375,7 @@ func TestAtomicUpdate(t *testing.T) { // Update an existing node. callbackCalled := false - objUpdate := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 2} + objUpdate := &TestResource{TypeMeta: api.TypeMeta{Name: "foo"}, Value: 2} err = helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) { callbackCalled = true @@ -410,7 +410,7 @@ func TestAtomicUpdateNoChange(t *testing.T) { // Create a new node. fakeClient.ExpectNotFoundGet("/some/key") - obj := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 1} + obj := &TestResource{TypeMeta: api.TypeMeta{Name: "foo"}, Value: 1} err := helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) { return obj, nil }) @@ -420,7 +420,7 @@ func TestAtomicUpdateNoChange(t *testing.T) { // Update an existing node with the same data callbackCalled := false - objUpdate := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: 1} + objUpdate := &TestResource{TypeMeta: api.TypeMeta{Name: "foo"}, Value: 1} fakeClient.Err = errors.New("should not be called") err = helper.AtomicUpdate("/some/key", &TestResource{}, func(in runtime.Object) (runtime.Object, error) { callbackCalled = true @@ -463,7 +463,7 @@ func TestAtomicUpdate_CreateCollision(t *testing.T) { } currValue := in.(*TestResource).Value - obj := &TestResource{TypeMeta: api.TypeMeta{ID: "foo"}, Value: currValue + 1} + obj := &TestResource{TypeMeta: api.TypeMeta{Name: "foo"}, Value: currValue + 1} return obj, nil }) if err != nil { diff --git a/pkg/tools/etcd_tools_watch_test.go b/pkg/tools/etcd_tools_watch_test.go index df271032cb4..f6d8e5e8b00 100644 --- a/pkg/tools/etcd_tools_watch_test.go +++ b/pkg/tools/etcd_tools_watch_test.go @@ -32,11 +32,11 @@ import ( func TestWatchInterpretations(t *testing.T) { codec := latest.Codec // Declare some pods to make the test cases compact. - podFoo := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} - podBar := &api.Pod{TypeMeta: api.TypeMeta{ID: "bar"}} - podBaz := &api.Pod{TypeMeta: api.TypeMeta{ID: "baz"}} + podFoo := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} + podBar := &api.Pod{TypeMeta: api.TypeMeta{Name: "bar"}} + podBaz := &api.Pod{TypeMeta: api.TypeMeta{Name: "baz"}} firstLetterIsB := func(obj runtime.Object) bool { - return obj.(*api.Pod).ID[0] == 'b' + return obj.(*api.Pod).Name[0] == 'b' } // All of these test cases will be run with the firstLetterIsB FilterFunc. @@ -236,7 +236,7 @@ func TestWatch(t *testing.T) { } // Test normal case - pod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + pod := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} podBytes, _ := codec.Encode(pod) fakeClient.WatchResponse <- &etcd.Response{ Action: "set", @@ -294,7 +294,7 @@ func TestWatchEtcdState(t *testing.T) { { Action: "create", Node: &etcd.Node{ - Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{}})), }, }, }, @@ -308,12 +308,12 @@ func TestWatchEtcdState(t *testing.T) { { Action: "compareAndSwap", Node: &etcd.Node{ - Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), + Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), CreatedIndex: 1, ModifiedIndex: 2, }, PrevNode: &etcd.Node{ - Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{}})), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -330,7 +330,7 @@ func TestWatchEtcdState(t *testing.T) { R: &etcd.Response{ Action: "get", Node: &etcd.Node{ - Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{}})), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -343,12 +343,12 @@ func TestWatchEtcdState(t *testing.T) { { Action: "compareAndSwap", Node: &etcd.Node{ - Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), + Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{"127.0.0.1:9000"}})), CreatedIndex: 1, ModifiedIndex: 2, }, PrevNode: &etcd.Node{ - Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{ID: "foo"}, Endpoints: []string{}})), + Value: string(runtime.EncodeOrDie(codec, &api.Endpoints{TypeMeta: api.TypeMeta{Name: "foo"}, Endpoints: []string{}})), CreatedIndex: 1, ModifiedIndex: 1, }, @@ -391,7 +391,7 @@ func TestWatchEtcdState(t *testing.T) { func TestWatchFromZeroIndex(t *testing.T) { codec := latest.Codec - pod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + pod := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} testCases := map[string]struct { Response EtcdResponseWithError @@ -464,7 +464,7 @@ func TestWatchFromZeroIndex(t *testing.T) { func TestWatchListFromZeroIndex(t *testing.T) { codec := latest.Codec - pod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + pod := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = EtcdResponseWithError{ diff --git a/pkg/watch/json/decoder_test.go b/pkg/watch/json/decoder_test.go index 7571819d4db..2e2b03e2d18 100644 --- a/pkg/watch/json/decoder_test.go +++ b/pkg/watch/json/decoder_test.go @@ -36,7 +36,7 @@ func TestDecoder(t *testing.T) { out, in := io.Pipe() decoder := NewDecoder(out, testapi.Codec()) - expect := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + expect := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} encoder := json.NewEncoder(in) go func() { data, err := testapi.Codec().Encode(expect) diff --git a/pkg/watch/json/encoder_test.go b/pkg/watch/json/encoder_test.go index a8dab9ad46c..b77fb792bc3 100644 --- a/pkg/watch/json/encoder_test.go +++ b/pkg/watch/json/encoder_test.go @@ -37,17 +37,17 @@ func TestEncodeDecodeRoundTrip(t *testing.T) { }{ { watch.Added, - &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}, + &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}, v1beta1.Codec, }, { watch.Modified, - &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}, + &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}, v1beta2.Codec, }, { watch.Deleted, - &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}, + &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}, api.Codec, }, } diff --git a/plugin/pkg/scheduler/factory/factory.go b/plugin/pkg/scheduler/factory/factory.go index 9b1abc17f02..8d0ae25ffe1 100644 --- a/plugin/pkg/scheduler/factory/factory.go +++ b/plugin/pkg/scheduler/factory/factory.go @@ -93,7 +93,7 @@ func (factory *ConfigFactory) Create() *scheduler.Config { glog.V(2).Infof("About to try and schedule pod %v\n"+ "\tknown minions: %v\n"+ "\tknown scheduled pods: %v\n", - pod.ID, minionCache.Contains(), podCache.Contains()) + pod.Name, minionCache.Contains(), podCache.Contains()) return pod }, Error: factory.makeDefaultErrorFunc(&podBackoff, podQueue), @@ -174,13 +174,13 @@ func (factory *ConfigFactory) pollMinions() (cache.Enumerator, error) { func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue *cache.FIFO) func(pod *api.Pod, err error) { return func(pod *api.Pod, err error) { - glog.Errorf("Error scheduling %v: %v; retrying", pod.ID, err) + glog.Errorf("Error scheduling %v: %v; retrying", pod.Name, err) backoff.gc() // Retry asynchronously. // Note that this is extremely rudimentary and we need a more real error handling path. go func() { defer util.HandleCrash() - podID := pod.ID + podID := pod.Name backoff.wait(podID) // Get the pod again; it may have changed/been scheduled already. pod = &api.Pod{} @@ -191,7 +191,7 @@ func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue return } if pod.DesiredState.Host == "" { - podQueue.Add(pod.ID, pod) + podQueue.Add(pod.Name, pod) } }() } @@ -247,7 +247,7 @@ func (me *minionEnumerator) Len() int { // Get returns the item (and ID) with the particular index. func (me *minionEnumerator) Get(index int) (string, interface{}) { - return me.Items[index].ID, &me.Items[index] + return me.Items[index].Name, &me.Items[index] } type binder struct { diff --git a/plugin/pkg/scheduler/factory/factory_test.go b/plugin/pkg/scheduler/factory/factory_test.go index d7b3cf008ff..d86f26f4a8d 100644 --- a/plugin/pkg/scheduler/factory/factory_test.go +++ b/plugin/pkg/scheduler/factory/factory_test.go @@ -145,8 +145,8 @@ func TestPollMinions(t *testing.T) { }{ { minions: []api.Minion{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, - {TypeMeta: api.TypeMeta{ID: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, }, }, } @@ -179,7 +179,7 @@ func TestPollMinions(t *testing.T) { } func TestDefaultErrorFunc(t *testing.T) { - testPod := &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}} + testPod := &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}} handler := util.FakeHandler{ StatusCode: 200, ResponseBody: runtime.EncodeOrDie(latest.Codec, testPod), @@ -219,7 +219,7 @@ func TestStoreToMinionLister(t *testing.T) { store := cache.NewStore() ids := util.NewStringSet("foo", "bar", "baz") for id := range ids { - store.Add(id, &api.Minion{TypeMeta: api.TypeMeta{ID: id}}) + store.Add(id, &api.Minion{TypeMeta: api.TypeMeta{Name: id}}) } sml := storeToMinionLister{store} @@ -229,7 +229,7 @@ func TestStoreToMinionLister(t *testing.T) { } got := make([]string, len(gotNodes.Items)) for ix := range gotNodes.Items { - got[ix] = gotNodes.Items[ix].ID + got[ix] = gotNodes.Items[ix].Name } if !ids.HasAll(got...) || len(got) != len(ids) { t.Errorf("Expected %v, got %v", ids, got) @@ -241,7 +241,7 @@ func TestStoreToPodLister(t *testing.T) { ids := []string{"foo", "bar", "baz"} for _, id := range ids { store.Add(id, &api.Pod{ - TypeMeta: api.TypeMeta{ID: id}, + TypeMeta: api.TypeMeta{Name: id}, Labels: map[string]string{"name": id}, }) } @@ -257,7 +257,7 @@ func TestStoreToPodLister(t *testing.T) { t.Errorf("Expected %v, got %v", e, a) continue } - if e, a := id, got[0].ID; e != a { + if e, a := id, got[0].Name; e != a { t.Errorf("Expected %v, got %v", e, a) continue } @@ -267,9 +267,9 @@ func TestStoreToPodLister(t *testing.T) { func TestMinionEnumerator(t *testing.T) { testList := &api.MinionList{ Items: []api.Minion{ - {TypeMeta: api.TypeMeta{ID: "foo"}}, - {TypeMeta: api.TypeMeta{ID: "bar"}}, - {TypeMeta: api.TypeMeta{ID: "baz"}}, + {TypeMeta: api.TypeMeta{Name: "foo"}}, + {TypeMeta: api.TypeMeta{Name: "bar"}}, + {TypeMeta: api.TypeMeta{Name: "baz"}}, }, } me := minionEnumerator{testList} @@ -279,7 +279,7 @@ func TestMinionEnumerator(t *testing.T) { } for i := range testList.Items { gotID, gotObj := me.Get(i) - if e, a := testList.Items[i].ID, gotID; e != a { + if e, a := testList.Items[i].Name, gotID; e != a { t.Errorf("Expected %v, got %v", e, a) } if e, a := &testList.Items[i], gotObj; !reflect.DeepEqual(e, a) { diff --git a/plugin/pkg/scheduler/scheduler.go b/plugin/pkg/scheduler/scheduler.go index d0d3e41c18f..a1fe15a354b 100644 --- a/plugin/pkg/scheduler/scheduler.go +++ b/plugin/pkg/scheduler/scheduler.go @@ -74,7 +74,7 @@ func (s *Scheduler) scheduleOne() { } b := &api.Binding{ TypeMeta: api.TypeMeta{Namespace: pod.Namespace}, - PodID: pod.ID, + PodID: pod.Name, Host: dest, } if err := s.config.Binder.Bind(b); err != nil { @@ -82,5 +82,5 @@ func (s *Scheduler) scheduleOne() { s.config.Error(pod, err) return } - record.Eventf(pod, "", string(api.PodWaiting), "scheduled", "Successfully assigned %v to %v", pod.ID, dest) + record.Eventf(pod, "", string(api.PodWaiting), "scheduled", "Successfully assigned %v to %v", pod.Name, dest) } diff --git a/plugin/pkg/scheduler/scheduler_test.go b/plugin/pkg/scheduler/scheduler_test.go index 421e4267789..396009484fd 100644 --- a/plugin/pkg/scheduler/scheduler_test.go +++ b/plugin/pkg/scheduler/scheduler_test.go @@ -34,7 +34,7 @@ type fakeBinder struct { func (fb fakeBinder) Bind(binding *api.Binding) error { return fb.b(binding) } func podWithID(id string) *api.Pod { - return &api.Pod{TypeMeta: api.TypeMeta{ID: id, SelfLink: testapi.SelfLink("pods", id)}} + return &api.Pod{TypeMeta: api.TypeMeta{Name: id, SelfLink: testapi.SelfLink("pods", id)}} } type mockScheduler struct { @@ -88,7 +88,7 @@ func TestScheduler(t *testing.T) { var gotBinding *api.Binding c := &Config{ MinionLister: scheduler.FakeMinionLister( - api.MinionList{Items: []api.Minion{{TypeMeta: api.TypeMeta{ID: "machine1"}}}}, + api.MinionList{Items: []api.Minion{{TypeMeta: api.TypeMeta{Name: "machine1"}}}}, ), Algorithm: item.algo, Binder: fakeBinder{func(b *api.Binding) error { diff --git a/test/integration/client_test.go b/test/integration/client_test.go index 4a7563fb8fc..0256be7eec6 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -104,8 +104,8 @@ func TestClient(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - if got.ID == "" { - t.Errorf("unexpected empty pod ID %v", got) + if got.Name == "" { + t.Errorf("unexpected empty pod Name %v", got) } // pod is shown, but not scheduled @@ -117,7 +117,7 @@ func TestClient(t *testing.T) { t.Errorf("expected one pod, got %#v", pods) } actual := pods.Items[0] - if actual.ID != got.ID { + if actual.Name != got.Name { t.Errorf("expected pod %#v, got %#v", got, actual) } if actual.CurrentState.Host != "" { diff --git a/test/integration/etcd_tools_test.go b/test/integration/etcd_tools_test.go index 025316a6f3f..87b0c33299d 100644 --- a/test/integration/etcd_tools_test.go +++ b/test/integration/etcd_tools_test.go @@ -95,7 +95,7 @@ func TestWatch(t *testing.T) { client := newEtcdClient() helper := tools.EtcdHelper{Client: client, Codec: latest.Codec, ResourceVersioner: tools.RuntimeVersionAdapter{latest.ResourceVersioner}} withEtcdKey(func(key string) { - resp, err := client.Set(key, runtime.EncodeOrDie(v1beta1.Codec, &api.Pod{TypeMeta: api.TypeMeta{ID: "foo"}}), 0) + resp, err := client.Set(key, runtime.EncodeOrDie(v1beta1.Codec, &api.Pod{TypeMeta: api.TypeMeta{Name: "foo"}}), 0) if err != nil { t.Fatalf("unexpected error: %v", err) }