diff --git a/api/examples/pod-list.json b/api/examples/pod-list.json
index 9ad192c5cb0e6..3cf50b0cbe466 100644
--- a/api/examples/pod-list.json
+++ b/api/examples/pod-list.json
@@ -9,6 +9,7 @@
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf5",
"image": "dockerfile/nginx",
"ports": [{
"hostPort": 8080,
@@ -30,6 +31,7 @@
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"image": "dockerfile/nginx",
"ports": [{
"hostPort": 8080,
diff --git a/api/examples/pod.json b/api/examples/pod.json
index 2a26cb742f571..0f60c4ed53aee 100644
--- a/api/examples/pod.json
+++ b/api/examples/pod.json
@@ -3,6 +3,7 @@
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"image": "dockerfile/nginx",
"ports": [{
"containerPort": 80,
diff --git a/api/kubernetes.html b/api/kubernetes.html
index df5d77a8fdbf9..e6ede305a5d43 100644
--- a/api/kubernetes.html
+++ b/api/kubernetes.html
@@ -259,6 +259,8 @@
+
+
@@ -287,6 +289,7 @@ Body
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf5",
"image": "dockerfile/nginx",
"ports": [{
"hostPort": 8080,
@@ -308,6 +311,7 @@ Body
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"image": "dockerfile/nginx",
"ports": [{
"hostPort": 8080,
@@ -364,6 +368,8 @@
+
+
Body
Type: application/json
@@ -466,6 +472,7 @@ Body
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"image": "dockerfile/nginx",
"ports": [{
"containerPort": 80,
@@ -575,6 +582,8 @@ URI Parameters
+
+
@@ -597,6 +606,7 @@ Body
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"image": "dockerfile/nginx",
"ports": [{
"containerPort": 80,
@@ -660,6 +670,8 @@ URI Parameters
+
+
Body
Type: application/json
@@ -762,6 +774,7 @@ Body
"desiredState": {
"manifest": {
"containers": [{
+ "id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"image": "dockerfile/nginx",
"ports": [{
"containerPort": 80,
@@ -829,6 +842,8 @@ URI Parameters
+
+
@@ -947,6 +962,8 @@
+
+
@@ -1036,6 +1053,8 @@
+
+
Body
Type: application/json
@@ -1210,6 +1229,8 @@ URI Parameters
+
+
@@ -1295,6 +1316,8 @@ URI Parameters
+
+
Body
Type: application/json
@@ -1427,6 +1450,8 @@ URI Parameters
+
+
@@ -1545,6 +1570,8 @@
+
+
@@ -1631,6 +1658,8 @@
+
+
Body
Type: application/json
@@ -1787,6 +1816,8 @@ URI Parameters
+
+
@@ -1864,6 +1895,8 @@ URI Parameters
+
+
Body
Type: application/json
@@ -1978,6 +2011,8 @@ URI Parameters
+
+
diff --git a/pkg/api/types.go b/pkg/api/types.go
index e9f480385ffaa..472039889afcb 100644
--- a/pkg/api/types.go
+++ b/pkg/api/types.go
@@ -57,6 +57,7 @@ type EnvVar struct {
// Container represents a single container that is expected to be run on the host.
type Container struct {
+ ID string `yaml:"id,omitempty" json:"id,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Image string `yaml:"image,omitempty" json:"image,omitempty"`
Command []string `yaml:"command,omitempty" json:"command,omitempty"`
diff --git a/pkg/registry/pod_registry.go b/pkg/registry/pod_registry.go
index 06b0c4ae79e6f..fe5ba87aea88f 100644
--- a/pkg/registry/pod_registry.go
+++ b/pkg/registry/pod_registry.go
@@ -20,6 +20,7 @@ import (
"fmt"
"strings"
+ "code.google.com/p/go-uuid/uuid"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
@@ -143,7 +144,12 @@ func (storage *PodRegistryStorage) Extract(body []byte) (interface{}, error) {
func (storage *PodRegistryStorage) Create(pod interface{}) (<-chan interface{}, error) {
podObj := pod.(api.Pod)
if len(podObj.ID) == 0 {
- return nil, fmt.Errorf("id is unspecified: %#v", pod)
+ return nil, fmt.Errorf("id is unspecified: %#v", podObj)
+ }
+ for i := range podObj.DesiredState.Manifest.Containers {
+ if len(podObj.DesiredState.Manifest.Containers[i].ID) == 0 {
+ podObj.DesiredState.Manifest.Containers[i].ID = uuid.NewUUID().String()
+ }
}
machine, err := storage.scheduler.Schedule(podObj)
if err != nil {
diff --git a/pkg/registry/pod_registry_test.go b/pkg/registry/pod_registry_test.go
index e2e06f42cadd3..202a5eea71111 100644
--- a/pkg/registry/pod_registry_test.go
+++ b/pkg/registry/pod_registry_test.go
@@ -19,6 +19,7 @@ package registry
import (
"fmt"
"reflect"
+ "strings"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
@@ -32,6 +33,55 @@ func expectNoError(t *testing.T, err error) {
}
}
+func TestCreatePodIdError(t *testing.T) {
+ storage := PodRegistryStorage{
+ registry: &MockPodRegistry{},
+ }
+ pod := api.Pod{}
+ _, err := storage.Create(pod)
+ if !strings.HasPrefix(err.Error(), "id is unspecified: ") {
+ t.Errorf("Expected id is unspecified error, Got %#v", err)
+ }
+}
+
+type MockScheduler struct {
+ err error
+ pod api.Pod
+}
+
+func (m *MockScheduler) Schedule(pod api.Pod) (string, error) {
+ m.pod = pod
+ return "", m.err
+}
+
+func TestCreatePodContainerIdError(t *testing.T) {
+ mockScheduler := MockScheduler{
+ err: fmt.Errorf("test error"),
+ }
+ storage := PodRegistryStorage{
+ scheduler: &mockScheduler,
+ }
+ pod := api.Pod{
+ JSONBase: api.JSONBase{
+ ID: "test",
+ },
+ DesiredState: api.PodState{
+ Manifest: api.ContainerManifest{
+ Containers: []api.Container{
+ api.Container{},
+ },
+ },
+ },
+ }
+ _, err := storage.Create(pod)
+ if err != mockScheduler.err {
+ t.Errorf("Expected %#v, Got %#v", mockScheduler.err, err)
+ }
+ if len(mockScheduler.pod.DesiredState.Manifest.Containers[0].ID) == 0 {
+ t.Errorf("Expected container[0] to have ID set, Got %#v", mockScheduler.pod)
+ }
+}
+
func TestListPodsError(t *testing.T) {
mockRegistry := MockPodRegistry{
err: fmt.Errorf("test error"),
diff --git a/third_party/deps.sh b/third_party/deps.sh
index 5f63f14c5d9cd..1b2c9a5b1dd35 100755
--- a/third_party/deps.sh
+++ b/third_party/deps.sh
@@ -4,6 +4,7 @@ TOP_PACKAGES="
github.com/golang/glog
code.google.com/p/goauth2/compute/serviceaccount
code.google.com/p/goauth2/oauth
+ code.google.com/p/go-uuid/uuid
code.google.com/p/google-api-go-client/compute/v1
"