forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: 126326: Add end-to-end tests for Volume Group Snapshot
- Loading branch information
Showing
13 changed files
with
1,914 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
test/e2e/storage/framework/volume_group_snapshot_resource.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
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 framework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/kubernetes/test/e2e/framework" | ||
"k8s.io/kubernetes/test/e2e/storage/utils" | ||
) | ||
|
||
func getVolumeGroupSnapshot(labels map[string]interface{}, ns, snapshotClassName string) *unstructured.Unstructured { | ||
snapshot := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"kind": "VolumeGroupSnapshot", | ||
"apiVersion": utils.VolumeGroupSnapshotAPIVersion, | ||
"metadata": map[string]interface{}{ | ||
"generateName": "group-snapshot-", | ||
"namespace": ns, | ||
}, | ||
"spec": map[string]interface{}{ | ||
"volumeGroupSnapshotClassName": snapshotClassName, | ||
"source": map[string]interface{}{ | ||
"selector": map[string]interface{}{ | ||
"matchLabels": labels, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return snapshot | ||
} | ||
|
||
// VolumeGroupSnapshotResource represents a volumegroupsnapshot class, a volumegroupsnapshot and its bound contents for a specific test case | ||
type VolumeGroupSnapshotResource struct { | ||
Config *PerTestConfig | ||
Pattern TestPattern | ||
|
||
Vgs *unstructured.Unstructured | ||
Vgscontent *unstructured.Unstructured | ||
Vgsclass *unstructured.Unstructured | ||
} | ||
|
||
// CreateVolumeGroupSnapshot creates a VolumeGroupSnapshotClass with given SnapshotDeletionPolicy and a VolumeGroupSnapshot | ||
// from the VolumeGroupSnapshotClass using a dynamic client. | ||
// Returns the unstructured VolumeGroupSnapshotClass and VolumeGroupSnapshot objects. | ||
func CreateVolumeGroupSnapshot(ctx context.Context, sDriver VoulmeGroupSnapshottableTestDriver, config *PerTestConfig, pattern TestPattern, groupName string, pvcNamespace string, timeouts *framework.TimeoutContext, parameters map[string]string) (*unstructured.Unstructured, *unstructured.Unstructured) { | ||
defer ginkgo.GinkgoRecover() | ||
var err error | ||
if pattern.SnapshotType != VolumeGroupSnapshot { | ||
err = fmt.Errorf("SnapshotType must be set to VolumeGroupSnapshot") | ||
framework.ExpectNoError(err, "SnapshotType is set to VolumeGroupSnapshot") | ||
} | ||
dc := config.Framework.DynamicClient | ||
|
||
ginkgo.By("creating a VolumeGroupSnapshotClass") | ||
gsclass := sDriver.GetVolumeGroupSnapshotClass(ctx, config, parameters) | ||
if gsclass == nil { | ||
framework.Failf("Failed to get volume group snapshot class based on test config") | ||
} | ||
gsclass.Object["deletionPolicy"] = pattern.SnapshotDeletionPolicy.String() | ||
|
||
gsclass, err = dc.Resource(utils.VolumeGroupSnapshotClassGVR).Create(ctx, gsclass, metav1.CreateOptions{}) | ||
framework.ExpectNoError(err, "Failed to create volume group snapshot class") | ||
gsclass, err = dc.Resource(utils.VolumeGroupSnapshotClassGVR).Get(ctx, gsclass.GetName(), metav1.GetOptions{}) | ||
framework.ExpectNoError(err, "Failed to get volume group snapshot class") | ||
|
||
ginkgo.By("creating a dynamic VolumeGroupSnapshot") | ||
// Prepare a dynamically provisioned group volume snapshot with certain data | ||
volumeGroupSnapshot := getVolumeGroupSnapshot(map[string]interface{}{ | ||
"group": groupName, | ||
}, pvcNamespace, gsclass.GetName()) | ||
|
||
volumeGroupSnapshot, err = dc.Resource(utils.VolumeGroupSnapshotGVR).Namespace(volumeGroupSnapshot.GetNamespace()).Create(ctx, volumeGroupSnapshot, metav1.CreateOptions{}) | ||
framework.ExpectNoError(err, "Failed to create volume group snapshot") | ||
ginkgo.By("Waiting for group snapshot to be ready") | ||
err = utils.WaitForVolumeGroupSnapshotReady(ctx, dc, volumeGroupSnapshot.GetNamespace(), volumeGroupSnapshot.GetName(), framework.Poll, timeouts.SnapshotCreate*10) | ||
framework.ExpectNoError(err, "Group snapshot is not ready to use within the timeout") | ||
ginkgo.By("Getting group snapshot and content") | ||
volumeGroupSnapshot, err = dc.Resource(utils.VolumeGroupSnapshotGVR).Namespace(volumeGroupSnapshot.GetNamespace()).Get(ctx, volumeGroupSnapshot.GetName(), metav1.GetOptions{}) | ||
framework.ExpectNoError(err, "Failed to get volume group snapshot after creation") | ||
|
||
return gsclass, volumeGroupSnapshot | ||
} | ||
|
||
// CleanupResource deletes the VolumeGroupSnapshotClass and VolumeGroupSnapshot objects using a dynamic client. | ||
func (r *VolumeGroupSnapshotResource) CleanupResource(ctx context.Context, timeouts *framework.TimeoutContext) error { | ||
defer ginkgo.GinkgoRecover() | ||
dc := r.Config.Framework.DynamicClient | ||
err := dc.Resource(utils.VolumeGroupSnapshotClassGVR).Delete(ctx, r.Vgsclass.GetName(), metav1.DeleteOptions{}) | ||
framework.ExpectNoError(err, "Failed to delete volume group snapshot class") | ||
return nil | ||
} | ||
|
||
// CreateVolumeGroupSnapshotResource creates a VolumeGroupSnapshotResource object with the given parameters. | ||
func CreateVolumeGroupSnapshotResource(ctx context.Context, sDriver VoulmeGroupSnapshottableTestDriver, config *PerTestConfig, pattern TestPattern, pvcName string, pvcNamespace string, timeouts *framework.TimeoutContext, parameters map[string]string) *VolumeGroupSnapshotResource { | ||
vgsclass, snapshot := CreateVolumeGroupSnapshot(ctx, sDriver, config, pattern, pvcName, pvcNamespace, timeouts, parameters) | ||
vgs := &VolumeGroupSnapshotResource{ | ||
Config: config, | ||
Pattern: pattern, | ||
Vgs: snapshot, | ||
Vgsclass: vgsclass, | ||
Vgscontent: nil, | ||
} | ||
return vgs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.