mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Enable more storage tests to work independent of the providerless tag
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
parent
4b296699af
commit
fdf6503e60
26
test/e2e/storage/constants.go
Normal file
26
test/e2e/storage/constants.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
minNodes = 2
|
||||||
|
|
||||||
|
// total time to wait for cloudprovider or file system resize to finish
|
||||||
|
totalResizeWaitPeriod = 10 * time.Minute
|
||||||
|
)
|
@ -1,6 +1,3 @@
|
|||||||
//go:build !providerless
|
|
||||||
// +build !providerless
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2018 The Kubernetes Authors.
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
@ -22,9 +19,6 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
"github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@ -43,11 +37,7 @@ import (
|
|||||||
"k8s.io/kubernetes/test/e2e/storage/testsuites"
|
"k8s.io/kubernetes/test/e2e/storage/testsuites"
|
||||||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||||
admissionapi "k8s.io/pod-security-admission/api"
|
admissionapi "k8s.io/pod-security-admission/api"
|
||||||
)
|
"path"
|
||||||
|
|
||||||
const (
|
|
||||||
// total time to wait for cloudprovider or file system resize to finish
|
|
||||||
totalResizeWaitPeriod = 10 * time.Minute
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = utils.SIGDescribe(feature.Flexvolumes, "Mounted flexvolume expand", framework.WithSlow(), func() {
|
var _ = utils.SIGDescribe(feature.Flexvolumes, "Mounted flexvolume expand", framework.WithSlow(), func() {
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build !providerless
|
|
||||||
// +build !providerless
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2018 The Kubernetes Authors.
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build !providerless
|
|
||||||
// +build !providerless
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2018 The Kubernetes Authors.
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
|
133
test/e2e/storage/helpers.go
Normal file
133
test/e2e/storage/helpers.go
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2024 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
storagev1 "k8s.io/api/storage/v1"
|
||||||
|
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
"k8s.io/client-go/kubernetes"
|
||||||
|
"k8s.io/kubernetes/pkg/client/conditions"
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
|
||||||
|
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
|
||||||
|
"k8s.io/kubernetes/test/e2e/storage/testsuites"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newStorageClass(t testsuites.StorageClassTest, ns string, prefix string) *storagev1.StorageClass {
|
||||||
|
pluginName := t.Provisioner
|
||||||
|
if pluginName == "" {
|
||||||
|
pluginName = getDefaultPluginName()
|
||||||
|
}
|
||||||
|
if prefix == "" {
|
||||||
|
prefix = "sc"
|
||||||
|
}
|
||||||
|
bindingMode := storagev1.VolumeBindingImmediate
|
||||||
|
if t.DelayBinding {
|
||||||
|
bindingMode = storagev1.VolumeBindingWaitForFirstConsumer
|
||||||
|
}
|
||||||
|
if t.Parameters == nil {
|
||||||
|
t.Parameters = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if framework.NodeOSDistroIs("windows") {
|
||||||
|
// fstype might be forced from outside, in that case skip setting a default
|
||||||
|
if _, exists := t.Parameters["fstype"]; !exists {
|
||||||
|
t.Parameters["fstype"] = e2epv.GetDefaultFSType()
|
||||||
|
framework.Logf("settings a default fsType=%s in the storage class", t.Parameters["fstype"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sc := getStorageClass(pluginName, t.Parameters, &bindingMode, t.MountOptions, ns, prefix)
|
||||||
|
if t.AllowVolumeExpansion {
|
||||||
|
sc.AllowVolumeExpansion = &t.AllowVolumeExpansion
|
||||||
|
}
|
||||||
|
return sc
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultPluginName() string {
|
||||||
|
switch {
|
||||||
|
case framework.ProviderIs("gke"), framework.ProviderIs("gce"):
|
||||||
|
return "kubernetes.io/gce-pd"
|
||||||
|
case framework.ProviderIs("aws"):
|
||||||
|
return "kubernetes.io/aws-ebs"
|
||||||
|
case framework.ProviderIs("openstack"):
|
||||||
|
return "kubernetes.io/cinder"
|
||||||
|
case framework.ProviderIs("vsphere"):
|
||||||
|
return "kubernetes.io/vsphere-volume"
|
||||||
|
case framework.ProviderIs("azure"):
|
||||||
|
return "kubernetes.io/azure-disk"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStorageClass(
|
||||||
|
provisioner string,
|
||||||
|
parameters map[string]string,
|
||||||
|
bindingMode *storagev1.VolumeBindingMode,
|
||||||
|
mountOptions []string,
|
||||||
|
ns string,
|
||||||
|
prefix string,
|
||||||
|
) *storagev1.StorageClass {
|
||||||
|
if bindingMode == nil {
|
||||||
|
defaultBindingMode := storagev1.VolumeBindingImmediate
|
||||||
|
bindingMode = &defaultBindingMode
|
||||||
|
}
|
||||||
|
return &storagev1.StorageClass{
|
||||||
|
TypeMeta: v12.TypeMeta{
|
||||||
|
Kind: "StorageClass",
|
||||||
|
},
|
||||||
|
ObjectMeta: v12.ObjectMeta{
|
||||||
|
// Name must be unique, so let's base it on namespace name and the prefix (the prefix is test specific)
|
||||||
|
GenerateName: ns + "-" + prefix,
|
||||||
|
},
|
||||||
|
Provisioner: provisioner,
|
||||||
|
Parameters: parameters,
|
||||||
|
VolumeBindingMode: bindingMode,
|
||||||
|
MountOptions: mountOptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func waitForDeploymentToRecreatePod(ctx context.Context, client kubernetes.Interface, deployment *appsv1.Deployment) (v1.Pod, error) {
|
||||||
|
var runningPod v1.Pod
|
||||||
|
waitErr := wait.PollImmediate(10*time.Second, 5*time.Minute, func() (bool, error) {
|
||||||
|
podList, err := e2edeployment.GetPodsForDeployment(ctx, client, deployment)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to get pods for deployment: %w", err)
|
||||||
|
}
|
||||||
|
for _, pod := range podList.Items {
|
||||||
|
switch pod.Status.Phase {
|
||||||
|
case v1.PodRunning:
|
||||||
|
runningPod = pod
|
||||||
|
return true, nil
|
||||||
|
case v1.PodFailed, v1.PodSucceeded:
|
||||||
|
return false, conditions.ErrPodCompleted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
})
|
||||||
|
if waitErr != nil {
|
||||||
|
return runningPod, fmt.Errorf("error waiting for recreated pod: %v", waitErr)
|
||||||
|
}
|
||||||
|
return runningPod, nil
|
||||||
|
}
|
@ -1,6 +1,3 @@
|
|||||||
//go:build !providerless
|
|
||||||
// +build !providerless
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2018 The Kubernetes Authors.
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
@ -21,12 +18,8 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
"github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
storagev1 "k8s.io/api/storage/v1"
|
storagev1 "k8s.io/api/storage/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
@ -34,9 +27,7 @@ import (
|
|||||||
admissionapi "k8s.io/pod-security-admission/api"
|
admissionapi "k8s.io/pod-security-admission/api"
|
||||||
|
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/kubernetes/pkg/client/conditions"
|
|
||||||
"k8s.io/kubernetes/test/e2e/feature"
|
"k8s.io/kubernetes/test/e2e/feature"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
|
e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
|
||||||
@ -171,27 +162,3 @@ var _ = utils.SIGDescribe("Mounted volume expand", feature.StorageProvider, func
|
|||||||
gomega.Expect(pvcConditions).To(gomega.BeEmpty(), "pvc should not have conditions")
|
gomega.Expect(pvcConditions).To(gomega.BeEmpty(), "pvc should not have conditions")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func waitForDeploymentToRecreatePod(ctx context.Context, client clientset.Interface, deployment *appsv1.Deployment) (v1.Pod, error) {
|
|
||||||
var runningPod v1.Pod
|
|
||||||
waitErr := wait.PollImmediate(10*time.Second, 5*time.Minute, func() (bool, error) {
|
|
||||||
podList, err := e2edeployment.GetPodsForDeployment(ctx, client, deployment)
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("failed to get pods for deployment: %w", err)
|
|
||||||
}
|
|
||||||
for _, pod := range podList.Items {
|
|
||||||
switch pod.Status.Phase {
|
|
||||||
case v1.PodRunning:
|
|
||||||
runningPod = pod
|
|
||||||
return true, nil
|
|
||||||
case v1.PodFailed, v1.PodSucceeded:
|
|
||||||
return false, conditions.ErrPodCompleted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
})
|
|
||||||
if waitErr != nil {
|
|
||||||
return runningPod, fmt.Errorf("error waiting for recreated pod: %v", waitErr)
|
|
||||||
}
|
|
||||||
return runningPod, nil
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
//go:build !providerless
|
|
||||||
// +build !providerless
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2016 The Kubernetes Authors.
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ const (
|
|||||||
nodeStatusTimeout = 10 * time.Minute
|
nodeStatusTimeout = 10 * time.Minute
|
||||||
nodeStatusPollTime = 1 * time.Second
|
nodeStatusPollTime = 1 * time.Second
|
||||||
podEvictTimeout = 2 * time.Minute
|
podEvictTimeout = 2 * time.Minute
|
||||||
minNodes = 2
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = utils.SIGDescribe("Pod Disks", feature.StorageProvider, func() {
|
var _ = utils.SIGDescribe("Pod Disks", feature.StorageProvider, func() {
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
storagev1 "k8s.io/api/storage/v1"
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
@ -724,80 +723,6 @@ func updateDefaultStorageClass(ctx context.Context, c clientset.Interface, scNam
|
|||||||
verifyDefaultStorageClass(ctx, c, scName, expectedDefault)
|
verifyDefaultStorageClass(ctx, c, scName, expectedDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultPluginName() string {
|
|
||||||
switch {
|
|
||||||
case framework.ProviderIs("gke"), framework.ProviderIs("gce"):
|
|
||||||
return "kubernetes.io/gce-pd"
|
|
||||||
case framework.ProviderIs("aws"):
|
|
||||||
return "kubernetes.io/aws-ebs"
|
|
||||||
case framework.ProviderIs("openstack"):
|
|
||||||
return "kubernetes.io/cinder"
|
|
||||||
case framework.ProviderIs("vsphere"):
|
|
||||||
return "kubernetes.io/vsphere-volume"
|
|
||||||
case framework.ProviderIs("azure"):
|
|
||||||
return "kubernetes.io/azure-disk"
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func newStorageClass(t testsuites.StorageClassTest, ns string, prefix string) *storagev1.StorageClass {
|
|
||||||
pluginName := t.Provisioner
|
|
||||||
if pluginName == "" {
|
|
||||||
pluginName = getDefaultPluginName()
|
|
||||||
}
|
|
||||||
if prefix == "" {
|
|
||||||
prefix = "sc"
|
|
||||||
}
|
|
||||||
bindingMode := storagev1.VolumeBindingImmediate
|
|
||||||
if t.DelayBinding {
|
|
||||||
bindingMode = storagev1.VolumeBindingWaitForFirstConsumer
|
|
||||||
}
|
|
||||||
if t.Parameters == nil {
|
|
||||||
t.Parameters = make(map[string]string)
|
|
||||||
}
|
|
||||||
|
|
||||||
if framework.NodeOSDistroIs("windows") {
|
|
||||||
// fstype might be forced from outside, in that case skip setting a default
|
|
||||||
if _, exists := t.Parameters["fstype"]; !exists {
|
|
||||||
t.Parameters["fstype"] = e2epv.GetDefaultFSType()
|
|
||||||
framework.Logf("settings a default fsType=%s in the storage class", t.Parameters["fstype"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sc := getStorageClass(pluginName, t.Parameters, &bindingMode, t.MountOptions, ns, prefix)
|
|
||||||
if t.AllowVolumeExpansion {
|
|
||||||
sc.AllowVolumeExpansion = &t.AllowVolumeExpansion
|
|
||||||
}
|
|
||||||
return sc
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStorageClass(
|
|
||||||
provisioner string,
|
|
||||||
parameters map[string]string,
|
|
||||||
bindingMode *storagev1.VolumeBindingMode,
|
|
||||||
mountOptions []string,
|
|
||||||
ns string,
|
|
||||||
prefix string,
|
|
||||||
) *storagev1.StorageClass {
|
|
||||||
if bindingMode == nil {
|
|
||||||
defaultBindingMode := storagev1.VolumeBindingImmediate
|
|
||||||
bindingMode = &defaultBindingMode
|
|
||||||
}
|
|
||||||
return &storagev1.StorageClass{
|
|
||||||
TypeMeta: metav1.TypeMeta{
|
|
||||||
Kind: "StorageClass",
|
|
||||||
},
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
// Name must be unique, so let's base it on namespace name and the prefix (the prefix is test specific)
|
|
||||||
GenerateName: ns + "-" + prefix,
|
|
||||||
},
|
|
||||||
Provisioner: provisioner,
|
|
||||||
Parameters: parameters,
|
|
||||||
VolumeBindingMode: bindingMode,
|
|
||||||
MountOptions: mountOptions,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// waitForProvisionedVolumesDelete is a polling wrapper to scan all PersistentVolumes for any associated to the test's
|
// waitForProvisionedVolumesDelete is a polling wrapper to scan all PersistentVolumes for any associated to the test's
|
||||||
// StorageClass. Returns either an error and nil values or the remaining PVs and their count.
|
// StorageClass. Returns either an error and nil values or the remaining PVs and their count.
|
||||||
func waitForProvisionedVolumesDeleted(ctx context.Context, c clientset.Interface, scName string) ([]*v1.PersistentVolume, error) {
|
func waitForProvisionedVolumesDeleted(ctx context.Context, c clientset.Interface, scName string) ([]*v1.PersistentVolume, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user