diff --git a/pkg/csi/csi_ops.go b/pkg/csi/csi_ops.go index 2695ace..7316731 100644 --- a/pkg/csi/csi_ops.go +++ b/pkg/csi/csi_ops.go @@ -475,18 +475,18 @@ func (p *apiVersionFetch) GetCSISnapshotGroupVersion() (*metav1.GroupVersionForD //go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_data_validator.go -package=mocks . DataValidator type DataValidator interface { - FetchPodData(podName string, podNamespace string) (string, error) + FetchPodData(ctx context.Context, podName string, podNamespace string) (string, error) } type validateData struct { kubeCli kubernetes.Interface } -func (p *validateData) FetchPodData(podName string, podNamespace string) (string, error) { +func (p *validateData) FetchPodData(ctx context.Context, podName string, podNamespace string) (string, error) { if p.kubeCli == nil { return "", fmt.Errorf("kubeCli not initialized") } - stdout, _, err := kankube.Exec(p.kubeCli, podNamespace, podName, "", []string{"sh", "-c", "cat /data/out.txt"}, nil) + stdout, _, err := kankube.Exec(ctx, p.kubeCli, podNamespace, podName, "", []string{"sh", "-c", "cat /data/out.txt"}, nil) return stdout, err } diff --git a/pkg/csi/mocks/mock_data_validator.go b/pkg/csi/mocks/mock_data_validator.go index bb87cd8..2cd7f3b 100644 --- a/pkg/csi/mocks/mock_data_validator.go +++ b/pkg/csi/mocks/mock_data_validator.go @@ -5,6 +5,7 @@ package mocks import ( + context "context" reflect "reflect" gomock "github.com/golang/mock/gomock" @@ -34,16 +35,16 @@ func (m *MockDataValidator) EXPECT() *MockDataValidatorMockRecorder { } // FetchPodData mocks base method. -func (m *MockDataValidator) FetchPodData(arg0, arg1 string) (string, error) { +func (m *MockDataValidator) FetchPodData(arg0 context.Context, arg1, arg2 string) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FetchPodData", arg0, arg1) + ret := m.ctrl.Call(m, "FetchPodData", arg0, arg1, arg2) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } // FetchPodData indicates an expected call of FetchPodData. -func (mr *MockDataValidatorMockRecorder) FetchPodData(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockDataValidatorMockRecorder) FetchPodData(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchPodData", reflect.TypeOf((*MockDataValidator)(nil).FetchPodData), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchPodData", reflect.TypeOf((*MockDataValidator)(nil).FetchPodData), arg0, arg1, arg2) } diff --git a/pkg/csi/snapshot_restore.go b/pkg/csi/snapshot_restore.go index ae4765e..e2adcb9 100644 --- a/pkg/csi/snapshot_restore.go +++ b/pkg/csi/snapshot_restore.go @@ -203,7 +203,7 @@ func (s *snapshotRestoreSteps) CreateApplication(ctx context.Context, args *type } func (s *snapshotRestoreSteps) ValidateData(ctx context.Context, pod *v1.Pod, data string) error { - podData, err := s.dataValidatorOps.FetchPodData(pod.Name, pod.Namespace) + podData, err := s.dataValidatorOps.FetchPodData(ctx, pod.Name, pod.Namespace) if err != nil { return errors.Wrap(err, "Failed to fetch data from pod. Failure may be due to permissions issues. Try again with runAsUser=1000 option.") } diff --git a/pkg/fio/fio.go b/pkg/fio/fio.go index eb00950..c36361d 100644 --- a/pkg/fio/fio.go +++ b/pkg/fio/fio.go @@ -334,7 +334,7 @@ func (s *fioStepper) runFIOCommand(ctx context.Context, podName, containerName, var err error timestart := time.Now() go func() { - stdout, stderr, err = s.kubeExecutor.exec(namespace, podName, containerName, command) + stdout, stderr, err = s.kubeExecutor.exec(ctx, namespace, podName, containerName, command) if err != nil || stderr != "" { if err == nil { err = fmt.Errorf("stderr when running FIO") @@ -393,13 +393,13 @@ func (p *podReadyChecker) waitForPodReady(ctx context.Context, namespace, name s } type kubeExecInterface interface { - exec(namespace, podName, containerName string, command []string) (string, string, error) + exec(ctx context.Context, namespace, podName, containerName string, command []string) (string, string, error) } type kubeExecutor struct { cli kubernetes.Interface } -func (k *kubeExecutor) exec(namespace, podName, containerName string, command []string) (string, string, error) { - return kankube.Exec(k.cli, namespace, podName, containerName, command, nil) +func (k *kubeExecutor) exec(ctx context.Context, namespace, podName, containerName string, command []string) (string, string, error) { + return kankube.Exec(ctx, k.cli, namespace, podName, containerName, command, nil) } diff --git a/pkg/fio/fio_test.go b/pkg/fio/fio_test.go index 6f9bc5c..6ac655e 100644 --- a/pkg/fio/fio_test.go +++ b/pkg/fio/fio_test.go @@ -954,7 +954,7 @@ type fakeKubeExecutor struct { keInCommand []string } -func (fk *fakeKubeExecutor) exec(namespace, podName, containerName string, command []string) (string, string, error) { +func (fk *fakeKubeExecutor) exec(_ context.Context, namespace, podName, containerName string, command []string) (string, string, error) { fk.keInNS = namespace fk.keInPodName = podName fk.keInContainerName = containerName