mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Implement pod deletion cost
This commit is contained in:
@@ -32,6 +32,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
@@ -1328,3 +1329,53 @@ func TestDropEphemeralContainers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePodDeletionCostOption(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
oldPodMeta *metav1.ObjectMeta
|
||||
featureEnabled bool
|
||||
wantAllowInvalidPodDeletionCost bool
|
||||
}{
|
||||
{
|
||||
name: "CreateFeatureEnabled",
|
||||
featureEnabled: true,
|
||||
wantAllowInvalidPodDeletionCost: false,
|
||||
},
|
||||
{
|
||||
name: "CreateFeatureDisabled",
|
||||
featureEnabled: false,
|
||||
wantAllowInvalidPodDeletionCost: true,
|
||||
},
|
||||
{
|
||||
name: "UpdateFeatureDisabled",
|
||||
oldPodMeta: &metav1.ObjectMeta{Annotations: map[string]string{core.PodDeletionCost: "100"}},
|
||||
featureEnabled: false,
|
||||
wantAllowInvalidPodDeletionCost: true,
|
||||
},
|
||||
{
|
||||
name: "UpdateFeatureEnabledValidOldValue",
|
||||
oldPodMeta: &metav1.ObjectMeta{Annotations: map[string]string{core.PodDeletionCost: "100"}},
|
||||
featureEnabled: true,
|
||||
wantAllowInvalidPodDeletionCost: false,
|
||||
},
|
||||
{
|
||||
name: "UpdateFeatureEnabledValidOldValue",
|
||||
oldPodMeta: &metav1.ObjectMeta{Annotations: map[string]string{core.PodDeletionCost: "invalid-value"}},
|
||||
featureEnabled: true,
|
||||
wantAllowInvalidPodDeletionCost: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodDeletionCost, tc.featureEnabled)()
|
||||
// The new pod doesn't impact the outcome.
|
||||
gotOptions := GetValidationOptionsFromPodSpecAndMeta(nil, nil, nil, tc.oldPodMeta)
|
||||
if tc.wantAllowInvalidPodDeletionCost != gotOptions.AllowInvalidPodDeletionCost {
|
||||
t.Errorf("unexpected diff, want: %v, got: %v", tc.wantAllowInvalidPodDeletionCost, gotOptions.AllowInvalidPodDeletionCost)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user