Unverified Commit 49b0daeb authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #60137 from ianchakeres/e2e-local-block

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. e2e tests for local-volume plugin block devices **What this PR does / why we need it**: This PR contains e2e tests for local block devices, and it leverages the `BlockVolume` feature-gate. This PR can help us avoid regressions for local block volumes. For example, #60025. **Which issue(s) this PR fixes** : Fixes https://github.com/kubernetes/kubernetes/issues/60141 **Special notes for your reviewer**: These tests can be run with the following commands: ``` KUBE_FEATURE_GATES="MountPropagation=true,BlockVolume=true" NUM_NODES=1 go run hack/e2e.go -- --up go run hack/e2e.go -- -v --test --test_args="--ginkgo.focus=PersistentVolumes-local.*block” ``` **Release note**: ```release-note NONE ```
parents f351d8cd 4812f9e5
...@@ -61,7 +61,7 @@ func (v VolumePathHandler) GetLoopDevice(path string) (string, error) { ...@@ -61,7 +61,7 @@ func (v VolumePathHandler) GetLoopDevice(path string) (string, error) {
cmd := exec.Command(losetupPath, args...) cmd := exec.Command(losetupPath, args...)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
glog.V(2).Infof("Failed device discover command for path %s: %v", path, err) glog.V(2).Infof("Failed device discover command for path %s: %v %s", path, err, out)
return "", err return "", err
} }
return parseLosetupOutputForDevice(out) return parseLosetupOutputForDevice(out)
...@@ -72,7 +72,7 @@ func makeLoopDevice(path string) (string, error) { ...@@ -72,7 +72,7 @@ func makeLoopDevice(path string) (string, error) {
cmd := exec.Command(losetupPath, args...) cmd := exec.Command(losetupPath, args...)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
glog.V(2).Infof("Failed device create command for path %s: %v", path, err) glog.V(2).Infof("Failed device create command for path: %s %v %s ", path, err, out)
return "", err return "", err
} }
return parseLosetupOutputForDevice(out) return parseLosetupOutputForDevice(out)
......
...@@ -81,6 +81,7 @@ type PersistentVolumeConfig struct { ...@@ -81,6 +81,7 @@ type PersistentVolumeConfig struct {
Labels labels.Set Labels labels.Set
StorageClassName string StorageClassName string
NodeAffinity *v1.VolumeNodeAffinity NodeAffinity *v1.VolumeNodeAffinity
VolumeMode *v1.PersistentVolumeMode
} }
// PersistentVolumeClaimConfig is consumed by MakePersistentVolumeClaim() to generate a PVC object. // PersistentVolumeClaimConfig is consumed by MakePersistentVolumeClaim() to generate a PVC object.
...@@ -92,6 +93,7 @@ type PersistentVolumeClaimConfig struct { ...@@ -92,6 +93,7 @@ type PersistentVolumeClaimConfig struct {
Annotations map[string]string Annotations map[string]string
Selector *metav1.LabelSelector Selector *metav1.LabelSelector
StorageClassName *string StorageClassName *string
VolumeMode *v1.PersistentVolumeMode
} }
// Clean up a pv and pvc in a single pv/pvc test case. // Clean up a pv and pvc in a single pv/pvc test case.
...@@ -581,7 +583,7 @@ func MakePersistentVolume(pvConfig PersistentVolumeConfig) *v1.PersistentVolume ...@@ -581,7 +583,7 @@ func MakePersistentVolume(pvConfig PersistentVolumeConfig) *v1.PersistentVolume
Namespace: pvConfig.Prebind.Namespace, Namespace: pvConfig.Prebind.Namespace,
} }
} }
pv := &v1.PersistentVolume{ return &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
GenerateName: pvConfig.NamePrefix, GenerateName: pvConfig.NamePrefix,
Labels: pvConfig.Labels, Labels: pvConfig.Labels,
...@@ -603,9 +605,9 @@ func MakePersistentVolume(pvConfig PersistentVolumeConfig) *v1.PersistentVolume ...@@ -603,9 +605,9 @@ func MakePersistentVolume(pvConfig PersistentVolumeConfig) *v1.PersistentVolume
ClaimRef: claimRef, ClaimRef: claimRef,
StorageClassName: pvConfig.StorageClassName, StorageClassName: pvConfig.StorageClassName,
NodeAffinity: pvConfig.NodeAffinity, NodeAffinity: pvConfig.NodeAffinity,
VolumeMode: pvConfig.VolumeMode,
}, },
} }
return pv
} }
// Returns a PVC definition based on the namespace. // Returns a PVC definition based on the namespace.
...@@ -635,6 +637,7 @@ func MakePersistentVolumeClaim(cfg PersistentVolumeClaimConfig, ns string) *v1.P ...@@ -635,6 +637,7 @@ func MakePersistentVolumeClaim(cfg PersistentVolumeClaimConfig, ns string) *v1.P
}, },
}, },
StorageClassName: cfg.StorageClassName, StorageClassName: cfg.StorageClassName,
VolumeMode: cfg.VolumeMode,
}, },
} }
} }
...@@ -868,14 +871,21 @@ func MakeSecPod(ns string, pvclaims []*v1.PersistentVolumeClaim, isPrivileged bo ...@@ -868,14 +871,21 @@ func MakeSecPod(ns string, pvclaims []*v1.PersistentVolumeClaim, isPrivileged bo
RestartPolicy: v1.RestartPolicyOnFailure, RestartPolicy: v1.RestartPolicyOnFailure,
}, },
} }
var volumeMounts = make([]v1.VolumeMount, len(pvclaims)) var volumeMounts = make([]v1.VolumeMount, 0)
var volumeDevices = make([]v1.VolumeDevice, 0)
var volumes = make([]v1.Volume, len(pvclaims)) var volumes = make([]v1.Volume, len(pvclaims))
for index, pvclaim := range pvclaims { for index, pvclaim := range pvclaims {
volumename := fmt.Sprintf("volume%v", index+1) volumename := fmt.Sprintf("volume%v", index+1)
volumeMounts[index] = v1.VolumeMount{Name: volumename, MountPath: "/mnt/" + volumename} if pvclaim.Spec.VolumeMode != nil && *pvclaim.Spec.VolumeMode == v1.PersistentVolumeBlock {
volumeDevices = append(volumeDevices, v1.VolumeDevice{Name: volumename, DevicePath: "/mnt/" + volumename})
} else {
volumeMounts = append(volumeMounts, v1.VolumeMount{Name: volumename, MountPath: "/mnt/" + volumename})
}
volumes[index] = v1.Volume{Name: volumename, VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvclaim.Name, ReadOnly: false}}} volumes[index] = v1.Volume{Name: volumename, VolumeSource: v1.VolumeSource{PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvclaim.Name, ReadOnly: false}}}
} }
podSpec.Spec.Containers[0].VolumeMounts = volumeMounts podSpec.Spec.Containers[0].VolumeMounts = volumeMounts
podSpec.Spec.Containers[0].VolumeDevices = volumeDevices
podSpec.Spec.Volumes = volumes podSpec.Spec.Volumes = volumes
podSpec.Spec.SecurityContext.SELinuxOptions = seLinuxLabel podSpec.Spec.SecurityContext.SELinuxOptions = seLinuxLabel
return podSpec return podSpec
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment