mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #42829 from msau42/multizone_pv_tests
Automatic merge from submit-queue (batch tested with PRs 46972, 42829, 46799, 46802, 46844) Multizone static pv test **What this PR does / why we need it**: Adds an e2e test for checking that pods get scheduled to the same zone as statically created PVs. This tests the PersistentVolumeLabel admission controller, which adds zone and region labels when PVs are created. As part of this, I also had to make changes to volume test utility code to pass in a zone parameter for creating PDs, and also had to add an argument to the e2e test program to accept a list of zones. Fixes #46995 **Special notes for your reviewer**: It's probably easier to review each commit separately. **Release note**: NONE
This commit is contained in:
commit
1c64f31fdb
@ -641,10 +641,10 @@ func MakePersistentVolumeClaim(cfg PersistentVolumeClaimConfig, ns string) *v1.P
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePDWithRetry() (string, error) {
|
||||
func createPDWithRetry(zone string) (string, error) {
|
||||
var err error
|
||||
for start := time.Now(); time.Since(start) < PDRetryTimeout; time.Sleep(PDRetryPollTime) {
|
||||
newDiskName, err := createPD()
|
||||
newDiskName, err := createPD(zone)
|
||||
if err != nil {
|
||||
Logf("Couldn't create a new PD, sleeping 5 seconds: %v", err)
|
||||
continue
|
||||
@ -655,6 +655,14 @@ func CreatePDWithRetry() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
func CreatePDWithRetry() (string, error) {
|
||||
return createPDWithRetry("")
|
||||
}
|
||||
|
||||
func CreatePDWithRetryAndZone(zone string) (string, error) {
|
||||
return createPDWithRetry(zone)
|
||||
}
|
||||
|
||||
func DeletePDWithRetry(diskName string) error {
|
||||
var err error
|
||||
for start := time.Now(); time.Since(start) < PDRetryTimeout; time.Sleep(PDRetryPollTime) {
|
||||
@ -669,7 +677,11 @@ func DeletePDWithRetry(diskName string) error {
|
||||
return fmt.Errorf("unable to delete PD %q: %v", diskName, err)
|
||||
}
|
||||
|
||||
func createPD() (string, error) {
|
||||
func createPD(zone string) (string, error) {
|
||||
if zone == "" {
|
||||
zone = TestContext.CloudConfig.Zone
|
||||
}
|
||||
|
||||
if TestContext.Provider == "gce" || TestContext.Provider == "gke" {
|
||||
pdName := fmt.Sprintf("%s-%s", TestContext.Prefix, string(uuid.NewUUID()))
|
||||
|
||||
@ -679,7 +691,7 @@ func createPD() (string, error) {
|
||||
}
|
||||
|
||||
tags := map[string]string{}
|
||||
err = gceCloud.CreateDisk(pdName, gcecloud.DiskTypeSSD, TestContext.CloudConfig.Zone, 10 /* sizeGb */, tags)
|
||||
err = gceCloud.CreateDisk(pdName, gcecloud.DiskTypeSSD, zone, 10 /* sizeGb */, tags)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -688,7 +700,7 @@ func createPD() (string, error) {
|
||||
client := ec2.New(session.New())
|
||||
|
||||
request := &ec2.CreateVolumeInput{}
|
||||
request.AvailabilityZone = aws.String(TestContext.CloudConfig.Zone)
|
||||
request.AvailabilityZone = aws.String(zone)
|
||||
request.Size = aws.Int64(10)
|
||||
request.VolumeType = aws.String(awscloud.DefaultVolumeType)
|
||||
response, err := client.CreateVolume(request)
|
||||
@ -865,3 +877,39 @@ func WaitForPVClaimBoundPhase(client clientset.Interface, pvclaims []*v1.Persist
|
||||
}
|
||||
return persistentvolumes, nil
|
||||
}
|
||||
|
||||
func CreatePVSource(zone string) (*v1.PersistentVolumeSource, error) {
|
||||
diskName, err := CreatePDWithRetryAndZone(zone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if TestContext.Provider == "gce" || TestContext.Provider == "gke" {
|
||||
return &v1.PersistentVolumeSource{
|
||||
GCEPersistentDisk: &v1.GCEPersistentDiskVolumeSource{
|
||||
PDName: diskName,
|
||||
FSType: "ext3",
|
||||
ReadOnly: false,
|
||||
},
|
||||
}, nil
|
||||
} else if TestContext.Provider == "aws" {
|
||||
return &v1.PersistentVolumeSource{
|
||||
AWSElasticBlockStore: &v1.AWSElasticBlockStoreVolumeSource{
|
||||
VolumeID: diskName,
|
||||
FSType: "ext3",
|
||||
},
|
||||
}, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("Provider not supported")
|
||||
}
|
||||
}
|
||||
|
||||
func DeletePVSource(pvSource *v1.PersistentVolumeSource) error {
|
||||
if TestContext.Provider == "gce" || TestContext.Provider == "gke" {
|
||||
return DeletePDWithRetry(pvSource.GCEPersistentDisk.PDName)
|
||||
} else if TestContext.Provider == "aws" {
|
||||
return DeletePDWithRetry(pvSource.AWSElasticBlockStore.VolumeID)
|
||||
} else {
|
||||
return fmt.Errorf("Provider not supported")
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,10 @@ var _ = framework.KubeDescribe("Multi-AZ Clusters", func() {
|
||||
It("should spread the pods of a replication controller across zones", func() {
|
||||
SpreadRCOrFail(f, int32((2*zoneCount)+1), image)
|
||||
})
|
||||
|
||||
It("should schedule pods in the same zones as statically provisioned PVs", func() {
|
||||
PodsUseStaticPVsOrFail(f, (2*zoneCount)+1, image)
|
||||
})
|
||||
})
|
||||
|
||||
// Check that the pods comprising a service get spread evenly across available zones
|
||||
@ -241,3 +245,78 @@ func SpreadRCOrFail(f *framework.Framework, replicaCount int32, image string) {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(checkZoneSpreading(f.ClientSet, pods, zoneNames)).To(Equal(true))
|
||||
}
|
||||
|
||||
type StaticPVTestConfig struct {
|
||||
pvSource *v1.PersistentVolumeSource
|
||||
pv *v1.PersistentVolume
|
||||
pvc *v1.PersistentVolumeClaim
|
||||
pod *v1.Pod
|
||||
}
|
||||
|
||||
// Check that the pods using statically created PVs get scheduled to the same zone that the PV is in.
|
||||
func PodsUseStaticPVsOrFail(f *framework.Framework, podCount int, image string) {
|
||||
// TODO: add GKE after enabling admission plugin in GKE
|
||||
// TODO: add AWS
|
||||
framework.SkipUnlessProviderIs("gce")
|
||||
|
||||
var err error
|
||||
c := f.ClientSet
|
||||
ns := f.Namespace.Name
|
||||
|
||||
zones, err := getZoneNames(c)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating static PVs across zones")
|
||||
configs := make([]*StaticPVTestConfig, podCount)
|
||||
for i := range configs {
|
||||
configs[i] = &StaticPVTestConfig{}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
By("Cleaning up pods and PVs")
|
||||
for _, config := range configs {
|
||||
framework.DeletePodOrFail(c, ns, config.pod.Name)
|
||||
}
|
||||
for _, config := range configs {
|
||||
framework.WaitForPodNoLongerRunningInNamespace(c, config.pod.Name, ns)
|
||||
framework.PVPVCCleanup(c, ns, config.pv, config.pvc)
|
||||
err = framework.DeletePVSource(config.pvSource)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
}()
|
||||
|
||||
for i, config := range configs {
|
||||
zone := zones[i%len(zones)]
|
||||
config.pvSource, err = framework.CreatePVSource(zone)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
pvConfig := framework.PersistentVolumeConfig{
|
||||
NamePrefix: "multizone-pv",
|
||||
PVSource: *config.pvSource,
|
||||
Prebind: nil,
|
||||
}
|
||||
className := ""
|
||||
pvcConfig := framework.PersistentVolumeClaimConfig{StorageClassName: &className}
|
||||
|
||||
config.pv, config.pvc, err = framework.CreatePVPVC(c, pvConfig, pvcConfig, ns, true)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
By("Waiting for all PVCs to be bound")
|
||||
for _, config := range configs {
|
||||
framework.WaitOnPVandPVC(c, ns, config.pv, config.pvc)
|
||||
}
|
||||
|
||||
By("Creating pods for each static PV")
|
||||
for _, config := range configs {
|
||||
podConfig := framework.MakePod(ns, []*v1.PersistentVolumeClaim{config.pvc}, false, "")
|
||||
config.pod, err = c.Core().Pods(ns).Create(podConfig)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
By("Waiting for all pods to be running")
|
||||
for _, config := range configs {
|
||||
err = framework.WaitForPodRunningInNamespace(c, config.pod)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user