mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Merge pull request #3242 from thockin/name_is_required
Never set pod.Name in kubelet config code
This commit is contained in:
commit
2c25ca229f
@ -19,7 +19,6 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -93,10 +92,7 @@ func eventToPods(ev watch.Event) ([]api.BoundPod, error) {
|
|||||||
return pods, errors.New("unable to parse response as BoundPods")
|
return pods, errors.New("unable to parse response as BoundPods")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, pod := range boundPods.Items {
|
for _, pod := range boundPods.Items {
|
||||||
if len(pod.Name) == 0 {
|
|
||||||
pod.Name = fmt.Sprintf("%d", i+1)
|
|
||||||
}
|
|
||||||
// TODO: generate random UID if not present
|
// TODO: generate random UID if not present
|
||||||
if pod.UID == "" && !pod.CreationTimestamp.IsZero() {
|
if pod.UID == "" && !pod.CreationTimestamp.IsZero() {
|
||||||
pod.UID = strconv.FormatInt(pod.CreationTimestamp.Unix(), 10)
|
pod.UID = strconv.FormatInt(pod.CreationTimestamp.Unix(), 10)
|
||||||
|
@ -153,7 +153,6 @@ func extractFromFile(filename string) (api.BoundPod, error) {
|
|||||||
return pod, fmt.Errorf("can't convert pod from file %q: %v", filename, err)
|
return pod, fmt.Errorf("can't convert pod from file %q: %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.Name = simpleSubdomainSafeHash(filename)
|
|
||||||
if len(pod.UID) == 0 {
|
if len(pod.UID) == 0 {
|
||||||
pod.UID = simpleSubdomainSafeHash(filename)
|
pod.UID = simpleSubdomainSafeHash(filename)
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ func TestReadFromFile(t *testing.T) {
|
|||||||
update := got.(kubelet.PodUpdate)
|
update := got.(kubelet.PodUpdate)
|
||||||
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, api.BoundPod{
|
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, api.BoundPod{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: simpleSubdomainSafeHash(file.Name()),
|
Name: "test",
|
||||||
UID: simpleSubdomainSafeHash(file.Name()),
|
UID: simpleSubdomainSafeHash(file.Name()),
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
},
|
},
|
||||||
@ -161,8 +161,6 @@ func TestExtractFromValidDataFile(t *testing.T) {
|
|||||||
file := writeTestFile(t, os.TempDir(), "test_pod_config", string(text))
|
file := writeTestFile(t, os.TempDir(), "test_pod_config", string(text))
|
||||||
defer os.Remove(file.Name())
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
expectedPod.Name = simpleSubdomainSafeHash(file.Name())
|
|
||||||
|
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
c := sourceFile{file.Name(), ch}
|
c := sourceFile{file.Name(), ch}
|
||||||
err = c.extractFromPath()
|
err = c.extractFromPath()
|
||||||
@ -228,7 +226,6 @@ func TestExtractFromDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ioutil.WriteFile(name, data, 0755)
|
ioutil.WriteFile(name, data, 0755)
|
||||||
files[i] = file
|
files[i] = file
|
||||||
pods[i].Name = simpleSubdomainSafeHash(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
|
@ -91,9 +91,6 @@ func (s *sourceURL) extractFromURL() error {
|
|||||||
if err := api.Scheme.Convert(&manifest, &pod); err != nil {
|
if err := api.Scheme.Convert(&manifest, &pod); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(pod.Name) == 0 {
|
|
||||||
pod.Name = "1"
|
|
||||||
}
|
|
||||||
if len(pod.Namespace) == 0 {
|
if len(pod.Namespace) == 0 {
|
||||||
pod.Namespace = api.NamespaceDefault
|
pod.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user