mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +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:
@@ -22,7 +22,6 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash/adler32"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -92,7 +91,9 @@ func (s *sourceURL) extractFromURL() error {
|
||||
return singleErr
|
||||
}
|
||||
// It parsed!
|
||||
applyDefaults(&pod, s.url)
|
||||
if err = applyDefaults(&pod, s.url); err != nil {
|
||||
return err
|
||||
}
|
||||
s.updates <- kubelet.PodUpdate{[]api.BoundPod{pod}, kubelet.SET, kubelet.HTTPSource}
|
||||
return nil
|
||||
}
|
||||
@@ -114,7 +115,9 @@ func (s *sourceURL) extractFromURL() error {
|
||||
// Assume it parsed.
|
||||
for i := range pods.Items {
|
||||
pod := &pods.Items[i]
|
||||
applyDefaults(pod, s.url)
|
||||
if err = applyDefaults(pod, s.url); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.updates <- kubelet.PodUpdate{pods.Items, kubelet.SET, kubelet.HTTPSource}
|
||||
return nil
|
||||
@@ -180,7 +183,7 @@ func tryDecodeList(data []byte) (parsed bool, manifests []v1beta1.ContainerManif
|
||||
return true, manifests, pods, nil
|
||||
}
|
||||
|
||||
func applyDefaults(pod *api.BoundPod, url string) {
|
||||
func applyDefaults(pod *api.BoundPod, url string) error {
|
||||
if len(pod.UID) == 0 {
|
||||
hasher := md5.New()
|
||||
fmt.Fprintf(hasher, "url:%s", url)
|
||||
@@ -190,14 +193,18 @@ func applyDefaults(pod *api.BoundPod, url string) {
|
||||
}
|
||||
// This is required for backward compatibility, and should be removed once we
|
||||
// completely deprecate ContainerManifest.
|
||||
var err error
|
||||
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)
|
||||
pod.Namespace = fmt.Sprintf("url-%08x", hasher.Sum32())
|
||||
glog.V(5).Infof("Generated namespace %q for pod %q from URL %s", pod.Namespace, pod.Name, url)
|
||||
pod.Name, err = GeneratePodName(pod.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
glog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, url)
|
||||
|
||||
// Always overrides the namespace.
|
||||
pod.Namespace = kubelet.NamespaceDefault
|
||||
glog.V(5).Infof("Using namespace %q for pod %q from URL %s", pod.Namespace, pod.Name, url)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user