From 1be3de895c34f03e57455e9841d792931cc1113d Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Wed, 14 Jan 2015 15:22:21 -0800 Subject: [PATCH] Move util.UID to pkg/types --- pkg/api/meta/interfaces.go | 10 ++++----- pkg/api/meta/meta.go | 12 +++++----- pkg/api/types.go | 17 +++++++------- pkg/api/v1beta1/types.go | 17 +++++++------- pkg/api/v1beta2/types.go | 17 +++++++------- pkg/api/v1beta3/types.go | 17 +++++++------- pkg/health/exec.go | 6 ++--- pkg/health/exec_test.go | 4 ++-- pkg/health/health.go | 6 ++--- pkg/health/http.go | 3 ++- pkg/health/tcp.go | 3 ++- pkg/kubelet/cadvisor.go | 4 ++-- pkg/kubelet/config/config_test.go | 4 ++-- pkg/kubelet/config/file.go | 3 ++- pkg/kubelet/config/file_test.go | 6 ++--- pkg/kubelet/config/http.go | 3 ++- pkg/kubelet/dockertools/docker.go | 13 ++++++----- pkg/kubelet/dockertools/docker_test.go | 3 ++- pkg/kubelet/handlers.go | 5 +++-- pkg/kubelet/kubelet.go | 31 +++++++++++++------------- pkg/kubelet/kubelet_test.go | 3 ++- pkg/kubelet/server.go | 16 ++++++------- pkg/kubelet/server_test.go | 20 ++++++++--------- pkg/types/doc.go | 18 +++++++++++++++ pkg/types/uid.go | 22 ++++++++++++++++++ pkg/util/uuid.go | 10 +++------ 26 files changed, 161 insertions(+), 112 deletions(-) create mode 100644 pkg/types/doc.go create mode 100644 pkg/types/uid.go diff --git a/pkg/api/meta/interfaces.go b/pkg/api/meta/interfaces.go index f5f6a0fe888..02c8ab512fb 100644 --- a/pkg/api/meta/interfaces.go +++ b/pkg/api/meta/interfaces.go @@ -18,7 +18,7 @@ package meta import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" ) // VersionInterfaces contains the interfaces one should use for dealing with types of a particular version. @@ -37,8 +37,8 @@ type Interface interface { SetNamespace(namespace string) Name() string SetName(name string) - UID() util.UID - SetUID(uid util.UID) + UID() types.UID + SetUID(uid types.UID) APIVersion() string SetAPIVersion(version string) Kind() string @@ -72,8 +72,8 @@ type MetadataAccessor interface { Name(obj runtime.Object) (string, error) SetName(obj runtime.Object, name string) error - UID(obj runtime.Object) (util.UID, error) - SetUID(obj runtime.Object, uid util.UID) error + UID(obj runtime.Object) (types.UID, error) + SetUID(obj runtime.Object, uid types.UID) error SelfLink(obj runtime.Object) (string, error) SetSelfLink(obj runtime.Object, selfLink string) error diff --git a/pkg/api/meta/meta.go b/pkg/api/meta/meta.go index b9800e2d7d7..b16e3a192e7 100644 --- a/pkg/api/meta/meta.go +++ b/pkg/api/meta/meta.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" ) // Accessor takes an arbitary object pointer and returns meta.Interface. @@ -152,7 +152,7 @@ func (resourceAccessor) SetName(obj runtime.Object, name string) error { return nil } -func (resourceAccessor) UID(obj runtime.Object) (util.UID, error) { +func (resourceAccessor) UID(obj runtime.Object) (types.UID, error) { accessor, err := Accessor(obj) if err != nil { return "", err @@ -160,7 +160,7 @@ func (resourceAccessor) UID(obj runtime.Object) (util.UID, error) { return accessor.UID(), nil } -func (resourceAccessor) SetUID(obj runtime.Object, uid util.UID) error { +func (resourceAccessor) SetUID(obj runtime.Object, uid types.UID) error { accessor, err := Accessor(obj) if err != nil { return err @@ -242,7 +242,7 @@ func (resourceAccessor) SetResourceVersion(obj runtime.Object, version string) e type genericAccessor struct { namespace *string name *string - uid *util.UID + uid *types.UID apiVersion *string kind *string resourceVersion *string @@ -279,14 +279,14 @@ func (a genericAccessor) SetName(name string) { *a.name = name } -func (a genericAccessor) UID() util.UID { +func (a genericAccessor) UID() types.UID { if a.uid == nil { return "" } return *a.uid } -func (a genericAccessor) SetUID(uid util.UID) { +func (a genericAccessor) SetUID(uid types.UID) { if a.uid == nil { return } diff --git a/pkg/api/types.go b/pkg/api/types.go index 4372d0d444c..730c9646063 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -19,6 +19,7 @@ package api import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -93,7 +94,7 @@ type ObjectMeta struct { // UID is the unique in time and space value for this object. It is typically generated by // the server on successful creation of a resource and is not allowed to change on PUT // operations. - UID util.UID `json:"uid,omitempty"` + UID types.UID `json:"uid,omitempty"` // An opaque value that represents the version of this resource. May be used for optimistic // concurrency, change detection, and the watch operation on a resource or set of resources. @@ -1004,12 +1005,12 @@ type OperationList struct { // ObjectReference contains enough information to let you inspect or modify the referred object. type ObjectReference struct { - Kind string `json:"kind,omitempty"` - Namespace string `json:"namespace,omitempty"` - Name string `json:"name,omitempty"` - UID util.UID `json:"uid,omitempty"` - APIVersion string `json:"apiVersion,omitempty"` - ResourceVersion string `json:"resourceVersion,omitempty"` + Kind string `json:"kind,omitempty"` + Namespace string `json:"namespace,omitempty"` + Name string `json:"name,omitempty"` + UID types.UID `json:"uid,omitempty"` + APIVersion string `json:"apiVersion,omitempty"` + ResourceVersion string `json:"resourceVersion,omitempty"` // Optional. If referring to a piece of an object instead of an entire object, this string // should contain information to identify the sub-object. For example, if the object @@ -1076,7 +1077,7 @@ type ContainerManifest struct { // TODO: UUID on Manifest is deprecated in the future once we are done // with the API refactoring. It is required for now to determine the instance // of a Pod. - UUID util.UID `json:"uuid,omitempty"` + UUID types.UID `json:"uuid,omitempty"` Volumes []Volume `json:"volumes"` Containers []Container `json:"containers"` RestartPolicy RestartPolicy `json:"restartPolicy,omitempty"` diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index 24ab81c070c..0a8c4875a5c 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -18,6 +18,7 @@ package v1beta1 import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -56,7 +57,7 @@ type ContainerManifest struct { // TODO: UUID on Manifext is deprecated in the future once we are done // with the API refactory. It is required for now to determine the instance // of a Pod. - UUID util.UID `json:"uuid,omitempty" description:"manifest UUID"` + UUID types.UID `json:"uuid,omitempty" description:"manifest UUID"` Volumes []Volume `json:"volumes" description:"list of volumes that can be mounted by containers belonging to the pod"` Containers []Container `json:"containers" description:"list of containers belonging to the pod"` RestartPolicy RestartPolicy `json:"restartPolicy,omitempty" description:"restart policy for all containers within the pod; one of RestartPolicyAlways, RestartPolicyOnFailure, RestartPolicyNever"` @@ -297,7 +298,7 @@ type Lifecycle struct { type TypeMeta struct { Kind string `json:"kind,omitempty" description:"kind of object, in CamelCase"` ID string `json:"id,omitempty" description:"name of the object; must be a DNS_SUBDOMAIN and unique among all objects of the same kind within the same namespace; used in resource URLs"` - UID util.UID `json:"uid,omitempty" description:"UUID assigned by the system upon creation, unique across space and time"` + UID types.UID `json:"uid,omitempty" description:"UUID assigned by the system upon creation, unique across space and time"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" description:"RFC 3339 date and time at which the object was created; recorded by the system; null for lists"` SelfLink string `json:"selfLink,omitempty" description:"URL for the object"` ResourceVersion uint64 `json:"resourceVersion,omitempty" description:"string that identifies the internal version of this object that can be used by clients to determine when objects have changed; value must be treated as opaque by clients and passed unmodified back to the server"` @@ -776,12 +777,12 @@ type ServerOpList struct { // ObjectReference contains enough information to let you inspect or modify the referred object. type ObjectReference struct { - Kind string `json:"kind,omitempty" description:"kind of the referent"` - Namespace string `json:"namespace,omitempty" description:"namespace of the referent"` - ID string `json:"name,omitempty" description:"id of the referent"` - UID util.UID `json:"uid,omitempty" description:"uid of the referent"` - APIVersion string `json:"apiVersion,omitempty" description:"API version of the referent"` - ResourceVersion string `json:"resourceVersion,omitempty" description:"specific resourceVersion to which this reference is made, if any"` + Kind string `json:"kind,omitempty" description:"kind of the referent"` + Namespace string `json:"namespace,omitempty" description:"namespace of the referent"` + ID string `json:"name,omitempty" description:"id of the referent"` + UID types.UID `json:"uid,omitempty" description:"uid of the referent"` + APIVersion string `json:"apiVersion,omitempty" description:"API version of the referent"` + ResourceVersion string `json:"resourceVersion,omitempty" description:"specific resourceVersion to which this reference is made, if any"` // Optional. If referring to a piece of an object instead of an entire object, this string // should contain information to identify the sub-object. For example, if the object diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index e56acd10643..463a78d6f72 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -18,6 +18,7 @@ package v1beta2 import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -260,7 +261,7 @@ type Lifecycle struct { type TypeMeta struct { Kind string `json:"kind,omitempty" description:"kind of object, in CamelCase"` ID string `json:"id,omitempty" description:"name of the object; must be a DNS_SUBDOMAIN and unique among all objects of the same kind within the same namespace; used in resource URLs"` - UID util.UID `json:"uid,omitempty" description:"UUID assigned by the system upon creation, unique across space and time"` + UID types.UID `json:"uid,omitempty" description:"UUID assigned by the system upon creation, unique across space and time"` CreationTimestamp util.Time `json:"creationTimestamp,omitempty" description:"RFC 3339 date and time at which the object was created; recorded by the system; null for lists"` SelfLink string `json:"selfLink,omitempty" description:"URL for the object"` ResourceVersion uint64 `json:"resourceVersion,omitempty" description:"string that identifies the internal version of this object that can be used by clients to determine when objects have changed; value must be treated as opaque by clients and passed unmodified back to the server"` @@ -749,12 +750,12 @@ type ServerOpList struct { // ObjectReference contains enough information to let you inspect or modify the referred object. type ObjectReference struct { - Kind string `json:"kind,omitempty" description:"kind of the referent"` - Namespace string `json:"namespace,omitempty" description:"namespace of the referent"` - ID string `json:"name,omitempty" description:"id of the referent"` - UID util.UID `json:"uid,omitempty" description:"uid of the referent"` - APIVersion string `json:"apiVersion,omitempty" description:"API version of the referent"` - ResourceVersion string `json:"resourceVersion,omitempty" description:"specific resourceVersion to which this reference is made, if any"` + Kind string `json:"kind,omitempty" description:"kind of the referent"` + Namespace string `json:"namespace,omitempty" description:"namespace of the referent"` + ID string `json:"name,omitempty" description:"id of the referent"` + UID types.UID `json:"uid,omitempty" description:"uid of the referent"` + APIVersion string `json:"apiVersion,omitempty" description:"API version of the referent"` + ResourceVersion string `json:"resourceVersion,omitempty" description:"specific resourceVersion to which this reference is made, if any"` // Optional. If referring to a piece of an object instead of an entire object, this string // should contain information to identify the sub-object. For example, if the object @@ -825,7 +826,7 @@ type ContainerManifest struct { // TODO: UUID on Manifext is deprecated in the future once we are done // with the API refactory. It is required for now to determine the instance // of a Pod. - UUID util.UID `json:"uuid,omitempty" description:"manifest UUID"` + UUID types.UID `json:"uuid,omitempty" description:"manifest UUID"` Volumes []Volume `json:"volumes" description:"list of volumes that can be mounted by containers belonging to the pod"` Containers []Container `json:"containers" description:"list of containers belonging to the pod"` RestartPolicy RestartPolicy `json:"restartPolicy,omitempty" description:"restart policy for all containers within the pod; one of RestartPolicyAlways, RestartPolicyOnFailure, RestartPolicyNever"` diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index 4960ec0f273..fbb147455d4 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -19,6 +19,7 @@ package v1beta3 import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -93,7 +94,7 @@ type ObjectMeta struct { // UID is the unique in time and space value for this object. It is typically generated by // the server on successful creation of a resource and is not allowed to change on PUT // operations. - UID util.UID `json:"uid,omitempty"` + UID types.UID `json:"uid,omitempty"` // An opaque value that represents the version of this resource. May be used for optimistic // concurrency, change detection, and the watch operation on a resource or set of resources. @@ -138,7 +139,7 @@ const ( // // TODO: UUID on Manifest is deprecated in the future once we are done // // with the API refactoring. It is required for now to determine the instance // // of a Pod. -// UUID util.UID `json:"uuid,omitempty"` +// UUID types.UID `json:"uuid,omitempty"` // Volumes []Volume `json:"volumes"` // Containers []Container `json:"containers"` // RestartPolicy RestartPolicy `json:"restartPolicy,omitempty"` @@ -995,12 +996,12 @@ type OperationList struct { // ObjectReference contains enough information to let you inspect or modify the referred object. type ObjectReference struct { - Kind string `json:"kind,omitempty"` - Namespace string `json:"namespace,omitempty"` - Name string `json:"name,omitempty"` - UID util.UID `json:"uid,omitempty"` - APIVersion string `json:"apiVersion,omitempty"` - ResourceVersion string `json:"resourceVersion,omitempty"` + Kind string `json:"kind,omitempty"` + Namespace string `json:"namespace,omitempty"` + Name string `json:"name,omitempty"` + UID types.UID `json:"uid,omitempty"` + APIVersion string `json:"apiVersion,omitempty"` + ResourceVersion string `json:"resourceVersion,omitempty"` // Optional. If referring to a piece of an object instead of an entire object, this string // should contain information to identify the sub-object. For example, if the object diff --git a/pkg/health/exec.go b/pkg/health/exec.go index ad06cffe120..9f0ad4434c1 100644 --- a/pkg/health/exec.go +++ b/pkg/health/exec.go @@ -21,14 +21,14 @@ import ( "strings" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/golang/glog" ) const defaultHealthyOutput = "ok" type CommandRunner interface { - RunInContainer(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) + RunInContainer(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error) } type ExecHealthChecker struct { @@ -39,7 +39,7 @@ func NewExecHealthChecker(runner CommandRunner) HealthChecker { return &ExecHealthChecker{runner} } -func (e *ExecHealthChecker) HealthCheck(podFullName string, podUID util.UID, status api.PodStatus, container api.Container) (Status, error) { +func (e *ExecHealthChecker) HealthCheck(podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (Status, error) { if container.LivenessProbe.Exec == nil { return Unknown, fmt.Errorf("missing exec parameters") } diff --git a/pkg/health/exec_test.go b/pkg/health/exec_test.go index 0a7f2be8a5b..a9aa2199c89 100644 --- a/pkg/health/exec_test.go +++ b/pkg/health/exec_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" ) type FakeExec struct { @@ -31,7 +31,7 @@ type FakeExec struct { err error } -func (f *FakeExec) RunInContainer(podFullName string, uid util.UID, container string, cmd []string) ([]byte, error) { +func (f *FakeExec) RunInContainer(podFullName string, uid types.UID, container string, cmd []string) ([]byte, error) { f.cmd = cmd return f.out, f.err } diff --git a/pkg/health/health.go b/pkg/health/health.go index caa694543cf..64233e166ee 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -20,7 +20,7 @@ import ( "sync" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/golang/glog" ) @@ -36,7 +36,7 @@ const ( // HealthChecker defines an abstract interface for checking container health. type HealthChecker interface { - HealthCheck(podFullName string, podUID util.UID, status api.PodStatus, container api.Container) (Status, error) + HealthCheck(podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (Status, error) CanCheck(probe *api.LivenessProbe) bool } @@ -79,7 +79,7 @@ func (m *muxHealthChecker) findCheckerFor(probe *api.LivenessProbe) HealthChecke // HealthCheck delegates the health-checking of the container to one of the bundled implementations. // If there is no health checker that can check container it returns Unknown, nil. -func (m *muxHealthChecker) HealthCheck(podFullName string, podUID util.UID, status api.PodStatus, container api.Container) (Status, error) { +func (m *muxHealthChecker) HealthCheck(podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (Status, error) { checker := m.findCheckerFor(container.LivenessProbe) if checker == nil { glog.Warningf("Failed to find health checker for %s %+v", container.Name, container.LivenessProbe) diff --git a/pkg/health/http.go b/pkg/health/http.go index 67ac1c707de..f5b44793887 100644 --- a/pkg/health/http.go +++ b/pkg/health/http.go @@ -24,6 +24,7 @@ import ( "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" ) @@ -105,7 +106,7 @@ func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) { } // HealthCheck checks if the container is healthy by trying sending HTTP Get requests to the container. -func (h *HTTPHealthChecker) HealthCheck(podFullName string, podUID util.UID, status api.PodStatus, container api.Container) (Status, error) { +func (h *HTTPHealthChecker) HealthCheck(podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (Status, error) { host, port, path, err := getURLParts(status, container) if err != nil { return Unknown, err diff --git a/pkg/health/tcp.go b/pkg/health/tcp.go index 4eec9f19001..039e82d140c 100644 --- a/pkg/health/tcp.go +++ b/pkg/health/tcp.go @@ -22,6 +22,7 @@ import ( "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" ) @@ -74,7 +75,7 @@ func DoTCPCheck(addr string) (Status, error) { return Healthy, nil } -func (t *TCPHealthChecker) HealthCheck(podFullName string, podUID util.UID, status api.PodStatus, container api.Container) (Status, error) { +func (t *TCPHealthChecker) HealthCheck(podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (Status, error) { host, port, err := getTCPAddrParts(status, container) if err != nil { return Unknown, err diff --git a/pkg/kubelet/cadvisor.go b/pkg/kubelet/cadvisor.go index ae24ea2592e..e784be69773 100644 --- a/pkg/kubelet/cadvisor.go +++ b/pkg/kubelet/cadvisor.go @@ -20,7 +20,7 @@ import ( "fmt" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" cadvisor "github.com/google/cadvisor/info" ) @@ -54,7 +54,7 @@ func (kl *Kubelet) statsFromDockerContainer(cc cadvisorInterface, containerId st } // GetContainerInfo returns stats (from Cadvisor) for a container. -func (kl *Kubelet) GetContainerInfo(podFullName string, uid util.UID, containerName string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) { +func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) { cc := kl.GetCadvisorClient() if cc == nil { return nil, nil diff --git a/pkg/kubelet/config/config_test.go b/pkg/kubelet/config/config_test.go index 5f375cca61e..0b9d0450c46 100644 --- a/pkg/kubelet/config/config_test.go +++ b/pkg/kubelet/config/config_test.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" ) const ( @@ -53,7 +53,7 @@ func (s sortedPods) Less(i, j int) bool { func CreateValidPod(name, namespace, source string) api.BoundPod { return api.BoundPod{ ObjectMeta: api.ObjectMeta{ - UID: util.UID(name), // for the purpose of testing, this is unique enough + UID: types.UID(name), // for the purpose of testing, this is unique enough Name: name, Namespace: namespace, Annotations: map[string]string{kubelet.ConfigSourceAnnotationKey: source}, diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index 00c2f3def38..9037a0484f3 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -30,6 +30,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/ghodss/yaml" @@ -164,7 +165,7 @@ func extractFromFile(filename string) (api.BoundPod, error) { fmt.Fprintf(hasher, "host:%s", hostname) fmt.Fprintf(hasher, "file:%s", filename) util.DeepHashObject(hasher, pod) - pod.UID = util.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) + pod.UID = types.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) glog.V(5).Infof("Generated UID %q for pod %q from file %s", pod.UID, pod.Name, filename) } if len(pod.Namespace) == 0 { diff --git a/pkg/kubelet/config/file_test.go b/pkg/kubelet/config/file_test.go index 0b3a5b1ada3..0337526647e 100644 --- a/pkg/kubelet/config/file_test.go +++ b/pkg/kubelet/config/file_test.go @@ -28,13 +28,13 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" ) func ExampleManifestAndPod(id string) (api.ContainerManifest, api.BoundPod) { manifest := api.ContainerManifest{ ID: id, - UUID: util.UID(id), + UUID: types.UID(id), Containers: []api.Container{ { Name: "c" + id, @@ -54,7 +54,7 @@ func ExampleManifestAndPod(id string) (api.ContainerManifest, api.BoundPod) { expectedPod := api.BoundPod{ ObjectMeta: api.ObjectMeta{ Name: id, - UID: util.UID(id), + UID: types.UID(id), }, Spec: api.PodSpec{ Containers: []api.Container{ diff --git a/pkg/kubelet/config/http.go b/pkg/kubelet/config/http.go index c69989ce446..be310bd9bf8 100644 --- a/pkg/kubelet/config/http.go +++ b/pkg/kubelet/config/http.go @@ -30,6 +30,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/ghodss/yaml" @@ -147,7 +148,7 @@ func applyDefaults(pod *api.BoundPod, url string) { hasher := md5.New() fmt.Fprintf(hasher, "url:%s", url) util.DeepHashObject(hasher, pod) - pod.UID = util.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) + pod.UID = types.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) glog.V(5).Infof("Generated UID %q for pod %q from URL %s", pod.UID, pod.Name, url) } if len(pod.Namespace) == 0 { diff --git a/pkg/kubelet/dockertools/docker.go b/pkg/kubelet/dockertools/docker.go index 136a10f76a5..ee6fa0dcb35 100644 --- a/pkg/kubelet/dockertools/docker.go +++ b/pkg/kubelet/dockertools/docker.go @@ -31,6 +31,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" docker "github.com/fsouza/go-dockerclient" "github.com/golang/glog" @@ -254,7 +255,7 @@ func (p throttledDockerPuller) IsImagePresent(name string) (bool, error) { // DockerContainers is a map of containers type DockerContainers map[DockerID]*docker.APIContainers -func (c DockerContainers) FindPodContainer(podFullName string, uid util.UID, containerName string) (*docker.APIContainers, bool, uint64) { +func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64) { for _, dockerContainer := range c { if len(dockerContainer.Names) == 0 { continue @@ -314,7 +315,7 @@ func GetKubeletDockerContainers(client DockerInterface, allContainers bool) (Doc // GetRecentDockerContainersWithNameAndUUID returns a list of dead docker containers which matches the name // and uid given. -func GetRecentDockerContainersWithNameAndUUID(client DockerInterface, podFullName string, uid util.UID, containerName string) ([]*docker.Container, error) { +func GetRecentDockerContainersWithNameAndUUID(client DockerInterface, podFullName string, uid types.UID, containerName string) ([]*docker.Container, error) { var result []*docker.Container containers, err := client.ListContainers(docker.ListContainersOptions{All: true}) if err != nil { @@ -447,7 +448,7 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str } // GetDockerPodInfo returns docker info for all containers in the pod/manifest. -func GetDockerPodInfo(client DockerInterface, manifest api.PodSpec, podFullName string, uid util.UID) (api.PodInfo, error) { +func GetDockerPodInfo(client DockerInterface, manifest api.PodSpec, podFullName string, uid types.UID) (api.PodInfo, error) { info := api.PodInfo{} expectedContainers := make(map[string]api.Container) for _, container := range manifest.Containers { @@ -545,7 +546,7 @@ func HashContainer(container *api.Container) uint64 { } // Creates a name which can be reversed to identify both full pod name and container name. -func BuildDockerName(podUID util.UID, podFullName string, container *api.Container) string { +func BuildDockerName(podUID types.UID, podFullName string, container *api.Container) string { containerName := container.Name + "." + strconv.FormatUint(HashContainer(container), 16) return fmt.Sprintf("%s_%s_%s_%s_%08x", containerNamePrefix, @@ -557,7 +558,7 @@ func BuildDockerName(podUID util.UID, podFullName string, container *api.Contain // Unpacks a container name, returning the pod full name and container name we would have used to // construct the docker name. If the docker name isn't the one we created, we may return empty strings. -func ParseDockerName(name string) (podFullName string, podUID util.UID, containerName string, hash uint64) { +func ParseDockerName(name string) (podFullName string, podUID types.UID, containerName string, hash uint64) { // For some reason docker appears to be appending '/' to names. // If it's there, strip it. if name[0] == '/' { @@ -590,7 +591,7 @@ func ParseDockerName(name string) (podFullName string, podUID util.UID, containe podFullName = parts[2] // Pod UID. - podUID = util.UID(parts[3]) + podUID = types.UID(parts[3]) return } diff --git a/pkg/kubelet/dockertools/docker_test.go b/pkg/kubelet/dockertools/docker_test.go index 539f2f7c1b2..d62a16d7145 100644 --- a/pkg/kubelet/dockertools/docker_test.go +++ b/pkg/kubelet/dockertools/docker_test.go @@ -24,6 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" docker "github.com/fsouza/go-dockerclient" ) @@ -91,7 +92,7 @@ func verifyPackUnpack(t *testing.T, podNamespace, podUID, podName, containerName util.DeepHashObject(hasher, *container) computedHash := uint64(hasher.Sum32()) podFullName := fmt.Sprintf("%s.%s", podName, podNamespace) - name := BuildDockerName(util.UID(podUID), podFullName, container) + name := BuildDockerName(types.UID(podUID), podFullName, container) returnedPodFullName, returnedUID, returnedContainerName, hash := ParseDockerName(name) if podFullName != returnedPodFullName || podUID != string(returnedUID) || containerName != returnedContainerName || computedHash != hash { t.Errorf("For (%s, %s, %s, %d), unpacked (%s, %s, %s, %d)", podFullName, podUID, containerName, computedHash, returnedPodFullName, returnedUID, returnedContainerName, hash) diff --git a/pkg/kubelet/handlers.go b/pkg/kubelet/handlers.go index f8f8e3f07d1..4a20dcfb62f 100644 --- a/pkg/kubelet/handlers.go +++ b/pkg/kubelet/handlers.go @@ -24,6 +24,7 @@ import ( "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" ) @@ -32,7 +33,7 @@ type execActionHandler struct { kubelet *Kubelet } -func (e *execActionHandler) Run(podFullName string, uid util.UID, container *api.Container, handler *api.Handler) error { +func (e *execActionHandler) Run(podFullName string, uid types.UID, container *api.Container, handler *api.Handler) error { _, err := e.kubelet.RunInContainer(podFullName, uid, container.Name, handler.Exec.Command) return err } @@ -67,7 +68,7 @@ func ResolvePort(portReference util.IntOrString, container *api.Container) (int, return -1, fmt.Errorf("couldn't find port: %v in %v", portReference, container) } -func (h *httpActionHandler) Run(podFullName string, uid util.UID, container *api.Container, handler *api.Handler) error { +func (h *httpActionHandler) Run(podFullName string, uid types.UID, container *api.Container, handler *api.Handler) error { host := handler.HTTPGet.Host if len(host) == 0 { var info api.PodInfo diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 1f3c0c1c4e3..ccdafda93fa 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -41,6 +41,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" @@ -205,7 +206,7 @@ func (kl *Kubelet) GetPodsDir() string { // GetPodDir returns the full path to the per-pod data directory for the // specified pod. This directory may not exist if the pod does not exist. -func (kl *Kubelet) GetPodDir(podUID util.UID) string { +func (kl *Kubelet) GetPodDir(podUID types.UID) string { // Backwards compat. The "old" stuff should be removed before 1.0 // release. The thinking here is this: // !old && !new = use new @@ -228,14 +229,14 @@ func (kl *Kubelet) GetPodDir(podUID util.UID) string { // GetPodVolumesDir returns the full path to the per-pod data directory under // which volumes are created for the specified pod. This directory may not // exist if the pod does not exist. -func (kl *Kubelet) GetPodVolumesDir(podUID util.UID) string { +func (kl *Kubelet) GetPodVolumesDir(podUID types.UID) string { return path.Join(kl.GetPodDir(podUID), "volumes") } // GetPodContainerDir returns the full path to the per-pod data directory under // which container data is held for the specified pod. This directory may not // exist if the pod or container does not exist. -func (kl *Kubelet) GetPodContainerDir(podUID util.UID, ctrName string) string { +func (kl *Kubelet) GetPodContainerDir(podUID types.UID, ctrName string) string { // Backwards compat. The "old" stuff should be removed before 1.0 // release. The thinking here is this: // !old && !new = use new @@ -275,15 +276,15 @@ func (kl *Kubelet) setupDataDirs() error { } // Get a list of pods that have data directories. -func (kl *Kubelet) listPodsFromDisk() ([]util.UID, error) { +func (kl *Kubelet) listPodsFromDisk() ([]types.UID, error) { podInfos, err := ioutil.ReadDir(kl.GetPodsDir()) if err != nil { return nil, err } - pods := []util.UID{} + pods := []types.UID{} for i := range podInfos { if podInfos[i].IsDir() { - pods = append(pods, util.UID(podInfos[i].Name())) + pods = append(pods, types.UID(podInfos[i].Name())) } } return pods, nil @@ -527,7 +528,7 @@ func (kl *Kubelet) mountExternalVolumes(pod *api.BoundPod) (volumeMap, error) { // A basic interface that knows how to execute handlers type actionHandler interface { - Run(podFullName string, uid util.UID, container *api.Container, handler *api.Handler) error + Run(podFullName string, uid types.UID, container *api.Container, handler *api.Handler) error } func (kl *Kubelet) newActionHandler(handler *api.Handler) actionHandler { @@ -542,7 +543,7 @@ func (kl *Kubelet) newActionHandler(handler *api.Handler) actionHandler { } } -func (kl *Kubelet) runHandler(podFullName string, uid util.UID, container *api.Container, handler *api.Handler) error { +func (kl *Kubelet) runHandler(podFullName string, uid types.UID, container *api.Container, handler *api.Handler) error { actionHandler := kl.newActionHandler(handler) if actionHandler == nil { return fmt.Errorf("invalid handler") @@ -1134,7 +1135,7 @@ func (kl *Kubelet) syncPod(pod *api.BoundPod, dockerContainers dockertools.Docke type podContainer struct { podFullName string - uid util.UID + uid types.UID containerName string } @@ -1197,7 +1198,7 @@ func (kl *Kubelet) SyncPods(pods []api.BoundPod) error { glog.V(4).Infof("Desired: %#v", pods) var err error desiredContainers := make(map[podContainer]empty) - desiredPods := make(map[util.UID]empty) + desiredPods := make(map[types.UID]empty) dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false) if err != nil { @@ -1268,7 +1269,7 @@ func (kl *Kubelet) SyncPods(pods []api.BoundPod) error { func updateBoundPods(changed []api.BoundPod, current []api.BoundPod) []api.BoundPod { updated := []api.BoundPod{} - m := map[util.UID]*api.BoundPod{} + m := map[types.UID]*api.BoundPod{} for i := range changed { pod := &changed[i] m[pod.UID] = pod @@ -1376,7 +1377,7 @@ func (kl *Kubelet) GetPodByName(namespace, name string) (*api.BoundPod, bool) { } // GetPodInfo returns information from Docker about the containers in a pod -func (kl *Kubelet) GetPodInfo(podFullName string, uid util.UID) (api.PodInfo, error) { +func (kl *Kubelet) GetPodInfo(podFullName string, uid types.UID) (api.PodInfo, error) { var manifest api.PodSpec for _, pod := range kl.pods { if GetPodFullName(&pod) == podFullName { @@ -1387,7 +1388,7 @@ func (kl *Kubelet) GetPodInfo(podFullName string, uid util.UID) (api.PodInfo, er return dockertools.GetDockerPodInfo(kl.dockerClient, manifest, podFullName, uid) } -func (kl *Kubelet) healthy(podFullName string, podUID util.UID, status api.PodStatus, container api.Container, dockerContainer *docker.APIContainers) (health.Status, error) { +func (kl *Kubelet) healthy(podFullName string, podUID types.UID, status api.PodStatus, container api.Container, dockerContainer *docker.APIContainers) (health.Status, error) { // Give the container 60 seconds to start up. if container.LivenessProbe == nil { return health.Healthy, nil @@ -1408,7 +1409,7 @@ func (kl *Kubelet) ServeLogs(w http.ResponseWriter, req *http.Request) { } // Run a command in a container, returns the combined stdout, stderr as an array of bytes -func (kl *Kubelet) RunInContainer(podFullName string, uid util.UID, container string, cmd []string) ([]byte, error) { +func (kl *Kubelet) RunInContainer(podFullName string, uid types.UID, container string, cmd []string) ([]byte, error) { if kl.runner == nil { return nil, fmt.Errorf("no runner specified.") } @@ -1431,7 +1432,7 @@ func (kl *Kubelet) BirthCry() { ref := &api.ObjectReference{ Kind: "Minion", Name: kl.hostname, - UID: util.UID(kl.hostname), + UID: types.UID(kl.hostname), Namespace: api.NamespaceDefault, } record.Eventf(ref, "starting", "Starting kubelet.") diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index ce2101c4a1d..76d53537956 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -33,6 +33,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/health" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/volume" "github.com/fsouza/go-dockerclient" @@ -808,7 +809,7 @@ func TestSyncPodDeletesDuplicate(t *testing.T) { type FalseHealthChecker struct{} -func (f *FalseHealthChecker) HealthCheck(podFullName string, podUID util.UID, status api.PodStatus, container api.Container) (health.Status, error) { +func (f *FalseHealthChecker) HealthCheck(podFullName string, podUID types.UID, status api.PodStatus, container api.Container) (health.Status, error) { return health.Unhealthy, nil } diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index d73026de599..53b540cba69 100644 --- a/pkg/kubelet/server.go +++ b/pkg/kubelet/server.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/healthz" "github.com/GoogleCloudPlatform/kubernetes/pkg/httplog" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/golang/glog" "github.com/google/cadvisor/info" ) @@ -62,13 +62,13 @@ func ListenAndServeKubeletServer(host HostInterface, address net.IP, port uint, // HostInterface contains all the kubelet methods required by the server. // For testablitiy. type HostInterface interface { - GetContainerInfo(podFullName string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) + GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error) GetMachineInfo() (*info.MachineInfo, error) GetBoundPods() ([]api.BoundPod, error) GetPodByName(namespace, name string) (*api.BoundPod, bool) - GetPodInfo(name string, uid util.UID) (api.PodInfo, error) - RunInContainer(name string, uid util.UID, container string, cmd []string) ([]byte, error) + GetPodInfo(name string, uid types.UID) (api.PodInfo, error) + RunInContainer(name string, uid types.UID, container string, cmd []string) ([]byte, error) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error ServeLogs(w http.ResponseWriter, req *http.Request) } @@ -204,7 +204,7 @@ func (s *Server) handlePodInfo(w http.ResponseWriter, req *http.Request, version return } podID := u.Query().Get("podID") - podUID := util.UID(u.Query().Get("UUID")) + podUID := types.UID(u.Query().Get("UUID")) podNamespace := u.Query().Get("podNamespace") if len(podID) == 0 { w.WriteHeader(http.StatusBadRequest) @@ -272,7 +272,7 @@ func (s *Server) handleRun(w http.ResponseWriter, req *http.Request) { } parts := strings.Split(u.Path, "/") var podNamespace, podID, container string - var uid util.UID + var uid types.UID if len(parts) == 5 { podNamespace = parts[2] podID = parts[3] @@ -280,7 +280,7 @@ func (s *Server) handleRun(w http.ResponseWriter, req *http.Request) { } else if len(parts) == 6 { podNamespace = parts[2] podID = parts[3] - uid = util.UID(parts[4]) + uid = types.UID(parts[4]) container = parts[5] } else { http.Error(w, "Unexpected path for command running", http.StatusBadRequest) @@ -348,7 +348,7 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) { http.Error(w, "Pod does not exist", http.StatusNotFound) return } - stats, err = s.host.GetContainerInfo(GetPodFullName(pod), util.UID(components[3]), components[4], &query) + stats, err = s.host.GetContainerInfo(GetPodFullName(pod), types.UID(components[3]), components[4], &query) default: http.Error(w, "unknown resource.", http.StatusNotFound) return diff --git a/pkg/kubelet/server_test.go b/pkg/kubelet/server_test.go index f190c4ba0ed..1af31c1f9a2 100644 --- a/pkg/kubelet/server_test.go +++ b/pkg/kubelet/server_test.go @@ -29,19 +29,19 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" "github.com/google/cadvisor/info" ) type fakeKubelet struct { podByNameFunc func(namespace, name string) (*api.BoundPod, bool) infoFunc func(name string) (api.PodInfo, error) - containerInfoFunc func(podFullName string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) + containerInfoFunc func(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) rootInfoFunc func(query *info.ContainerInfoRequest) (*info.ContainerInfo, error) machineInfoFunc func() (*info.MachineInfo, error) boundPodsFunc func() ([]api.BoundPod, error) logFunc func(w http.ResponseWriter, req *http.Request) - runFunc func(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) + runFunc func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error) containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error } @@ -49,11 +49,11 @@ func (fk *fakeKubelet) GetPodByName(namespace, name string) (*api.BoundPod, bool return fk.podByNameFunc(namespace, name) } -func (fk *fakeKubelet) GetPodInfo(name string, uid util.UID) (api.PodInfo, error) { +func (fk *fakeKubelet) GetPodInfo(name string, uid types.UID) (api.PodInfo, error) { return fk.infoFunc(name) } -func (fk *fakeKubelet) GetContainerInfo(podFullName string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { +func (fk *fakeKubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { return fk.containerInfoFunc(podFullName, uid, containerName, req) } @@ -77,7 +77,7 @@ func (fk *fakeKubelet) GetKubeletContainerLogs(podFullName, containerName, tail return fk.containerLogsFunc(podFullName, containerName, tail, follow, stdout, stderr) } -func (fk *fakeKubelet) RunInContainer(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) { +func (fk *fakeKubelet) RunInContainer(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error) { return fk.runFunc(podFullName, uid, containerName, cmd) } @@ -162,7 +162,7 @@ func TestContainerInfo(t *testing.T) { podID := "somepod" expectedPodID := "somepod" + ".default.etcd" expectedContainerName := "goodcontainer" - fw.fakeKubelet.containerInfoFunc = func(podID string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { + fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { if podID != expectedPodID || containerName != expectedContainerName { return nil, fmt.Errorf("bad podID or containerName: podID=%v; containerName=%v", podID, containerName) } @@ -192,7 +192,7 @@ func TestContainerInfoWithUidNamespace(t *testing.T) { expectedPodID := "somepod" + "." + expectedNamespace + ".etcd" expectedContainerName := "goodcontainer" expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647" - fw.fakeKubelet.containerInfoFunc = func(podID string, uid util.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { + fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) { if podID != expectedPodID || string(uid) != expectedUid || containerName != expectedContainerName { return nil, fmt.Errorf("bad podID or uid or containerName: podID=%v; uid=%v; containerName=%v", podID, uid, containerName) } @@ -297,7 +297,7 @@ func TestServeRunInContainer(t *testing.T) { expectedPodName := podName + "." + podNamespace + ".etcd" expectedContainerName := "baz" expectedCommand := "ls -a" - fw.fakeKubelet.runFunc = func(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) { + fw.fakeKubelet.runFunc = func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error) { if podFullName != expectedPodName { t.Errorf("expected %s, got %s", expectedPodName, podFullName) } @@ -338,7 +338,7 @@ func TestServeRunInContainerWithUID(t *testing.T) { expectedUID := "7e00838d_-_3523_-_11e4_-_8421_-_42010af0a720" expectedContainerName := "baz" expectedCommand := "ls -a" - fw.fakeKubelet.runFunc = func(podFullName string, uid util.UID, containerName string, cmd []string) ([]byte, error) { + fw.fakeKubelet.runFunc = func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error) { if podFullName != expectedPodName { t.Errorf("expected %s, got %s", expectedPodName, podFullName) } diff --git a/pkg/types/doc.go b/pkg/types/doc.go new file mode 100644 index 00000000000..8fc2e325e7a --- /dev/null +++ b/pkg/types/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package types implements various generic types used throughout kubernetes. +package types diff --git a/pkg/types/uid.go b/pkg/types/uid.go new file mode 100644 index 00000000000..63e9a92bcb4 --- /dev/null +++ b/pkg/types/uid.go @@ -0,0 +1,22 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +// UID is a type that holds unique ID values, including UUIDs. Because we +// don't ONLY use UUIDs, this is an alias to string. Being a type captures +// intent and helps make sure that UIDs and names do not get conflated. +type UID string diff --git a/pkg/util/uuid.go b/pkg/util/uuid.go index 542118d2746..ffc6aaa046f 100644 --- a/pkg/util/uuid.go +++ b/pkg/util/uuid.go @@ -21,13 +21,9 @@ import ( "time" "code.google.com/p/go-uuid/uuid" + "github.com/GoogleCloudPlatform/kubernetes/pkg/types" ) -// UID is a type that holds unique ID values, including UUIDs. Because we -// don't ONLY use UUIDs, this is an alias to string. Being a type captures -// intent and helps make sure that UIDs and names do not get conflated. -type UID string - var uuidLock sync.Mutex /** @@ -36,12 +32,12 @@ var uuidLock sync.Mutex * Blocks in a go routine, so that the caller doesn't have to wait. * TODO: save old unused UUIDs so that no one has to block. */ -func NewUUID() UID { +func NewUUID() types.UID { uuidLock.Lock() result := uuid.NewUUID() go func() { time.Sleep(200 * time.Nanosecond) uuidLock.Unlock() }() - return UID(result.String()) + return types.UID(result.String()) }