Skip to content

Commit 2c374fe

Browse files
YashasG98mrunalpagnis
authored andcommitted
Removed hardcoded function and race condition
1 parent fa12c50 commit 2c374fe

File tree

1 file changed

+12
-59
lines changed

1 file changed

+12
-59
lines changed

test/e2e/framework/pvc_util.go

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@
1515
package framework
1616

1717
import (
18-
"bytes"
1918
"fmt"
20-
"io"
2119
"k8s.io/apimachinery/pkg/labels"
22-
"k8s.io/client-go/kubernetes/scheme"
23-
"k8s.io/client-go/tools/clientcmd"
24-
"k8s.io/client-go/tools/remotecommand"
25-
"os"
26-
"path/filepath"
2720
"strings"
2821
"time"
2922

@@ -940,7 +933,7 @@ func (j *PVCTestJig) CheckDataPersistenceWithDeployment(pvcName string, ns strin
940933
podName := pods.Items[0].Name
941934

942935
By("Writing to the volume using the pod")
943-
_, _, err = j.ExecCommandOnPod(podName, writeCommand, nil, ns)
936+
_, err = RunHostCmd(ns, podName, writeCommand)
944937

945938
if err!= nil{
946939
Failf("Error executing write command a pod: %v", err)
@@ -950,7 +943,14 @@ func (j *PVCTestJig) CheckDataPersistenceWithDeployment(pvcName string, ns strin
950943
err = j.KubeClient.CoreV1().Pods(ns).Delete(podName, &metav1.DeleteOptions{})
951944

952945
if err!= nil{
953-
Failf("Error deleting pod: %v", err)
946+
Failf("Error sending pod delete request: %v", err)
947+
}
948+
949+
By("Waiting timeout for pod to not be found in namespace")
950+
err = j.waitTimeoutForPodNotFoundInNamespace(podName, ns, DefaultTimeout)
951+
952+
if err!= nil{
953+
Failf("Error deleting podt: %v", err)
954954
}
955955

956956
By("Waiting for pod to be restarted")
@@ -969,61 +969,14 @@ func (j *PVCTestJig) CheckDataPersistenceWithDeployment(pvcName string, ns strin
969969
podName = pods.Items[0].Name
970970

971971
By("Reading from the volume using the pod and checking data integrity")
972-
stdout, _, err := j.ExecCommandOnPod(podName, readCommand, nil, ns)
972+
output, err := RunHostCmd(ns, podName, readCommand)
973973

974974
if err!= nil{
975975
Failf("Error executing write command a pod: %v", err)
976976
}
977977

978-
if dataWritten != strings.TrimSpace(stdout){
979-
Failf("Written data not found on the volume, written: %v, found: %v", dataWritten, strings.TrimSpace(stdout))
980-
}
981-
982-
}
983-
984-
func (j *PVCTestJig) ExecCommandOnPod(podName string, command string, stdin io.Reader, ns string) (string, string, error) {
985-
cmd := []string{
986-
"sh",
987-
"-c",
988-
command,
989-
}
990-
991-
req := j.KubeClient.CoreV1().RESTClient().Post().Resource("pods").Name(podName).Namespace(ns).SubResource("exec")
992-
option := &v1.PodExecOptions{
993-
Command: cmd,
994-
Stdin: true,
995-
Stdout: true,
996-
Stderr: true,
997-
TTY: true,
998-
}
999-
if stdin == nil {
1000-
option.Stdin = false
1001-
}
1002-
req.VersionedParams(
1003-
option,
1004-
scheme.ParameterCodec,
1005-
)
1006-
1007-
kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config_amd")
1008-
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
1009-
1010-
if err != nil {
1011-
return "", "", fmt.Errorf("error while retrieving kubeconfig: %v", err)
1012-
}
1013-
1014-
exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
1015-
if err != nil {
1016-
return "", "", fmt.Errorf("error while creating Executor: %v", err)
1017-
}
1018-
var stdout, stderr bytes.Buffer
1019-
err = exec.Stream(remotecommand.StreamOptions{
1020-
Stdin: stdin,
1021-
Stdout: &stdout,
1022-
Stderr: &stderr,
1023-
})
1024-
if err != nil {
1025-
return "", "", fmt.Errorf("error in Stream: %v", err)
978+
if dataWritten != strings.TrimSpace(output){
979+
Failf("Written data not found on the volume, written: %v, found: %v", dataWritten, strings.TrimSpace(output))
1026980
}
1027981

1028-
return stdout.String(), stderr.String(), nil
1029982
}

0 commit comments

Comments
 (0)