Use ID instead of Id (go style) everywhere

Fixes #278
This commit is contained in:
Clayton Coleman 2014-06-30 15:41:48 -04:00
parent d53c56dd29
commit 15c96508a9
9 changed files with 40 additions and 40 deletions

View File

@ -23,7 +23,7 @@ type ContainerManifest struct {
Version string `yaml:"version" json:"version"` Version string `yaml:"version" json:"version"`
Volumes []Volume `yaml:"volumes" json:"volumes"` Volumes []Volume `yaml:"volumes" json:"volumes"`
Containers []Container `yaml:"containers" json:"containers"` Containers []Container `yaml:"containers" json:"containers"`
Id string `yaml:"id,omitempty" json:"id,omitempty"` ID string `yaml:"id,omitempty" json:"id,omitempty"`
} }
// Volume represents a named volume in a pod that may be accessed by any containers in the pod. // Volume represents a named volume in a pod that may be accessed by any containers in the pod.

View File

@ -59,7 +59,7 @@ func TestParsePod(t *testing.T) {
JSONBase: api.JSONBase{ID: "test pod"}, JSONBase: api.JSONBase{ID: "test pod"},
DesiredState: api.PodState{ DesiredState: api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
Id: "My manifest", ID: "My manifest",
Containers: []api.Container{ Containers: []api.Container{
{Name: "my container"}, {Name: "my container"},
}, },
@ -91,7 +91,7 @@ func TestParseController(t *testing.T) {
PodTemplate: api.PodTemplate{ PodTemplate: api.PodTemplate{
DesiredState: api.PodState{ DesiredState: api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
Id: "My manifest", ID: "My manifest",
Containers: []api.Container{ Containers: []api.Container{
{Name: "my container"}, {Name: "my container"},
}, },

View File

@ -198,7 +198,7 @@ func (kl *Kubelet) getContainerId(manifest *api.ContainerManifest, container *ap
} }
for id, dockerContainer := range dockerContainers { for id, dockerContainer := range dockerContainers {
manifestId, containerName := parseDockerName(dockerContainer.Names[0]) manifestId, containerName := parseDockerName(dockerContainer.Names[0])
if manifestId == manifest.Id && containerName == container.Name { if manifestId == manifest.ID && containerName == container.Name {
return DockerId(id), nil return DockerId(id), nil
} }
} }
@ -247,8 +247,8 @@ const containerNamePrefix = "k8s"
// Creates a name which can be reversed to identify both manifest id and container name. // Creates a name which can be reversed to identify both manifest id and container name.
func buildDockerName(manifest *api.ContainerManifest, container *api.Container) string { func buildDockerName(manifest *api.ContainerManifest, container *api.Container) string {
// Note, manifest.Id could be blank. // Note, manifest.ID could be blank.
return fmt.Sprintf("%s--%s--%s--%08x", containerNamePrefix, escapeDash(container.Name), escapeDash(manifest.Id), rand.Uint32()) return fmt.Sprintf("%s--%s--%s--%08x", containerNamePrefix, escapeDash(container.Name), escapeDash(manifest.ID), rand.Uint32())
} }
// Upacks a container name, returning the manifest id and container name we would have used to // Upacks a container name, returning the manifest id and container name we would have used to
@ -367,7 +367,7 @@ func (kl *Kubelet) killContainer(container docker.APIContainers) error {
kl.LogEvent(&api.Event{ kl.LogEvent(&api.Event{
Event: "STOP", Event: "STOP",
Manifest: &api.ContainerManifest{ Manifest: &api.ContainerManifest{
Id: manifestId, ID: manifestId,
}, },
Container: &api.Container{ Container: &api.Container{
Name: containerName, Name: containerName,
@ -650,14 +650,14 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
// Make sure we have a network container // Make sure we have a network container
netId, err := kl.getNetworkContainerId(&manifest) netId, err := kl.getNetworkContainerId(&manifest)
if err != nil { if err != nil {
glog.Errorf("Failed to introspect network container. (%v) Skipping container %s", err, manifest.Id) glog.Errorf("Failed to introspect network container. (%v) Skipping container %s", err, manifest.ID)
continue continue
} }
if netId == "" { if netId == "" {
glog.Infof("Network container doesn't exist, creating") glog.Infof("Network container doesn't exist, creating")
netId, err = kl.createNetworkContainer(&manifest) netId, err = kl.createNetworkContainer(&manifest)
if err != nil { if err != nil {
glog.Errorf("Failed to create network container: %v Skipping container %s", err, manifest.Id) glog.Errorf("Failed to create network container: %v Skipping container %s", err, manifest.ID)
continue continue
} }
} }

View File

@ -74,7 +74,7 @@ func readResp(resp *http.Response) (string, error) {
func TestContainer(t *testing.T) { func TestContainer(t *testing.T) {
fw := makeServerTest() fw := makeServerTest()
expected := []api.ContainerManifest{ expected := []api.ContainerManifest{
{Id: "test_manifest"}, {ID: "test_manifest"},
} }
body := bytes.NewBuffer([]byte(util.MakeJSONString(expected[0]))) // Only send a single ContainerManifest body := bytes.NewBuffer([]byte(util.MakeJSONString(expected[0]))) // Only send a single ContainerManifest
resp, err := http.Post(fw.testHttpServer.URL+"/container", "application/json", body) resp, err := http.Post(fw.testHttpServer.URL+"/container", "application/json", body)
@ -95,8 +95,8 @@ func TestContainer(t *testing.T) {
func TestContainers(t *testing.T) { func TestContainers(t *testing.T) {
fw := makeServerTest() fw := makeServerTest()
expected := []api.ContainerManifest{ expected := []api.ContainerManifest{
{Id: "test_manifest_1"}, {ID: "test_manifest_1"},
{Id: "test_manifest_2"}, {ID: "test_manifest_2"},
} }
body := bytes.NewBuffer([]byte(util.MakeJSONString(expected))) body := bytes.NewBuffer([]byte(util.MakeJSONString(expected)))
resp, err := http.Post(fw.testHttpServer.URL+"/containers", "application/json", body) resp, err := http.Post(fw.testHttpServer.URL+"/containers", "application/json", body)

View File

@ -110,7 +110,7 @@ func verifyStringArrayEquals(t *testing.T, actual, expected []string) {
func verifyPackUnpack(t *testing.T, manifestId, containerName string) { func verifyPackUnpack(t *testing.T, manifestId, containerName string) {
name := buildDockerName( name := buildDockerName(
&api.ContainerManifest{Id: manifestId}, &api.ContainerManifest{ID: manifestId},
&api.Container{Name: containerName}, &api.Container{Name: containerName},
) )
returnedManifestId, returnedContainerName := parseDockerName(name) returnedManifestId, returnedContainerName := parseDockerName(name)
@ -142,7 +142,7 @@ func TestGetContainerId(t *testing.T) {
DockerPuller: &FakeDockerPuller{}, DockerPuller: &FakeDockerPuller{},
} }
manifest := api.ContainerManifest{ manifest := api.ContainerManifest{
Id: "qux", ID: "qux",
} }
container := api.Container{ container := api.Container{
Name: "foo", Name: "foo",
@ -171,7 +171,7 @@ func TestGetContainerId(t *testing.T) {
} }
fakeDocker.clearCalls() fakeDocker.clearCalls()
missingManifest := api.ContainerManifest{Id: "foobar"} missingManifest := api.ContainerManifest{ID: "foobar"}
id, err = kubelet.getContainerId(&missingManifest, &container) id, err = kubelet.getContainerId(&missingManifest, &container)
verifyCalls(t, fakeDocker, []string{"list"}) verifyCalls(t, fakeDocker, []string{"list"})
if id != "" { if id != "" {
@ -245,12 +245,12 @@ func TestResponseToManifests(t *testing.T) {
list, err := kubelet.ResponseToManifests(&etcd.Response{ list, err := kubelet.ResponseToManifests(&etcd.Response{
Node: &etcd.Node{ Node: &etcd.Node{
Value: util.MakeJSONString([]api.ContainerManifest{ Value: util.MakeJSONString([]api.ContainerManifest{
{Id: "foo"}, {ID: "foo"},
{Id: "bar"}, {ID: "bar"},
}), }),
}, },
}) })
if len(list) != 2 || list[0].Id != "foo" || list[1].Id != "bar" { if len(list) != 2 || list[0].ID != "foo" || list[1].ID != "bar" {
t.Errorf("Unexpected list: %#v", list) t.Errorf("Unexpected list: %#v", list)
} }
expectNoError(t, err) expectNoError(t, err)
@ -399,7 +399,7 @@ func TestSyncManifestsDoesNothing(t *testing.T) {
} }
err := kubelet.SyncManifests([]api.ContainerManifest{ err := kubelet.SyncManifests([]api.ContainerManifest{
{ {
Id: "foo", ID: "foo",
Containers: []api.Container{ Containers: []api.Container{
{Name: "bar"}, {Name: "bar"},
}, },
@ -639,7 +639,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
func TestExtractFromValidDataFile(t *testing.T) { func TestExtractFromValidDataFile(t *testing.T) {
kubelet := Kubelet{} kubelet := Kubelet{}
manifest := api.ContainerManifest{Id: "bar"} manifest := api.ContainerManifest{ID: "bar"}
data, err := json.Marshal(manifest) data, err := json.Marshal(manifest)
expectNoError(t, err) expectNoError(t, err)
file, err := ioutil.TempFile("", "foo") file, err := ioutil.TempFile("", "foo")
@ -669,8 +669,8 @@ func TestExtractFromDir(t *testing.T) {
kubelet := Kubelet{} kubelet := Kubelet{}
manifests := []api.ContainerManifest{ manifests := []api.ContainerManifest{
{Id: "aaaa"}, {ID: "aaaa"},
{Id: "bbbb"}, {ID: "bbbb"},
} }
dirName, err := ioutil.TempDir("", "foo") dirName, err := ioutil.TempDir("", "foo")
@ -679,7 +679,7 @@ func TestExtractFromDir(t *testing.T) {
for _, manifest := range manifests { for _, manifest := range manifests {
data, err := json.Marshal(manifest) data, err := json.Marshal(manifest)
expectNoError(t, err) expectNoError(t, err)
file, err := ioutil.TempFile(dirName, manifest.Id) file, err := ioutil.TempFile(dirName, manifest.ID)
expectNoError(t, err) expectNoError(t, err)
name := file.Name() name := file.Name()
expectNoError(t, file.Close()) expectNoError(t, file.Close())
@ -716,7 +716,7 @@ func TestExtractFromHttpSingle(t *testing.T) {
reader := startReading(updateChannel) reader := startReading(updateChannel)
manifests := []api.ContainerManifest{ manifests := []api.ContainerManifest{
{Version: "v1beta1", Id: "foo"}, {Version: "v1beta1", ID: "foo"},
} }
// Taking a single-manifest from a URL allows kubelet to be used // Taking a single-manifest from a URL allows kubelet to be used
// in the implementation of google's container VM image. // in the implementation of google's container VM image.
@ -751,8 +751,8 @@ func TestExtractFromHttpMultiple(t *testing.T) {
reader := startReading(updateChannel) reader := startReading(updateChannel)
manifests := []api.ContainerManifest{ manifests := []api.ContainerManifest{
{Version: "v1beta1", Id: "foo"}, {Version: "v1beta1", ID: "foo"},
{Version: "v1beta1", Id: "bar"}, {Version: "v1beta1", ID: "bar"},
} }
data, err := json.Marshal(manifests) data, err := json.Marshal(manifests)
if err != nil { if err != nil {
@ -828,7 +828,7 @@ func TestWatchEtcd(t *testing.T) {
manifest := []api.ContainerManifest{ manifest := []api.ContainerManifest{
{ {
Id: "foo", ID: "foo",
}, },
} }
data, err := json.Marshal(manifest) data, err := json.Marshal(manifest)

View File

@ -150,7 +150,7 @@ func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error
newManifests := make([]api.ContainerManifest, 0, len(manifests)) newManifests := make([]api.ContainerManifest, 0, len(manifests))
found := false found := false
for _, manifest := range manifests { for _, manifest := range manifests {
if manifest.Id != podID { if manifest.ID != podID {
newManifests = append(newManifests, manifest) newManifests = append(newManifests, manifest)
} else { } else {
found = true found = true

View File

@ -100,7 +100,7 @@ func TestEtcdCreatePod(t *testing.T) {
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false) resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err) expectNoError(t, err)
err = json.Unmarshal([]byte(resp.Node.Value), &manifests) err = json.Unmarshal([]byte(resp.Node.Value), &manifests)
if len(manifests) != 1 || manifests[0].Id != "foo" { if len(manifests) != 1 || manifests[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
} }
@ -179,7 +179,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
}, },
DesiredState: api.PodState{ DesiredState: api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
Id: "foo", ID: "foo",
Containers: []api.Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
@ -201,7 +201,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false) resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err) expectNoError(t, err)
err = json.Unmarshal([]byte(resp.Node.Value), &manifests) err = json.Unmarshal([]byte(resp.Node.Value), &manifests)
if len(manifests) != 1 || manifests[0].Id != "foo" { if len(manifests) != 1 || manifests[0].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
} }
@ -216,7 +216,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
} }
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{ fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{ {
Id: "bar", ID: "bar",
}, },
}), 0) }), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
@ -226,7 +226,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
}, },
DesiredState: api.PodState{ DesiredState: api.PodState{
Manifest: api.ContainerManifest{ Manifest: api.ContainerManifest{
Id: "foo", ID: "foo",
Containers: []api.Container{ Containers: []api.Container{
{ {
Name: "foo", Name: "foo",
@ -248,7 +248,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false) resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err) expectNoError(t, err)
err = json.Unmarshal([]byte(resp.Node.Value), &manifests) err = json.Unmarshal([]byte(resp.Node.Value), &manifests)
if len(manifests) != 2 || manifests[1].Id != "foo" { if len(manifests) != 2 || manifests[1].ID != "foo" {
t.Errorf("Unexpected manifest list: %#v", manifests) t.Errorf("Unexpected manifest list: %#v", manifests)
} }
} }
@ -259,7 +259,7 @@ func TestEtcdDeletePod(t *testing.T) {
fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{ fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{ {
Id: "foo", ID: "foo",
}, },
}), 0) }), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
@ -281,8 +281,8 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
key := "/registry/hosts/machine/pods/foo" key := "/registry/hosts/machine/pods/foo"
fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{ fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{Id: "foo"}, {ID: "foo"},
{Id: "bar"}, {ID: "bar"},
}), 0) }), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.DeletePod("foo") err := registry.DeletePod("foo")
@ -299,7 +299,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
if len(manifests) != 1 { if len(manifests) != 1 {
t.Errorf("Unexpected manifest set: %#v, expected empty", manifests) t.Errorf("Unexpected manifest set: %#v, expected empty", manifests)
} }
if manifests[0].Id != "bar" { if manifests[0].ID != "bar" {
t.Errorf("Deleted wrong manifest: %#v", manifests) t.Errorf("Deleted wrong manifest: %#v", manifests)
} }
} }

View File

@ -35,7 +35,7 @@ func (b *BasicManifestFactory) MakeManifest(machine string, pod api.Pod) (api.Co
return api.ContainerManifest{}, err return api.ContainerManifest{}, err
} }
for ix, container := range pod.DesiredState.Manifest.Containers { for ix, container := range pod.DesiredState.Manifest.Containers {
pod.DesiredState.Manifest.Id = pod.ID pod.DesiredState.Manifest.ID = pod.ID
pod.DesiredState.Manifest.Containers[ix].Env = append(container.Env, envVars...) pod.DesiredState.Manifest.Containers[ix].Env = append(container.Env, envVars...)
} }
return pod.DesiredState.Manifest, nil return pod.DesiredState.Manifest, nil

View File

@ -47,7 +47,7 @@ func TestMakeManifestNoServices(t *testing.T) {
container.Env[0].Value != "machine" { container.Env[0].Value != "machine" {
t.Errorf("Expected one env vars, got: %#v", manifest) t.Errorf("Expected one env vars, got: %#v", manifest)
} }
if manifest.Id != "foobar" { if manifest.ID != "foobar" {
t.Errorf("Failed to assign id to manifest: %#v") t.Errorf("Failed to assign id to manifest: %#v")
} }
} }