Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use ID instead of Id (go style) everywhere #321

Merged
merged 1 commit into from
Jul 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ContainerManifest struct {
Version string `yaml:"version" json:"version"`
Volumes []Volume `yaml:"volumes" json:"volumes"`
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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubecfg/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestParsePod(t *testing.T) {
JSONBase: api.JSONBase{ID: "test pod"},
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Id: "My manifest",
ID: "My manifest",
Containers: []api.Container{
{Name: "my container"},
},
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestParseController(t *testing.T) {
PodTemplate: api.PodTemplate{
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Id: "My manifest",
ID: "My manifest",
Containers: []api.Container{
{Name: "my container"},
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (kl *Kubelet) getContainerId(manifest *api.ContainerManifest, container *ap
}
for id, dockerContainer := range dockerContainers {
manifestId, containerName := parseDockerName(dockerContainer.Names[0])
if manifestId == manifest.Id && containerName == container.Name {
if manifestId == manifest.ID && containerName == container.Name {
return DockerId(id), nil
}
}
Expand Down Expand Up @@ -247,8 +247,8 @@ const containerNamePrefix = "k8s"

// Creates a name which can be reversed to identify both manifest id and container name.
func buildDockerName(manifest *api.ContainerManifest, container *api.Container) string {
// Note, manifest.Id could be blank.
return fmt.Sprintf("%s--%s--%s--%08x", containerNamePrefix, escapeDash(container.Name), escapeDash(manifest.Id), rand.Uint32())
// Note, manifest.ID could be blank.
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
Expand Down Expand Up @@ -367,7 +367,7 @@ func (kl *Kubelet) killContainer(container docker.APIContainers) error {
kl.LogEvent(&api.Event{
Event: "STOP",
Manifest: &api.ContainerManifest{
Id: manifestId,
ID: manifestId,
},
Container: &api.Container{
Name: containerName,
Expand Down Expand Up @@ -650,14 +650,14 @@ func (kl *Kubelet) SyncManifests(config []api.ContainerManifest) error {
// Make sure we have a network container
netId, err := kl.getNetworkContainerId(&manifest)
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
}
if netId == "" {
glog.Infof("Network container doesn't exist, creating")
netId, err = kl.createNetworkContainer(&manifest)
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
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/kubelet_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func readResp(resp *http.Response) (string, error) {
func TestContainer(t *testing.T) {
fw := makeServerTest()
expected := []api.ContainerManifest{
{Id: "test_manifest"},
{ID: "test_manifest"},
}
body := bytes.NewBuffer([]byte(util.MakeJSONString(expected[0]))) // Only send a single ContainerManifest
resp, err := http.Post(fw.testHttpServer.URL+"/container", "application/json", body)
Expand All @@ -95,8 +95,8 @@ func TestContainer(t *testing.T) {
func TestContainers(t *testing.T) {
fw := makeServerTest()
expected := []api.ContainerManifest{
{Id: "test_manifest_1"},
{Id: "test_manifest_2"},
{ID: "test_manifest_1"},
{ID: "test_manifest_2"},
}
body := bytes.NewBuffer([]byte(util.MakeJSONString(expected)))
resp, err := http.Post(fw.testHttpServer.URL+"/containers", "application/json", body)
Expand Down
30 changes: 15 additions & 15 deletions pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func verifyStringArrayEquals(t *testing.T, actual, expected []string) {

func verifyPackUnpack(t *testing.T, manifestId, containerName string) {
name := buildDockerName(
&api.ContainerManifest{Id: manifestId},
&api.ContainerManifest{ID: manifestId},
&api.Container{Name: containerName},
)
returnedManifestId, returnedContainerName := parseDockerName(name)
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestGetContainerId(t *testing.T) {
DockerPuller: &FakeDockerPuller{},
}
manifest := api.ContainerManifest{
Id: "qux",
ID: "qux",
}
container := api.Container{
Name: "foo",
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestGetContainerId(t *testing.T) {
}

fakeDocker.clearCalls()
missingManifest := api.ContainerManifest{Id: "foobar"}
missingManifest := api.ContainerManifest{ID: "foobar"}
id, err = kubelet.getContainerId(&missingManifest, &container)
verifyCalls(t, fakeDocker, []string{"list"})
if id != "" {
Expand Down Expand Up @@ -245,12 +245,12 @@ func TestResponseToManifests(t *testing.T) {
list, err := kubelet.ResponseToManifests(&etcd.Response{
Node: &etcd.Node{
Value: util.MakeJSONString([]api.ContainerManifest{
{Id: "foo"},
{Id: "bar"},
{ID: "foo"},
{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)
}
expectNoError(t, err)
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestSyncManifestsDoesNothing(t *testing.T) {
}
err := kubelet.SyncManifests([]api.ContainerManifest{
{
Id: "foo",
ID: "foo",
Containers: []api.Container{
{Name: "bar"},
},
Expand Down Expand Up @@ -639,7 +639,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
func TestExtractFromValidDataFile(t *testing.T) {
kubelet := Kubelet{}

manifest := api.ContainerManifest{Id: "bar"}
manifest := api.ContainerManifest{ID: "bar"}
data, err := json.Marshal(manifest)
expectNoError(t, err)
file, err := ioutil.TempFile("", "foo")
Expand Down Expand Up @@ -669,8 +669,8 @@ func TestExtractFromDir(t *testing.T) {
kubelet := Kubelet{}

manifests := []api.ContainerManifest{
{Id: "aaaa"},
{Id: "bbbb"},
{ID: "aaaa"},
{ID: "bbbb"},
}

dirName, err := ioutil.TempDir("", "foo")
Expand All @@ -679,7 +679,7 @@ func TestExtractFromDir(t *testing.T) {
for _, manifest := range manifests {
data, err := json.Marshal(manifest)
expectNoError(t, err)
file, err := ioutil.TempFile(dirName, manifest.Id)
file, err := ioutil.TempFile(dirName, manifest.ID)
expectNoError(t, err)
name := file.Name()
expectNoError(t, file.Close())
Expand Down Expand Up @@ -716,7 +716,7 @@ func TestExtractFromHttpSingle(t *testing.T) {
reader := startReading(updateChannel)

manifests := []api.ContainerManifest{
{Version: "v1beta1", Id: "foo"},
{Version: "v1beta1", ID: "foo"},
}
// Taking a single-manifest from a URL allows kubelet to be used
// in the implementation of google's container VM image.
Expand Down Expand Up @@ -751,8 +751,8 @@ func TestExtractFromHttpMultiple(t *testing.T) {
reader := startReading(updateChannel)

manifests := []api.ContainerManifest{
{Version: "v1beta1", Id: "foo"},
{Version: "v1beta1", Id: "bar"},
{Version: "v1beta1", ID: "foo"},
{Version: "v1beta1", ID: "bar"},
}
data, err := json.Marshal(manifests)
if err != nil {
Expand Down Expand Up @@ -828,7 +828,7 @@ func TestWatchEtcd(t *testing.T) {

manifest := []api.ContainerManifest{
{
Id: "foo",
ID: "foo",
},
}
data, err := json.Marshal(manifest)
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/etcd_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (registry *EtcdRegistry) deletePodFromMachine(machine, podID string) error
newManifests := make([]api.ContainerManifest, 0, len(manifests))
found := false
for _, manifest := range manifests {
if manifest.Id != podID {
if manifest.ID != podID {
newManifests = append(newManifests, manifest)
} else {
found = true
Expand Down
20 changes: 10 additions & 10 deletions pkg/registry/etcd_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestEtcdCreatePod(t *testing.T) {
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err)
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)
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
},
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Id: "foo",
ID: "foo",
Containers: []api.Container{
{
Name: "foo",
Expand All @@ -201,7 +201,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err)
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)
}
}
Expand All @@ -216,7 +216,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
}
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{
Id: "bar",
ID: "bar",
},
}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
Expand All @@ -226,7 +226,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
},
DesiredState: api.PodState{
Manifest: api.ContainerManifest{
Id: "foo",
ID: "foo",
Containers: []api.Container{
{
Name: "foo",
Expand All @@ -248,7 +248,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
resp, err = fakeClient.Get("/registry/hosts/machine/kubelet", false, false)
expectNoError(t, err)
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)
}
}
Expand All @@ -259,7 +259,7 @@ func TestEtcdDeletePod(t *testing.T) {
fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{
Id: "foo",
ID: "foo",
},
}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
Expand All @@ -281,8 +281,8 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
key := "/registry/hosts/machine/pods/foo"
fakeClient.Set(key, util.MakeJSONString(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]api.ContainerManifest{
{Id: "foo"},
{Id: "bar"},
{ID: "foo"},
{ID: "bar"},
}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.DeletePod("foo")
Expand All @@ -299,7 +299,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
if len(manifests) != 1 {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/manifest_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (b *BasicManifestFactory) MakeManifest(machine string, pod api.Pod) (api.Co
return api.ContainerManifest{}, err
}
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...)
}
return pod.DesiredState.Manifest, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/manifest_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestMakeManifestNoServices(t *testing.T) {
container.Env[0].Value != "machine" {
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")
}
}
Expand Down