mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
kubelet: revamp the pod/container naming scheme
There are two main goals for this change.
1. Fix the naming scheme in kubelet so that it accepts DNS subdomain
name/namespaces correctly (#4920). The design is discussed in #3453.
2. Prepare for syncing the static pods back to the apiserver(#4090). This
includes
- Eliminate the source component in the internal full pod name (#4922). Pods
no longer need sources as they will all be sync'd via apiserver.
- Changing the naming scheme for the static (file-, http-, and etcd-based)
pods such that they are distinguishable when syncing back to the apiserver.
The changes includes:
* name = <pod.Name>-<hostname>
* namespace = <cluster_namespace> (i.e. "default" for now).
* container_name = k8s_<contianer_name>.<hash_of_container>_<pod_name>_<namespace>_<uid>_<random>
Note that this is not backward-compatible, meaning the kubelet won't recognize
existing running containers using the old naming scheme.
This commit is contained in:
@@ -54,8 +54,9 @@ func ExampleManifestAndPod(id string) (v1beta1.ContainerManifest, api.BoundPod)
|
||||
}
|
||||
expectedPod := api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: id,
|
||||
UID: types.UID(id),
|
||||
Name: id,
|
||||
UID: types.UID(id),
|
||||
Namespace: kubelet.NamespaceDefault,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
@@ -131,27 +132,30 @@ func TestReadFromFile(t *testing.T) {
|
||||
update := got.(kubelet.PodUpdate)
|
||||
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "test",
|
||||
Name: "",
|
||||
UID: "12345",
|
||||
Namespace: "",
|
||||
Namespace: kubelet.NamespaceDefault,
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{Containers: []api.Container{{Image: "test/image"}}},
|
||||
})
|
||||
|
||||
if !strings.HasPrefix(update.Pods[0].Name, "test-") {
|
||||
t.Errorf("Unexpected name: %s", update.Pods[0].Name)
|
||||
}
|
||||
// There's no way to provide namespace in ContainerManifest, so
|
||||
// it will be defaulted.
|
||||
if !strings.HasPrefix(update.Pods[0].ObjectMeta.Namespace, "file-") {
|
||||
t.Errorf("Unexpected namespace: %s", update.Pods[0].ObjectMeta.Namespace)
|
||||
if update.Pods[0].Namespace != kubelet.NamespaceDefault {
|
||||
t.Errorf("Unexpected namespace: %s", update.Pods[0].Namespace)
|
||||
}
|
||||
update.Pods[0].ObjectMeta.Namespace = ""
|
||||
|
||||
// SelfLink depends on namespace.
|
||||
if !strings.HasPrefix(update.Pods[0].ObjectMeta.SelfLink, "/api/") {
|
||||
t.Errorf("Unexpected selflink: %s", update.Pods[0].ObjectMeta.SelfLink)
|
||||
if !strings.HasPrefix(update.Pods[0].SelfLink, "/api/") {
|
||||
t.Errorf("Unexpected selflink: %s", update.Pods[0].SelfLink)
|
||||
}
|
||||
update.Pods[0].ObjectMeta.SelfLink = ""
|
||||
|
||||
// Reset the fileds that we don't want to compare.
|
||||
update.Pods[0].Name = ""
|
||||
update.Pods[0].SelfLink = ""
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
@@ -179,7 +183,7 @@ func TestReadFromFileWithoutID(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "",
|
||||
UID: "12345",
|
||||
Namespace: "",
|
||||
Namespace: kubelet.NamespaceDefault,
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{Containers: []api.Container{{Image: "test/image"}}},
|
||||
@@ -188,10 +192,9 @@ func TestReadFromFileWithoutID(t *testing.T) {
|
||||
if len(update.Pods[0].ObjectMeta.Name) == 0 {
|
||||
t.Errorf("Name did not get defaulted")
|
||||
}
|
||||
update.Pods[0].ObjectMeta.Name = ""
|
||||
update.Pods[0].ObjectMeta.Namespace = ""
|
||||
update.Pods[0].ObjectMeta.SelfLink = ""
|
||||
|
||||
// Reset the fileds that we don't want to compare.
|
||||
update.Pods[0].Name = ""
|
||||
update.Pods[0].SelfLink = ""
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
@@ -218,17 +221,17 @@ func TestReadV1Beta2FromFile(t *testing.T) {
|
||||
update := got.(kubelet.PodUpdate)
|
||||
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, api.BoundPod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "test",
|
||||
Name: "",
|
||||
UID: "12345",
|
||||
Namespace: "",
|
||||
Namespace: kubelet.NamespaceDefault,
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{Containers: []api.Container{{Image: "test/image"}}},
|
||||
})
|
||||
|
||||
update.Pods[0].ObjectMeta.Namespace = ""
|
||||
update.Pods[0].ObjectMeta.SelfLink = ""
|
||||
|
||||
// Reset the fileds that we don't want to compare.
|
||||
update.Pods[0].Name = ""
|
||||
update.Pods[0].SelfLink = ""
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
@@ -252,8 +255,8 @@ func TestReadFromFileWithDefaults(t *testing.T) {
|
||||
select {
|
||||
case got := <-ch:
|
||||
update := got.(kubelet.PodUpdate)
|
||||
if update.Pods[0].ObjectMeta.UID == "" {
|
||||
t.Errorf("Unexpected UID: %s", update.Pods[0].ObjectMeta.UID)
|
||||
if update.Pods[0].UID == "" {
|
||||
t.Errorf("Unexpected UID: %s", update.Pods[0].UID)
|
||||
}
|
||||
|
||||
case <-time.After(time.Second):
|
||||
@@ -337,12 +340,16 @@ func TestExtractFromDir(t *testing.T) {
|
||||
|
||||
update := (<-ch).(kubelet.PodUpdate)
|
||||
for i := range update.Pods {
|
||||
update.Pods[i].Namespace = "foobar"
|
||||
// Pod name is generated with hash and is unique. Skip the comparision
|
||||
// here by setting it to a simple value.
|
||||
update.Pods[i].Name = manifests[i].ID
|
||||
update.Pods[i].SelfLink = ""
|
||||
}
|
||||
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource, pods...)
|
||||
for i := range expected.Pods {
|
||||
expected.Pods[i].Namespace = "foobar"
|
||||
// Pod name is generated with hash and is unique. Skip the comparision
|
||||
// here by setting it to a simple value.
|
||||
expected.Pods[i].Name = manifests[i].ID
|
||||
}
|
||||
sort.Sort(sortedPods(update.Pods))
|
||||
sort.Sort(sortedPods(expected.Pods))
|
||||
@@ -351,7 +358,7 @@ func TestExtractFromDir(t *testing.T) {
|
||||
}
|
||||
for i := range update.Pods {
|
||||
if errs := validation.ValidateBoundPod(&update.Pods[i]); len(errs) != 0 {
|
||||
t.Errorf("Expected no validation errors on %#v, Got %#v", update.Pods[i], errs)
|
||||
t.Errorf("Expected no validation errors on %#v, Got %q", update.Pods[i], errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user