Add a container type to the runtime labels
This is part of the "Debug Containers" feature and is hidden behind a feature gate. Debug containers have no stored spec, so this new runtime label allows the kubelet to treat containers differently without relying on spec.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
)
|
||||
|
||||
@@ -63,19 +64,92 @@ func TestContainerLabels(t *testing.T) {
|
||||
TerminationGracePeriodSeconds: &terminationGracePeriod,
|
||||
},
|
||||
}
|
||||
expected := &labeledContainerInfo{
|
||||
PodName: pod.Name,
|
||||
PodNamespace: pod.Namespace,
|
||||
PodUID: pod.UID,
|
||||
ContainerName: container.Name,
|
||||
|
||||
var tests = []struct {
|
||||
description string
|
||||
featuresCreated string // Features enabled when container is created
|
||||
featuresStatus string // Features enabled when container status is read
|
||||
typeLabel kubecontainer.ContainerType
|
||||
expected *labeledContainerInfo
|
||||
}{
|
||||
{
|
||||
"Debug containers disabled",
|
||||
"DebugContainers=False",
|
||||
"DebugContainers=False",
|
||||
"ignored",
|
||||
&labeledContainerInfo{
|
||||
PodName: pod.Name,
|
||||
PodNamespace: pod.Namespace,
|
||||
PodUID: pod.UID,
|
||||
ContainerName: container.Name,
|
||||
ContainerType: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"Regular containers",
|
||||
"DebugContainers=True",
|
||||
"DebugContainers=True",
|
||||
kubecontainer.ContainerTypeRegular,
|
||||
&labeledContainerInfo{
|
||||
PodName: pod.Name,
|
||||
PodNamespace: pod.Namespace,
|
||||
PodUID: pod.UID,
|
||||
ContainerName: container.Name,
|
||||
ContainerType: kubecontainer.ContainerTypeRegular,
|
||||
},
|
||||
},
|
||||
{
|
||||
"Init containers",
|
||||
"DebugContainers=True",
|
||||
"DebugContainers=True",
|
||||
kubecontainer.ContainerTypeInit,
|
||||
&labeledContainerInfo{
|
||||
PodName: pod.Name,
|
||||
PodNamespace: pod.Namespace,
|
||||
PodUID: pod.UID,
|
||||
ContainerName: container.Name,
|
||||
ContainerType: kubecontainer.ContainerTypeInit,
|
||||
},
|
||||
},
|
||||
{
|
||||
"Created without type label",
|
||||
"DebugContainers=False",
|
||||
"DebugContainers=True",
|
||||
"ignored",
|
||||
&labeledContainerInfo{
|
||||
PodName: pod.Name,
|
||||
PodNamespace: pod.Namespace,
|
||||
PodUID: pod.UID,
|
||||
ContainerName: container.Name,
|
||||
ContainerType: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"Created with type label, subsequently disabled",
|
||||
"DebugContainers=True",
|
||||
"DebugContainers=False",
|
||||
kubecontainer.ContainerTypeRegular,
|
||||
&labeledContainerInfo{
|
||||
PodName: pod.Name,
|
||||
PodNamespace: pod.Namespace,
|
||||
PodUID: pod.UID,
|
||||
ContainerName: container.Name,
|
||||
ContainerType: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Test whether we can get right information from label
|
||||
labels := newContainerLabels(container, pod)
|
||||
containerInfo := getContainerInfoFromLabels(labels)
|
||||
if !reflect.DeepEqual(containerInfo, expected) {
|
||||
t.Errorf("expected %v, got %v", expected, containerInfo)
|
||||
for _, test := range tests {
|
||||
utilfeature.DefaultFeatureGate.Set(test.featuresCreated)
|
||||
labels := newContainerLabels(container, pod, test.typeLabel)
|
||||
utilfeature.DefaultFeatureGate.Set(test.featuresStatus)
|
||||
containerInfo := getContainerInfoFromLabels(labels)
|
||||
if !reflect.DeepEqual(containerInfo, test.expected) {
|
||||
t.Errorf("%v: expected %v, got %v", test.description, test.expected, containerInfo)
|
||||
}
|
||||
}
|
||||
utilfeature.DefaultFeatureGate.Set("DebugContainers=False")
|
||||
}
|
||||
|
||||
func TestContainerAnnotations(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user