kubeadm: Add back labels for the Static Pod control plane (attempt 2)

pull/6/head
Lucas Käldström 2017-08-19 19:59:59 +03:00
parent eb207eb882
commit 4a693337b6
No known key found for this signature in database
GPG Key ID: 3FA3783D77751514
3 changed files with 35 additions and 9 deletions

View File

@ -15,6 +15,7 @@ go_test(
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
], ],
) )

View File

@ -42,6 +42,9 @@ func ComponentPod(container v1.Container, volumes []v1.Volume) v1.Pod {
Name: container.Name, Name: container.Name,
Namespace: metav1.NamespaceSystem, Namespace: metav1.NamespaceSystem,
Annotations: map[string]string{kubetypes.CriticalPodAnnotationKey: ""}, Annotations: map[string]string{kubetypes.CriticalPodAnnotationKey: ""},
// The component and tier labels are useful for quickly identifying the control plane Pods when doing a .List()
// against Pods in the kube-system namespace. Can for example be used together with the WaitForPodsWithLabel function
Labels: map[string]string{"component": container.Name, "tier": "control-plane"},
}, },
Spec: v1.PodSpec{ Spec: v1.PodSpec{
Containers: []v1.Container{container}, Containers: []v1.Container{container},

View File

@ -22,6 +22,7 @@ import (
"testing" "testing"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
) )
@ -79,22 +80,43 @@ func TestComponentProbe(t *testing.T) {
func TestComponentPod(t *testing.T) { func TestComponentPod(t *testing.T) {
var tests = []struct { var tests = []struct {
n string name string
expected v1.Pod
}{ }{
{ {
n: "foo", name: "foo",
expected: v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "kube-system",
Annotations: map[string]string{"scheduler.alpha.kubernetes.io/critical-pod": ""},
Labels: map[string]string{"component": "foo", "tier": "control-plane"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "foo",
},
},
HostNetwork: true,
Volumes: []v1.Volume{},
},
},
}, },
} }
for _, rt := range tests { for _, rt := range tests {
c := v1.Container{Name: rt.n} c := v1.Container{Name: rt.name}
v := []v1.Volume{} actual := ComponentPod(c, []v1.Volume{})
actual := ComponentPod(c, v) if !reflect.DeepEqual(rt.expected, actual) {
if actual.ObjectMeta.Name != rt.n {
t.Errorf( t.Errorf(
"failed componentPod:\n\texpected: %s\n\t actual: %s", "failed componentPod:\n\texpected: %v\n\t actual: %v",
rt.n, rt.expected,
actual.ObjectMeta.Name, actual,
) )
} }
} }