mirror of https://github.com/k3s-io/k3s
Fix local PV node affinity tests and only run once
parent
b80ee8c02c
commit
95f04eebee
|
@ -168,6 +168,7 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO: move this under volumeType loop
|
||||||
Context("when one pod requests one prebound PVC", func() {
|
Context("when one pod requests one prebound PVC", func() {
|
||||||
|
|
||||||
var testVol *localTestVolume
|
var testVol *localTestVolume
|
||||||
|
@ -257,75 +258,91 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("when pod using local volume with non-existant path", func() {
|
|
||||||
|
|
||||||
ep := &eventPatterns{
|
|
||||||
reason: "FailedMount",
|
|
||||||
pattern: make([]string, 2)}
|
|
||||||
ep.pattern = append(ep.pattern, "MountVolume.SetUp failed")
|
|
||||||
ep.pattern = append(ep.pattern, "does not exist")
|
|
||||||
|
|
||||||
It("should not be able to mount", func() {
|
|
||||||
testVol := &localTestVolume{
|
|
||||||
node: config.node0,
|
|
||||||
hostDir: "/non-existent/location/nowhere",
|
|
||||||
localVolumeType: testVolType,
|
|
||||||
}
|
|
||||||
By("Creating local PVC and PV")
|
|
||||||
createLocalPVCsPVs(config, []*localTestVolume{testVol}, testMode)
|
|
||||||
pod, err := createLocalPod(config, testVol)
|
|
||||||
Expect(err).To(HaveOccurred())
|
|
||||||
checkPodEvents(config, pod.Name, ep)
|
|
||||||
verifyLocalVolume(config, testVol)
|
|
||||||
cleanupLocalPVCsPVs(config, []*localTestVolume{testVol})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("when pod's node is different from PV's NodeAffinity", func() {
|
|
||||||
|
|
||||||
BeforeEach(func() {
|
|
||||||
if len(config.nodes) < 2 {
|
|
||||||
framework.Skipf("Runs only when number of nodes >= 2")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ep := &eventPatterns{
|
|
||||||
reason: "FailedScheduling",
|
|
||||||
pattern: make([]string, 2)}
|
|
||||||
ep.pattern = append(ep.pattern, "MatchNodeSelector")
|
|
||||||
ep.pattern = append(ep.pattern, "VolumeNodeAffinityConflict")
|
|
||||||
|
|
||||||
It("should not be able to mount due to different NodeAffinity", func() {
|
|
||||||
testPodWithNodeName(config, testVolType, ep, config.nodes[1].Name, makeLocalPodWithNodeAffinity, testMode)
|
|
||||||
})
|
|
||||||
|
|
||||||
It("should not be able to mount due to different NodeSelector", func() {
|
|
||||||
testPodWithNodeName(config, testVolType, ep, config.nodes[1].Name, makeLocalPodWithNodeSelector, testMode)
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
Context("when pod's node is different from PV's NodeName", func() {
|
|
||||||
|
|
||||||
BeforeEach(func() {
|
|
||||||
if len(config.nodes) < 2 {
|
|
||||||
framework.Skipf("Runs only when number of nodes >= 2")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ep := &eventPatterns{
|
|
||||||
reason: "FailedMount",
|
|
||||||
pattern: make([]string, 2)}
|
|
||||||
ep.pattern = append(ep.pattern, "NodeSelectorTerm")
|
|
||||||
ep.pattern = append(ep.pattern, "MountVolume.NodeAffinity check failed")
|
|
||||||
|
|
||||||
It("should not be able to mount due to different NodeName", func() {
|
|
||||||
testPodWithNodeName(config, testVolType, ep, config.nodes[1].Name, makeLocalPodWithNodeName, testMode)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context("when local volume cannot be mounted [Slow]", func() {
|
||||||
|
// TODO:
|
||||||
|
// - make the pod create timeout shorter
|
||||||
|
// - check for these errors in unit tests intead
|
||||||
|
It("should fail mount due to non-existant path", func() {
|
||||||
|
ep := &eventPatterns{
|
||||||
|
reason: "FailedMount",
|
||||||
|
pattern: make([]string, 2)}
|
||||||
|
ep.pattern = append(ep.pattern, "MountVolume.SetUp failed")
|
||||||
|
ep.pattern = append(ep.pattern, "does not exist")
|
||||||
|
|
||||||
|
testVol := &localTestVolume{
|
||||||
|
node: config.node0,
|
||||||
|
hostDir: "/non-existent/location/nowhere",
|
||||||
|
localVolumeType: DirectoryLocalVolumeType,
|
||||||
|
}
|
||||||
|
By("Creating local PVC and PV")
|
||||||
|
createLocalPVCsPVs(config, []*localTestVolume{testVol}, immediateMode)
|
||||||
|
pod, err := createLocalPod(config, testVol)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
checkPodEvents(config, pod.Name, ep)
|
||||||
|
verifyLocalVolume(config, testVol)
|
||||||
|
cleanupLocalPVCsPVs(config, []*localTestVolume{testVol})
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should fail mount due to wrong node", func() {
|
||||||
|
if len(config.nodes) < 2 {
|
||||||
|
framework.Skipf("Runs only when number of nodes >= 2")
|
||||||
|
}
|
||||||
|
|
||||||
|
ep := &eventPatterns{
|
||||||
|
reason: "FailedMount",
|
||||||
|
pattern: make([]string, 2)}
|
||||||
|
ep.pattern = append(ep.pattern, "NodeSelectorTerm")
|
||||||
|
ep.pattern = append(ep.pattern, "MountVolume.NodeAffinity check failed")
|
||||||
|
|
||||||
|
testVols := setupLocalVolumesPVCsPVs(config, DirectoryLocalVolumeType, config.node0, 1, immediateMode)
|
||||||
|
testVol := testVols[0]
|
||||||
|
|
||||||
|
pod := makeLocalPodWithNodeName(config, testVol, config.nodes[1].Name)
|
||||||
|
pod, err := config.client.CoreV1().Pods(config.ns).Create(pod)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
err = framework.WaitForPodNameRunningInNamespace(config.client, pod.Name, pod.Namespace)
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
checkPodEvents(config, pod.Name, ep)
|
||||||
|
|
||||||
|
cleanupLocalVolumes(config, []*localTestVolume{testVol})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("when pod's node is different from PV's NodeAffinity", func() {
|
||||||
|
var (
|
||||||
|
testVol *localTestVolume
|
||||||
|
volumeType localVolumeType
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
if len(config.nodes) < 2 {
|
||||||
|
framework.Skipf("Runs only when number of nodes >= 2")
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeType = DirectoryLocalVolumeType
|
||||||
|
setupStorageClass(config, &immediateMode)
|
||||||
|
testVols := setupLocalVolumesPVCsPVs(config, volumeType, config.node0, 1, immediateMode)
|
||||||
|
testVol = testVols[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
cleanupLocalVolumes(config, []*localTestVolume{testVol})
|
||||||
|
cleanupStorageClass(config)
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should not be able to mount due to different NodeAffinity", func() {
|
||||||
|
testPodWithNodeConflict(config, volumeType, config.nodes[1].Name, makeLocalPodWithNodeAffinity, immediateMode)
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should not be able to mount due to different NodeSelector", func() {
|
||||||
|
testPodWithNodeConflict(config, volumeType, config.nodes[1].Name, makeLocalPodWithNodeSelector, immediateMode)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Context("when using local volume provisioner", func() {
|
Context("when using local volume provisioner", func() {
|
||||||
var volumePath string
|
var volumePath string
|
||||||
|
|
||||||
|
@ -424,7 +441,7 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
|
||||||
|
|
||||||
type makeLocalPodWith func(config *localTestConfig, volume *localTestVolume, nodeName string) *v1.Pod
|
type makeLocalPodWith func(config *localTestConfig, volume *localTestVolume, nodeName string) *v1.Pod
|
||||||
|
|
||||||
func testPodWithNodeName(config *localTestConfig, testVolType localVolumeType, ep *eventPatterns, nodeName string, makeLocalPodFunc makeLocalPodWith, bindingMode storagev1.VolumeBindingMode) {
|
func testPodWithNodeConflict(config *localTestConfig, testVolType localVolumeType, nodeName string, makeLocalPodFunc makeLocalPodWith, bindingMode storagev1.VolumeBindingMode) {
|
||||||
By(fmt.Sprintf("local-volume-type: %s", testVolType))
|
By(fmt.Sprintf("local-volume-type: %s", testVolType))
|
||||||
testVols := setupLocalVolumesPVCsPVs(config, testVolType, config.node0, 1, bindingMode)
|
testVols := setupLocalVolumesPVCsPVs(config, testVolType, config.node0, 1, bindingMode)
|
||||||
testVol := testVols[0]
|
testVol := testVols[0]
|
||||||
|
@ -432,9 +449,9 @@ func testPodWithNodeName(config *localTestConfig, testVolType localVolumeType, e
|
||||||
pod := makeLocalPodFunc(config, testVol, nodeName)
|
pod := makeLocalPodFunc(config, testVol, nodeName)
|
||||||
pod, err := config.client.CoreV1().Pods(config.ns).Create(pod)
|
pod, err := config.client.CoreV1().Pods(config.ns).Create(pod)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
err = framework.WaitForPodRunningInNamespace(config.client, pod)
|
|
||||||
Expect(err).To(HaveOccurred())
|
err = framework.WaitForPodNameUnschedulableInNamespace(config.client, pod.Name, pod.Namespace)
|
||||||
checkPodEvents(config, pod.Name, ep)
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
cleanupLocalVolumes(config, []*localTestVolume{testVol})
|
cleanupLocalVolumes(config, []*localTestVolume{testVol})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue