Skip to content

Commit

Permalink
Adjust code to follow Kanister changes
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sumin committed May 9, 2024
1 parent 9b04482 commit 0373645
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pkg/csi/csi_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/csi/mocks/mock_data_validator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/csi/snapshot_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/fio/fio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/fio/fio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0373645

Please sign in to comment.