Skip to content

Commit

Permalink
Generate pod.Name when pod.Name == "" for both HTTP and file sources.
Browse files Browse the repository at this point in the history
Fix kubernetes#3584

# *** ERROR: *** docs are out of sync between cli and markdown
# run hack/run-gendocs.sh > docs/kubectl.md to regenerate

#
# Your commit will be aborted unless you regenerate docs.
    COMMIT_BLOCKED_ON_GENDOCS
  • Loading branch information
dchen1107 authored and zmerlynn committed Jan 23, 2015
1 parent af53d24 commit 5948b24
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/kubelet/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ func extractFromFile(filename string) (api.BoundPod, error) {
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)
}
// This is required for backward compatibility, and should be removed once we
// completely deprecate ContainerManifest.
if len(pod.Name) == 0 {
pod.Name = string(pod.UID)
glog.V(5).Infof("Generated Name %q for UID %q from file %s", pod.Name, pod.UID, filename)
}
if len(pod.Namespace) == 0 {
hasher := adler32.New()
fmt.Fprint(hasher, filename)
Expand Down
6 changes: 6 additions & 0 deletions pkg/kubelet/config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ func applyDefaults(pod *api.BoundPod, url string) {
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)
}
// This is required for backward compatibility, and should be removed once we
// completely deprecate ContainerManifest.
if len(pod.Name) == 0 {
pod.Name = string(pod.UID)
glog.V(5).Infof("Generate Name %q from UID %q from URL %s", pod.Name, pod.UID, url)
}
if len(pod.Namespace) == 0 {
hasher := adler32.New()
fmt.Fprint(hasher, url)
Expand Down
17 changes: 17 additions & 0 deletions pkg/kubelet/config/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ func TestExtractFromHTTP(t *testing.T) {
},
}),
},
{
desc: "Single manifest without ID",
manifests: api.ContainerManifest{Version: "v1beta1", UUID: "111"},
expected: CreatePodUpdate(kubelet.SET,
kubelet.HTTPSource,
api.BoundPod{
ObjectMeta: api.ObjectMeta{
UID: "111",
Name: "111",
Namespace: "foobar",
},
Spec: api.PodSpec{
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst,
},
}),
},
{
desc: "Multiple manifests",
manifests: []api.ContainerManifest{
Expand Down

0 comments on commit 5948b24

Please sign in to comment.