mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 23:29:21 +00:00
Tag all feature gates required by a test
Use all necessary feature gates in SELinuxMount tests.
This commit is contained in:
parent
2a22b6f6b8
commit
74417b517a
@ -49,12 +49,12 @@ import (
|
||||
// These tags are used in the tests:
|
||||
//
|
||||
// [FeatureGate:SELinuxMountReadWriteOncePod]
|
||||
// - The test requires SELinuxMountReadWriteOncePod enabled. SELinuxMount may be enabled or disabled, except for tests with Feature:SELinuxMountReadWriteOncePodOnly (see below).
|
||||
// - The test requires SELinuxMountReadWriteOncePod enabled.
|
||||
//
|
||||
// [FeatureGate:SELinuxMountReadWriteOncePod] [Feature:SELinuxMountReadWriteOncePodOnly]
|
||||
// - The test requires SELinuxMountReadWriteOncePod enabled and SELinuxMount disabled. This checks metrics that are emitted only when SELinuxMount is disabled.
|
||||
//
|
||||
// [FeatureGate:SELinuxMount]
|
||||
// [FeatureGate:SELinuxMountReadWriteOncePod] [FeatureGate:SELinuxMount]
|
||||
// - The test requires SELinuxMountReadWriteOncePod and SELinuxMount enabled.
|
||||
var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
f := framework.NewDefaultFramework("csi-mock-volumes-selinux")
|
||||
@ -89,7 +89,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
expectedFirstMountOptions []string
|
||||
expectedSecondMountOptions []string
|
||||
expectedUnstage bool
|
||||
feature interface{}
|
||||
testTags []interface{}
|
||||
}{
|
||||
// Start just a single pod and check its volume is mounted correctly
|
||||
{
|
||||
@ -98,7 +98,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
firstPodSELinuxOpts: &seLinuxOpts1,
|
||||
volumeMode: v1.ReadWriteOncePod,
|
||||
expectedFirstMountOptions: []string{seLinuxMountOption1},
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
{
|
||||
name: "should add SELinux mount option to existing mount options",
|
||||
@ -107,7 +107,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
mountOptions: []string{"noexec", "noatime"},
|
||||
volumeMode: v1.ReadWriteOncePod,
|
||||
expectedFirstMountOptions: []string{"noexec", "noatime", seLinuxMountOption1},
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
{
|
||||
name: "should not pass SELinux mount option for RWO volume with SELinuxMount disabled",
|
||||
@ -115,7 +115,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
firstPodSELinuxOpts: &seLinuxOpts1,
|
||||
volumeMode: v1.ReadWriteOnce,
|
||||
expectedFirstMountOptions: nil,
|
||||
feature: feature.SELinuxMountReadWriteOncePodOnly,
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), feature.SELinuxMountReadWriteOncePodOnly},
|
||||
},
|
||||
{
|
||||
name: "should pass SELinux mount option for RWO volume with SELinuxMount enabled",
|
||||
@ -123,7 +123,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
firstPodSELinuxOpts: &seLinuxOpts1,
|
||||
volumeMode: v1.ReadWriteOnce,
|
||||
expectedFirstMountOptions: []string{seLinuxMountOption1},
|
||||
feature: framework.WithFeatureGate(features.SELinuxMount),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), framework.WithFeatureGate(features.SELinuxMount)},
|
||||
},
|
||||
{
|
||||
name: "should not pass SELinux mount option for Pod without SELinux context",
|
||||
@ -131,7 +131,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
firstPodSELinuxOpts: nil,
|
||||
volumeMode: v1.ReadWriteOncePod,
|
||||
expectedFirstMountOptions: nil,
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
{
|
||||
name: "should not pass SELinux mount option for CSI driver that does not support SELinux mount",
|
||||
@ -139,7 +139,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
firstPodSELinuxOpts: &seLinuxOpts1,
|
||||
volumeMode: v1.ReadWriteOncePod,
|
||||
expectedFirstMountOptions: nil,
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
// Start two pods in a sequence and check their volume is / is not unmounted in between
|
||||
{
|
||||
@ -152,7 +152,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
expectedFirstMountOptions: []string{seLinuxMountOption1},
|
||||
expectedSecondMountOptions: []string{seLinuxMountOption1},
|
||||
expectedUnstage: false,
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
{
|
||||
name: "should unstage RWOP volume when starting a second pod with different SELinux context",
|
||||
@ -164,7 +164,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
expectedFirstMountOptions: []string{seLinuxMountOption1},
|
||||
expectedSecondMountOptions: []string{seLinuxMountOption2},
|
||||
expectedUnstage: true,
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
{
|
||||
name: "should not unstage RWO volume when starting a second pod with the same SELinux context",
|
||||
@ -176,7 +176,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
expectedFirstMountOptions: []string{seLinuxMountOption1},
|
||||
expectedSecondMountOptions: []string{seLinuxMountOption1},
|
||||
expectedUnstage: false,
|
||||
feature: framework.WithFeatureGate(features.SELinuxMount),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), framework.WithFeatureGate(features.SELinuxMount)},
|
||||
},
|
||||
{
|
||||
name: "should unstage RWO volume when starting a second pod with different SELinux context",
|
||||
@ -188,12 +188,12 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
expectedFirstMountOptions: []string{seLinuxMountOption1},
|
||||
expectedSecondMountOptions: []string{seLinuxMountOption2},
|
||||
expectedUnstage: true,
|
||||
feature: framework.WithFeatureGate(features.SELinuxMount),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), framework.WithFeatureGate(features.SELinuxMount)},
|
||||
},
|
||||
}
|
||||
for _, t := range tests {
|
||||
t := t
|
||||
f.It(t.name, t.feature, func(ctx context.Context) {
|
||||
testFunc := func(ctx context.Context) {
|
||||
if framework.NodeOSDistroIs("windows") {
|
||||
e2eskipper.Skipf("SELinuxMount is only applied on linux nodes -- skipping")
|
||||
}
|
||||
@ -303,7 +303,15 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount", func() {
|
||||
gomega.Expect(unpublishCalls.Load()).To(gomega.BeNumerically(">", 0), "NodeUnpublish calls after the first pod is deleted")
|
||||
gomega.Expect(publishCalls.Load()).To(gomega.BeNumerically(">", 0), "NodePublish calls for the second pod")
|
||||
gomega.Expect(nodePublishMountOpts).To(gomega.Equal(t.expectedSecondMountOptions), "NodePublish MountFlags for the second pod")
|
||||
})
|
||||
}
|
||||
// t.testTags is array and it's not possible to use It("name", func(){}, t.testTags...)
|
||||
// Compose It() arguments separately.
|
||||
args := []interface{}{
|
||||
t.name,
|
||||
testFunc,
|
||||
}
|
||||
args = append(args, t.testTags...)
|
||||
framework.It(args...)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -338,7 +346,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
waitForSecondPodStart bool
|
||||
secondPodFailureEvent string
|
||||
expectIncreases sets.String
|
||||
feature interface{}
|
||||
testTags []interface{}
|
||||
}{
|
||||
{
|
||||
name: "warning is not bumped on two Pods with the same context on RWO volume",
|
||||
@ -348,7 +356,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
volumeMode: v1.ReadWriteOnce,
|
||||
waitForSecondPodStart: true,
|
||||
expectIncreases: sets.NewString( /* no metric is increased, admitted_total was already increased when the first pod started */ ),
|
||||
feature: feature.SELinuxMountReadWriteOncePodOnly,
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), feature.SELinuxMountReadWriteOncePodOnly},
|
||||
},
|
||||
{
|
||||
name: "warning is bumped on two Pods with a different context on RWO volume",
|
||||
@ -358,7 +366,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
volumeMode: v1.ReadWriteOnce,
|
||||
waitForSecondPodStart: true,
|
||||
expectIncreases: sets.NewString("volume_manager_selinux_volume_context_mismatch_warnings_total"),
|
||||
feature: feature.SELinuxMountReadWriteOncePodOnly,
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), feature.SELinuxMountReadWriteOncePodOnly},
|
||||
},
|
||||
{
|
||||
name: "error is not bumped on two Pods with the same context on RWO volume and SELinuxMount enabled",
|
||||
@ -368,7 +376,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
volumeMode: v1.ReadWriteOnce,
|
||||
waitForSecondPodStart: true,
|
||||
expectIncreases: sets.NewString( /* no metric is increased, admitted_total was already increased when the first pod started */ ),
|
||||
feature: framework.WithFeatureGate(features.SELinuxMount),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), framework.WithFeatureGate(features.SELinuxMount)},
|
||||
},
|
||||
{
|
||||
name: "error is bumped on two Pods with a different context on RWO volume and SELinuxMount enabled",
|
||||
@ -379,7 +387,7 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
volumeMode: v1.ReadWriteOnce,
|
||||
waitForSecondPodStart: false,
|
||||
expectIncreases: sets.NewString("volume_manager_selinux_volume_context_mismatch_errors_total"),
|
||||
feature: framework.WithFeatureGate(features.SELinuxMount),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod), framework.WithFeatureGate(features.SELinuxMount)},
|
||||
},
|
||||
{
|
||||
name: "error is bumped on two Pods with a different context on RWOP volume",
|
||||
@ -390,12 +398,12 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
volumeMode: v1.ReadWriteOncePod,
|
||||
waitForSecondPodStart: false,
|
||||
expectIncreases: sets.NewString("volume_manager_selinux_volume_context_mismatch_errors_total"),
|
||||
feature: framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod),
|
||||
testTags: []interface{}{framework.WithFeatureGate(features.SELinuxMountReadWriteOncePod)},
|
||||
},
|
||||
}
|
||||
for _, t := range tests {
|
||||
t := t
|
||||
f.It(t.name, t.feature, func(ctx context.Context) {
|
||||
testFunc := func(ctx context.Context) {
|
||||
// Some metrics use CSI driver name as a label, which is "csi-mock-" + the namespace name.
|
||||
volumePluginLabel := "{volume_plugin=\"kubernetes.io/csi/csi-mock-" + f.Namespace.Name + "\"}"
|
||||
|
||||
@ -467,7 +475,15 @@ var _ = utils.SIGDescribe("CSI Mock selinux on mount metrics", func() {
|
||||
ginkgo.By("Waiting for expected metric changes")
|
||||
err = waitForMetricIncrease(ctx, grabber, pod.Spec.NodeName, allMetrics, t.expectIncreases, metrics, framework.PodStartShortTimeout)
|
||||
framework.ExpectNoError(err, "waiting for metrics %s to increase", t.expectIncreases)
|
||||
})
|
||||
}
|
||||
// t.testTags is array and it's not possible to use It("name", func(){xxx}, t.testTags...)
|
||||
// Compose It() arguments separately.
|
||||
args := []interface{}{
|
||||
t.name,
|
||||
testFunc,
|
||||
}
|
||||
args = append(args, t.testTags...)
|
||||
framework.It(args...)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user