mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
graduate MatchLabelKeysInPodAffinity to Beta
This commit is contained in:
parent
925cb2be30
commit
2ea7d8f523
4
api/openapi-spec/swagger.json
generated
4
api/openapi-spec/swagger.json
generated
@ -9120,7 +9120,7 @@
|
||||
"description": "A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods."
|
||||
},
|
||||
"matchLabelKeys": {
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -9128,7 +9128,7 @@
|
||||
"x-kubernetes-list-type": "atomic"
|
||||
},
|
||||
"mismatchLabelKeys": {
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -4944,7 +4944,7 @@
|
||||
"description": "A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods."
|
||||
},
|
||||
"matchLabelKeys": {
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
@ -4953,7 +4953,7 @@
|
||||
"x-kubernetes-list-type": "atomic"
|
||||
},
|
||||
"mismatchLabelKeys": {
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
|
@ -3418,7 +3418,7 @@
|
||||
"description": "A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods."
|
||||
},
|
||||
"matchLabelKeys": {
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
@ -3427,7 +3427,7 @@
|
||||
"x-kubernetes-list-type": "atomic"
|
||||
},
|
||||
"mismatchLabelKeys": {
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
|
@ -2622,7 +2622,7 @@
|
||||
"description": "A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods."
|
||||
},
|
||||
"matchLabelKeys": {
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
@ -2631,7 +2631,7 @@
|
||||
"x-kubernetes-list-type": "atomic"
|
||||
},
|
||||
"mismatchLabelKeys": {
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"items": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
|
@ -3083,19 +3083,27 @@ type PodAffinityTerm struct {
|
||||
NamespaceSelector *metav1.LabelSelector
|
||||
// MatchLabelKeys is a set of pod label keys to select which pods will
|
||||
// be taken into consideration. The keys are used to lookup values from the
|
||||
// incoming pod labels, those key-value labels are merged with `LabelSelector` as `key in (value)`
|
||||
// incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)`
|
||||
// to select the group of existing pods which pods will be taken into consideration
|
||||
// for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming
|
||||
// pod labels will be ignored. The default value is empty.
|
||||
// The same key is forbidden to exist in both matchLabelKeys and labelSelector.
|
||||
// Also, matchLabelKeys cannot be set when labelSelector isn't set.
|
||||
// This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).
|
||||
//
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
MatchLabelKeys []string
|
||||
// MismatchLabelKeys is a set of pod label keys to select which pods will
|
||||
// be taken into consideration. The keys are used to lookup values from the
|
||||
// incoming pod labels, those key-value labels are merged with `LabelSelector` as `key notin (value)`
|
||||
// incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)`
|
||||
// to select the group of existing pods which pods will be taken into consideration
|
||||
// for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming
|
||||
// pod labels will be ignored. The default value is empty.
|
||||
// The same key is forbidden to exist in both mismatchLabelKeys and labelSelector.
|
||||
// Also, mismatchLabelKeys cannot be set when labelSelector isn't set.
|
||||
// This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).
|
||||
//
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
MismatchLabelKeys []string
|
||||
|
@ -432,6 +432,7 @@ const (
|
||||
// owner: @sanposhiho
|
||||
// kep: https://kep.k8s.io/3633
|
||||
// alpha: v1.29
|
||||
// beta: v1.30
|
||||
//
|
||||
// Enables the MatchLabelKeys and MismatchLabelKeys in PodAffinity and PodAntiAffinity.
|
||||
MatchLabelKeysInPodAffinity featuregate.Feature = "MatchLabelKeysInPodAffinity"
|
||||
@ -1062,7 +1063,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
||||
|
||||
LogarithmicScaleDown: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
MatchLabelKeysInPodAffinity: {Default: false, PreRelease: featuregate.Alpha},
|
||||
MatchLabelKeysInPodAffinity: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
MatchLabelKeysInPodTopologySpread: {Default: true, PreRelease: featuregate.Beta},
|
||||
|
||||
|
4
pkg/generated/openapi/zz_generated.openapi.go
generated
4
pkg/generated/openapi/zz_generated.openapi.go
generated
@ -26270,7 +26270,7 @@ func schema_k8sio_api_core_v1_PodAffinityTerm(ref common.ReferenceCallback) comm
|
||||
},
|
||||
},
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
Description: "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
Type: []string{"array"},
|
||||
Items: &spec.SchemaOrArray{
|
||||
Schema: &spec.Schema{
|
||||
@ -26290,7 +26290,7 @@ func schema_k8sio_api_core_v1_PodAffinityTerm(ref common.ReferenceCallback) comm
|
||||
},
|
||||
},
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
Description: "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
Type: []string{"array"},
|
||||
Items: &spec.SchemaOrArray{
|
||||
Schema: &spec.Schema{
|
||||
|
@ -3515,7 +3515,8 @@ message PodAffinityTerm {
|
||||
// pod labels will be ignored. The default value is empty.
|
||||
// The same key is forbidden to exist in both matchLabelKeys and labelSelector.
|
||||
// Also, matchLabelKeys cannot be set when labelSelector isn't set.
|
||||
// This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.
|
||||
// This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).
|
||||
//
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
repeated string matchLabelKeys = 5;
|
||||
@ -3528,7 +3529,8 @@ message PodAffinityTerm {
|
||||
// pod labels will be ignored. The default value is empty.
|
||||
// The same key is forbidden to exist in both mismatchLabelKeys and labelSelector.
|
||||
// Also, mismatchLabelKeys cannot be set when labelSelector isn't set.
|
||||
// This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.
|
||||
// This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).
|
||||
//
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
repeated string mismatchLabelKeys = 6;
|
||||
|
@ -3426,7 +3426,8 @@ type PodAffinityTerm struct {
|
||||
// pod labels will be ignored. The default value is empty.
|
||||
// The same key is forbidden to exist in both matchLabelKeys and labelSelector.
|
||||
// Also, matchLabelKeys cannot be set when labelSelector isn't set.
|
||||
// This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.
|
||||
// This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).
|
||||
//
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
MatchLabelKeys []string `json:"matchLabelKeys,omitempty" protobuf:"bytes,5,opt,name=matchLabelKeys"`
|
||||
@ -3438,7 +3439,8 @@ type PodAffinityTerm struct {
|
||||
// pod labels will be ignored. The default value is empty.
|
||||
// The same key is forbidden to exist in both mismatchLabelKeys and labelSelector.
|
||||
// Also, mismatchLabelKeys cannot be set when labelSelector isn't set.
|
||||
// This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.
|
||||
// This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).
|
||||
//
|
||||
// +listType=atomic
|
||||
// +optional
|
||||
MismatchLabelKeys []string `json:"mismatchLabelKeys,omitempty" protobuf:"bytes,6,opt,name=mismatchLabelKeys"`
|
||||
|
@ -1544,8 +1544,8 @@ var map_PodAffinityTerm = map[string]string{
|
||||
"namespaces": "namespaces specifies a static list of namespace names that the term applies to. The term is applied to the union of the namespaces listed in this field and the ones selected by namespaceSelector. null or empty namespaces list and null namespaceSelector means \"this pod's namespace\".",
|
||||
"topologyKey": "This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed.",
|
||||
"namespaceSelector": "A label query over the set of namespaces that the term applies to. The term is applied to the union of the namespaces selected by this field and the ones listed in the namespaces field. null selector and null or empty namespaces list means \"this pod's namespace\". An empty selector ({}) matches all namespaces.",
|
||||
"matchLabelKeys": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"mismatchLabelKeys": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.",
|
||||
"matchLabelKeys": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
"mismatchLabelKeys": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set. This is a beta field and requires enabling MatchLabelKeysInPodAffinity feature gate (enabled by default).",
|
||||
}
|
||||
|
||||
func (PodAffinityTerm) SwaggerDoc() map[string]string {
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
@ -2174,3 +2175,142 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestPodAffinityMatchLabelKeyEnablement tests the Pod is correctly mutated by MatchLabelKeysInPodAffinity feature,
|
||||
// even if turing the feature gate enabled or disabled.
|
||||
func TestPodAffinityMatchLabelKeyEnablement(t *testing.T) {
|
||||
// enable the feature gate
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.MatchLabelKeysInPodAffinity, true)
|
||||
testCtx := initTest(t, "matchlabelkey")
|
||||
|
||||
pod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
GenerateName: "test",
|
||||
Namespace: testCtx.NS.Name,
|
||||
Labels: map[string]string{"foo": "", "bar": "a"},
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "container",
|
||||
Image: imageutils.GetPauseImageName(),
|
||||
Resources: v1.ResourceRequirements{
|
||||
Requests: v1.ResourceList{
|
||||
v1.ResourceMemory: resource.MustParse("1G"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Affinity: &v1.Affinity{
|
||||
PodAffinity: &v1.PodAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
|
||||
{
|
||||
TopologyKey: "node",
|
||||
LabelSelector: &metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "foo",
|
||||
Operator: metav1.LabelSelectorOpExists,
|
||||
},
|
||||
},
|
||||
},
|
||||
MatchLabelKeys: []string{"bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedLabelSelector := &metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "foo",
|
||||
Operator: metav1.LabelSelectorOpExists,
|
||||
},
|
||||
{
|
||||
Key: "bar",
|
||||
Operator: metav1.LabelSelectorOpIn,
|
||||
Values: []string{"a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p1, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Create(testCtx.Ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating pod during test: %v", err)
|
||||
}
|
||||
|
||||
// check the pod has the expected label selector.
|
||||
gotpod, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Get(testCtx.Ctx, p1.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting pod during test: %v", err)
|
||||
}
|
||||
|
||||
// the label selector should be changed from the original one because the feature gate is enabled.
|
||||
if d := cmp.Diff(gotpod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector, expectedLabelSelector); d != "" {
|
||||
t.Fatalf("Pod %v has wrong label selector: diff = \n%v", p1.Name, d)
|
||||
}
|
||||
|
||||
// disable the feature gate.
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.MatchLabelKeysInPodAffinity, false)
|
||||
|
||||
p2, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Create(testCtx.Ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating pod during test: %v", err)
|
||||
}
|
||||
|
||||
// check the pod has the expected label selector.
|
||||
gotpod, err = testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Get(testCtx.Ctx, p2.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting pod during test: %v", err)
|
||||
}
|
||||
|
||||
// the label selector should be the same as the original one because the feature gate is disabled.
|
||||
if d := cmp.Diff(gotpod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector, pod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector); d != "" {
|
||||
t.Fatalf("Pod %v has wrong label selector: diff = \n%v", p2.Name, d)
|
||||
}
|
||||
|
||||
// check the pod, which was created when the feature gate is enabled, still has the expected label selector.
|
||||
gotpod, err = testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Get(testCtx.Ctx, p1.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting pod during test: %v", err)
|
||||
}
|
||||
|
||||
// the label selector should be changed from the original one because the feature gate is enabled.
|
||||
if d := cmp.Diff(gotpod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector, expectedLabelSelector); d != "" {
|
||||
t.Fatalf("Pod %v has wrong label selector: diff = \n%v", p1.Name, d)
|
||||
}
|
||||
|
||||
// Again, enable the feature gate.
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.MatchLabelKeysInPodAffinity, true)
|
||||
|
||||
p3, err := testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Create(testCtx.Ctx, pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while creating pod during test: %v", err)
|
||||
}
|
||||
|
||||
// check the pod has the expected label selector.
|
||||
gotpod, err = testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Get(testCtx.Ctx, p3.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting pod during test: %v", err)
|
||||
}
|
||||
|
||||
// the label selector should be changed from the original one because the feature gate is enabled.
|
||||
if d := cmp.Diff(gotpod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector, expectedLabelSelector); d != "" {
|
||||
t.Fatalf("Pod %v has wrong label selector: diff = \n%v", p1.Name, d)
|
||||
}
|
||||
|
||||
// check the pod has the expected label selector.
|
||||
gotpod, err = testCtx.ClientSet.CoreV1().Pods(testCtx.NS.Name).Get(testCtx.Ctx, p2.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting pod during test: %v", err)
|
||||
}
|
||||
|
||||
// the label selector shouldn't get changed because the feature gate was disabled at its creation.
|
||||
// Even if the feature gate is enabled now, matchLabelKeys don't get applied to the pod.
|
||||
// (it's only handled when the pod is created)
|
||||
if d := cmp.Diff(gotpod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector, pod.Spec.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution[0].LabelSelector); d != "" {
|
||||
t.Fatalf("Pod %v has wrong label selector: diff = \n%v", p2.Name, d)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user