Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pod with deployment in E2E test #6644

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/basic/pvc-selected-node-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (p *PVCSelectedNodeChanging) Restore() error {
}
func (p *PVCSelectedNodeChanging) Verify() error {
By(fmt.Sprintf("PVC selected node should be %s", p.newNodeName), func() {
pvcNameList, err := GetPvcByPodName(p.Ctx, p.mappedNS, p.pvcName)
pvcNameList, err := GetPvcByPVCName(p.Ctx, p.mappedNS, p.pvcName)
Expect(err).To(Succeed())
Expect(len(pvcNameList)).Should(Equal(1))
pvc, err := GetPVC(p.Ctx, p.Client, p.mappedNS, pvcNameList[0])
Expand Down
40 changes: 27 additions & 13 deletions test/e2e/basic/storage-class-changing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ type StorageClasssChanging struct {
namespace string
srcStorageClass string
desStorageClass string
pvcName string
volume string
podName string
mappedNS string
deploymentName string
}

const SCCBaseName string = "scc-"
Expand Down Expand Up @@ -55,6 +57,7 @@ func (s *StorageClasssChanging) Init() error {
s.data = map[string]string{s.srcStorageClass: s.desStorageClass}
s.configmaptName = "change-storage-class-config"
s.volume = "volume-1"
s.pvcName = fmt.Sprintf("pvc-%s", s.volume)
s.podName = "pod-1"
s.BackupArgs = []string{
"create", "--namespace", VeleroCfg.VeleroNamespace, "backup", s.BackupName,
Expand All @@ -68,6 +71,9 @@ func (s *StorageClasssChanging) Init() error {
return nil
}
func (s *StorageClasssChanging) CreateResources() error {
label := map[string]string{
"app": "test",
}
s.Ctx, s.CtxCancel = context.WithTimeout(context.Background(), 10*time.Minute)
By(fmt.Sprintf("Create a storage class %s", s.desStorageClass), func() {
Expect(InstallStorageClass(s.Ctx, fmt.Sprintf("../testdata/storage-class/%s.yaml",
Expand All @@ -78,10 +84,20 @@ func (s *StorageClasssChanging) CreateResources() error {
fmt.Sprintf("Failed to create namespace %s", s.namespace))
})

By(fmt.Sprintf("Create pod %s in namespace %s", s.podName, s.namespace), func() {
_, err := CreatePod(s.Client, s.namespace, s.podName, s.srcStorageClass, "", []string{s.volume}, nil, nil)
By(fmt.Sprintf("Create a deployment in namespace %s", s.VeleroCfg.VeleroNamespace), func() {

pvc, err := CreatePVC(s.Client, s.namespace, s.pvcName, s.srcStorageClass, nil)
Expect(err).To(Succeed())
vols := CreateVolumes(pvc.Name, []string{s.volume})

deployment := NewDeployment(s.CaseBaseName, s.namespace, 1, label, nil).WithVolume(vols).Result()
deployment, err = CreateDeployment(s.Client.ClientGo, s.namespace, deployment)
Expect(err).To(Succeed())
s.deploymentName = deployment.Name
err = WaitForReadyDeployment(s.Client.ClientGo, s.namespace, s.deploymentName)
Expect(err).To(Succeed())
})

By(fmt.Sprintf("Create ConfigMap %s in namespace %s", s.configmaptName, s.VeleroCfg.VeleroNamespace), func() {
_, err := CreateConfigMap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.configmaptName, s.labels, s.data)
Expect(err).To(Succeed(), fmt.Sprintf("failed to create configmap in the namespace %q", s.VeleroCfg.VeleroNamespace))
Expand All @@ -91,19 +107,14 @@ func (s *StorageClasssChanging) CreateResources() error {

func (s *StorageClasssChanging) Destroy() error {
By(fmt.Sprintf("Expect storage class of PV %s to be %s ", s.volume, s.srcStorageClass), func() {
pvName, err := GetPVByPodName(s.Client, s.namespace, s.volume)
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV name by pod name %s", s.podName))
pvName, err := GetPVByPVCName(s.Client, s.namespace, s.pvcName)
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV name by PVC name %s", s.pvcName))
pv, err := GetPersistentVolume(s.Ctx, s.Client, s.namespace, pvName)
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV by pod name %s", s.podName))
fmt.Println(pv)
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV by name %s", pvName))
Expect(pv.Spec.StorageClassName).To(Equal(s.srcStorageClass),
fmt.Sprintf("PV storage %s is not as expected %s", pv.Spec.StorageClassName, s.srcStorageClass))
})

By(fmt.Sprintf("Start to destroy namespace %s......", s.CaseBaseName), func() {
Expect(CleanupNamespacesWithPoll(s.Ctx, s.Client, s.CaseBaseName)).To(Succeed(),
fmt.Sprintf("Failed to delete namespace %s", s.CaseBaseName))
})
return nil
}

Expand All @@ -123,12 +134,11 @@ func (s *StorageClasssChanging) Restore() error {
}
func (s *StorageClasssChanging) Verify() error {
By(fmt.Sprintf("Expect storage class of PV %s to be %s ", s.volume, s.desStorageClass), func() {
Expect(WaitForPods(s.Ctx, s.Client, s.mappedNS, []string{s.podName})).To(Succeed(), fmt.Sprintf("Failed to wait pod ready %s", s.podName))
pvName, err := GetPVByPodName(s.Client, s.mappedNS, s.volume)
Expect(WaitForReadyDeployment(s.Client.ClientGo, s.mappedNS, s.deploymentName)).To(Succeed())
pvName, err := GetPVByPVCName(s.Client, s.mappedNS, s.pvcName)
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV name by pod name %s", s.podName))
pv, err := GetPersistentVolume(s.Ctx, s.Client, s.mappedNS, pvName)
Expect(err).To(Succeed(), fmt.Sprintf("Failed to get PV by pod name %s", s.podName))
fmt.Println(pv)
Expect(pv.Spec.StorageClassName).To(Equal(s.desStorageClass),
fmt.Sprintf("PV storage %s is not as expected %s", pv.Spec.StorageClassName, s.desStorageClass))
})
Expand All @@ -137,6 +147,10 @@ func (s *StorageClasssChanging) Verify() error {

func (s *StorageClasssChanging) Clean() error {
if !s.VeleroCfg.Debug {
By(fmt.Sprintf("Start to destroy namespace %s......", s.CaseBaseName), func() {
Expect(CleanupNamespacesWithPoll(s.Ctx, s.Client, s.CaseBaseName)).To(Succeed(),
fmt.Sprintf("Failed to delete namespace %s", s.CaseBaseName))
})
DeleteConfigmap(s.Client.ClientGo, s.VeleroCfg.VeleroNamespace, s.configmaptName)
DeleteStorageClass(s.Ctx, s.Client, s.desStorageClass)
s.TestCase.Clean()
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/bsl-mgmt/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ func BslDeletionTest(useVolumeSnapshots bool) {
})

By("Get all 2 PVCs of Kibishii and label them seprately ", func() {
pvc, err := GetPvcByPodName(context.Background(), bslDeletionTestNs, podName_1)
pvc, err := GetPvcByPVCName(context.Background(), bslDeletionTestNs, podName_1)
Expect(err).To(Succeed())
fmt.Println(pvc)
Expect(len(pvc)).To(Equal(1))
pvc1 := pvc[0]
pvc, err = GetPvcByPodName(context.Background(), bslDeletionTestNs, podName_2)
pvc, err = GetPvcByPVCName(context.Background(), bslDeletionTestNs, podName_2)
Expect(err).To(Succeed())
fmt.Println(pvc)
Expect(len(pvc)).To(Equal(1))
Expand Down
2 changes: 1 addition & 1 deletion test/util/csi/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func GetCsiSnapshotHandleV1(client TestClient, backupName string) ([]string, err
return snapshotHandleList, nil
}
func GetVolumeSnapshotContentNameByPod(client TestClient, podName, namespace, backupName string) (string, error) {
pvcList, err := GetPvcByPodName(context.Background(), namespace, podName)
pvcList, err := GetPvcByPVCName(context.Background(), namespace, podName)
if err != nil {
return "", err
}
Expand Down
28 changes: 22 additions & 6 deletions test/util/k8s/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func WaitForPods(ctx context.Context, client TestClient, namespace string, pods
return nil
}

func GetPvcByPodName(ctx context.Context, namespace, podName string) ([]string, error) {
func GetPvcByPVCName(ctx context.Context, namespace, pvcName string) ([]string, error) {
// Example:
// NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
// kibishii-data-kibishii-deployment-0 Bound pvc-94b9fdf2-c30f-4a7b-87bf-06eadca0d5b6 1Gi RWO kibishii-storage-class 115s
Expand All @@ -94,7 +94,7 @@ func GetPvcByPodName(ctx context.Context, namespace, podName string) ([]string,

cmd = &common.OsCommandLine{
Cmd: "grep",
Args: []string{podName},
Args: []string{pvcName},
}
cmds = append(cmds, cmd)

Expand Down Expand Up @@ -233,20 +233,20 @@ func GetAPIVersions(client *TestClient, name string) ([]string, error) {
return nil, errors.New("Server API groups is empty")
}

func GetPVByPodName(client TestClient, namespace, podName string) (string, error) {
pvcList, err := GetPvcByPodName(context.Background(), namespace, podName)
func GetPVByPVCName(client TestClient, namespace, pvcName string) (string, error) {
pvcList, err := GetPvcByPVCName(context.Background(), namespace, pvcName)
if err != nil {
return "", err
}
if len(pvcList) != 1 {
return "", errors.New(fmt.Sprintf("Only 1 PVC of pod %s should be found under namespace %s but got %v", podName, namespace, pvcList))
return "", errors.New(fmt.Sprintf("Only 1 PVC of pod %s should be found under namespace %s but got %v", pvcName, namespace, pvcList))
}
pvList, err := GetPvByPvc(context.Background(), namespace, pvcList[0])
if err != nil {
return "", err
}
if len(pvList) != 1 {
return "", errors.New(fmt.Sprintf("Only 1 PV of PVC %s pod %s should be found under namespace %s", pvcList[0], podName, namespace))
return "", errors.New(fmt.Sprintf("Only 1 PV of PVC %s pod %s should be found under namespace %s", pvcList[0], pvcName, namespace))
}
pv_value, err := GetPersistentVolume(context.Background(), client, "", pvList[0])
fmt.Println(pv_value.Annotations["pv.kubernetes.io/provisioned-by"])
Expand Down Expand Up @@ -347,3 +347,19 @@ func GetAllService(ctx context.Context) (string, error) {
}
return stdout, nil
}

func CreateVolumes(pvcName string, volumeNameList []string) (vols []*corev1.Volume) {
vols = []*corev1.Volume{}
for _, volume := range volumeNameList {
vols = append(vols, &corev1.Volume{
Name: volume,
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: pvcName,
ReadOnly: false,
},
},
})
}
return
}
8 changes: 4 additions & 4 deletions test/util/k8s/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ func NewDeployment(name, ns string, replicas int32, labels map[string]string, co
}
}

func (d *DeploymentBuilder) WithVolume(vols []*v1.Volume) *DeploymentBuilder {
func (d *DeploymentBuilder) WithVolume(volumes []*v1.Volume) *DeploymentBuilder {
vmList := []v1.VolumeMount{}
for i, v := range vols {
for _, v := range volumes {
vmList = append(vmList, v1.VolumeMount{
Name: v.Name,
MountPath: "/" + v.Name,
})
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, *vols[i])
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, *v)

}

// NOTE here just mount volumes to the first container
d.Spec.Template.Spec.Containers[0].VolumeMounts = vmList

return d
}

Expand Down
Loading