Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stores hash of pod manifest in mirror pod's annotation #15983

Merged
merged 1 commit into from Oct 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/kubelet/config/common.go
Expand Up @@ -64,6 +64,12 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName string) er
pod.Spec.NodeName = nodeName

pod.ObjectMeta.SelfLink = getSelfLink(pod.Name, pod.Namespace)

if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
}
// The generated UID is the hash of the file.
pod.Annotations[kubetypes.ConfigHashAnnotationKey] = string(pod.UID)
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/kubelet/config/file_test.go
Expand Up @@ -96,10 +96,11 @@ func TestReadPodsFromFile(t *testing.T) {
},
expected: CreatePodUpdate(kubetypes.SET, kubetypes.FileSource, &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "test-" + hostname,
UID: "12345",
Namespace: "mynamespace",
SelfLink: getSelfLink("test-"+hostname, "mynamespace"),
Name: "test-" + hostname,
UID: "12345",
Namespace: "mynamespace",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "12345"},
SelfLink: getSelfLink("test-"+hostname, "mynamespace"),
},
Spec: api.PodSpec{
NodeName: hostname,
Expand Down
30 changes: 15 additions & 15 deletions pkg/kubelet/config/http_test.go
Expand Up @@ -152,11 +152,11 @@ func TestExtractPodsFromHTTP(t *testing.T) {
kubetypes.HTTPSource,
&api.Pod{
ObjectMeta: api.ObjectMeta{
UID: "111",
Name: "foo" + "-" + hostname,
Namespace: "mynamespace",

SelfLink: getSelfLink("foo-"+hostname, "mynamespace"),
UID: "111",
Name: "foo" + "-" + hostname,
Namespace: "mynamespace",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
SelfLink: getSelfLink("foo-"+hostname, "mynamespace"),
},
Spec: api.PodSpec{
NodeName: hostname,
Expand Down Expand Up @@ -210,11 +210,11 @@ func TestExtractPodsFromHTTP(t *testing.T) {
kubetypes.HTTPSource,
&api.Pod{
ObjectMeta: api.ObjectMeta{
UID: "111",
Name: "foo" + "-" + hostname,
Namespace: "default",

SelfLink: getSelfLink("foo-"+hostname, kubetypes.NamespaceDefault),
UID: "111",
Name: "foo" + "-" + hostname,
Namespace: "default",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "111"},
SelfLink: getSelfLink("foo-"+hostname, kubetypes.NamespaceDefault),
},
Spec: api.PodSpec{
NodeName: hostname,
Expand All @@ -233,11 +233,11 @@ func TestExtractPodsFromHTTP(t *testing.T) {
},
&api.Pod{
ObjectMeta: api.ObjectMeta{
UID: "222",
Name: "bar" + "-" + hostname,
Namespace: "default",

SelfLink: getSelfLink("bar-"+hostname, kubetypes.NamespaceDefault),
UID: "222",
Name: "bar" + "-" + hostname,
Namespace: "default",
Annotations: map[string]string{kubetypes.ConfigHashAnnotationKey: "222"},
SelfLink: getSelfLink("bar-"+hostname, kubetypes.NamespaceDefault),
},
Spec: api.PodSpec{
NodeName: hostname,
Expand Down
6 changes: 5 additions & 1 deletion pkg/kubelet/pod/manager.go
Expand Up @@ -234,7 +234,11 @@ func (pm *basicManager) IsMirrorPodOf(mirrorPod, pod *api.Pod) bool {
if pod.Name != mirrorPod.Name || pod.Namespace != mirrorPod.Namespace {
return false
}
return api.Semantic.DeepEqual(&pod.Spec, &mirrorPod.Spec)
hash, ok := getHashFromMirrorPod(mirrorPod)
if !ok {
return false
}
return hash == getPodHash(pod)
}

func podsMapToPods(UIDMap map[types.UID]*api.Pod) []*api.Pod {
Expand Down
19 changes: 13 additions & 6 deletions pkg/kubelet/pod/mirror_client.go
Expand Up @@ -52,7 +52,7 @@ func (mc *basicMirrorClient) CreateMirrorPod(pod *api.Pod) error {
for k, v := range pod.Annotations {
copyPod.Annotations[k] = v
}
copyPod.Annotations[kubetypes.ConfigMirrorAnnotationKey] = kubetypes.MirrorType
copyPod.Annotations[kubetypes.ConfigMirrorAnnotationKey] = getPodHash(pod)

_, err := mc.apiserverClient.Pods(copyPod.Namespace).Create(&copyPod)
return err
Expand Down Expand Up @@ -81,9 +81,16 @@ func IsStaticPod(pod *api.Pod) bool {
}

func IsMirrorPod(pod *api.Pod) bool {
if value, ok := pod.Annotations[kubetypes.ConfigMirrorAnnotationKey]; !ok {
return false
} else {
return value == kubetypes.MirrorType
}
_, ok := pod.Annotations[kubetypes.ConfigMirrorAnnotationKey]
return ok
}

func getHashFromMirrorPod(pod *api.Pod) (string, bool) {
hash, ok := pod.Annotations[kubetypes.ConfigMirrorAnnotationKey]
return hash, ok
}

func getPodHash(pod *api.Pod) string {
// The annotation exists for all static pods.
return pod.Annotations[kubetypes.ConfigHashAnnotationKey]
}
4 changes: 1 addition & 3 deletions pkg/kubelet/types/pod_update.go
Expand Up @@ -25,6 +25,7 @@ import (
const ConfigSourceAnnotationKey = "kubernetes.io/config.source"
const ConfigMirrorAnnotationKey = "kubernetes.io/config.mirror"
const ConfigFirstSeenAnnotationKey = "kubernetes.io/config.seen"
const ConfigHashAnnotationKey = "kubernetes.io/config.hash"

// PodOperation defines what changes will be made on a pod configuration.
type PodOperation int
Expand All @@ -49,9 +50,6 @@ const (
// Updates from all sources
AllSource = "*"

// Used for ConfigMirrorAnnotationKey.
MirrorType = "mirror"

NamespaceDefault = api.NamespaceDefault
)

Expand Down