diff --git a/pkg/function/backup_data_stats.go b/pkg/function/backup_data_stats.go index 012581e99e..1c1b7dde67 100644 --- a/pkg/function/backup_data_stats.go +++ b/pkg/function/backup_data_stats.go @@ -77,7 +77,7 @@ func backupDataStats(ctx context.Context, cli kubernetes.Interface, tp param.Tem } pr := kube.NewPodRunner(cli, options) podFunc := backupDataStatsPodFunc(tp, encryptionKey, backupArtifactPrefix, backupID, mode) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func backupDataStatsPodFunc( diff --git a/pkg/function/checkRepository.go b/pkg/function/checkRepository.go index 622ef349a5..a240f20e15 100644 --- a/pkg/function/checkRepository.go +++ b/pkg/function/checkRepository.go @@ -60,7 +60,7 @@ func CheckRepository(ctx context.Context, cli kubernetes.Interface, tp param.Tem } pr := kube.NewPodRunner(cli, options) podFunc := CheckRepositoryPodFunc(cli, tp, encryptionKey, targetPaths) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func CheckRepositoryPodFunc( diff --git a/pkg/function/copy_volume_data.go b/pkg/function/copy_volume_data.go index f41041bbf5..13461c676f 100644 --- a/pkg/function/copy_volume_data.go +++ b/pkg/function/copy_volume_data.go @@ -86,7 +86,7 @@ func copyVolumeData(ctx context.Context, cli kubernetes.Interface, tp param.Temp } pr := kube.NewPodRunner(cli, options) podFunc := copyVolumeDataPodFunc(cli, tp, mountPoint, targetPath, encryptionKey) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func copyVolumeDataPodFunc( diff --git a/pkg/function/delete_data.go b/pkg/function/delete_data.go index fd662cfa82..2eb0dded65 100644 --- a/pkg/function/delete_data.go +++ b/pkg/function/delete_data.go @@ -98,7 +98,7 @@ func deleteData( } pr := kube.NewPodRunner(cli, options) podFunc := deleteDataPodFunc(tp, reclaimSpace, encryptionKey, targetPaths, deleteTags, deleteIdentifiers) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } //nolint:gocognit diff --git a/pkg/function/delete_data_using_kopia_server.go b/pkg/function/delete_data_using_kopia_server.go index 74d97db565..ac1e04bdea 100644 --- a/pkg/function/delete_data_using_kopia_server.go +++ b/pkg/function/delete_data_using_kopia_server.go @@ -167,7 +167,7 @@ func deleteDataFromServer( username, userPassphrase, ) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func deleteDataFromServerPodFunc( diff --git a/pkg/function/describe_backups.go b/pkg/function/describe_backups.go index 841b00d554..879610d7d6 100644 --- a/pkg/function/describe_backups.go +++ b/pkg/function/describe_backups.go @@ -79,7 +79,7 @@ func describeBackups(ctx context.Context, cli kubernetes.Interface, tp param.Tem } pr := kube.NewPodRunner(cli, options) podFunc := describeBackupsPodFunc(cli, tp, encryptionKey, targetPaths) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func describeBackupsPodFunc( diff --git a/pkg/function/kube_task.go b/pkg/function/kube_task.go index 0b671cd00a..fa95fd4025 100644 --- a/pkg/function/kube_task.go +++ b/pkg/function/kube_task.go @@ -67,7 +67,7 @@ func kubeTask(ctx context.Context, cli kubernetes.Interface, namespace, image st pr := kube.NewPodRunner(cli, options) podFunc := kubeTaskPodFunc() - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func kubeTaskPodFunc() func(ctx context.Context, pc kube.PodController) (map[string]interface{}, error) { diff --git a/pkg/function/prepare_data.go b/pkg/function/prepare_data.go index 657407b59f..df71ca6ea1 100644 --- a/pkg/function/prepare_data.go +++ b/pkg/function/prepare_data.go @@ -101,7 +101,7 @@ func prepareData(ctx context.Context, cli kubernetes.Interface, namespace, servi } pr := kube.NewPodRunner(cli, options) podFunc := prepareDataPodFunc(cli) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func prepareDataPodFunc(cli kubernetes.Interface) func(ctx context.Context, pc kube.PodController) (map[string]interface{}, error) { diff --git a/pkg/function/restore_data.go b/pkg/function/restore_data.go index 747a322dd4..42aac6fe5d 100644 --- a/pkg/function/restore_data.go +++ b/pkg/function/restore_data.go @@ -130,7 +130,7 @@ func restoreData(ctx context.Context, cli kubernetes.Interface, tp param.Templat } pr := kube.NewPodRunner(cli, options) podFunc := restoreDataPodFunc(tp, encryptionKey, backupArtifactPrefix, restorePath, backupTag, backupID) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func restoreDataPodFunc( diff --git a/pkg/function/restore_data_using_kopia_server.go b/pkg/function/restore_data_using_kopia_server.go index f4b906a12f..07ffdcc6b1 100644 --- a/pkg/function/restore_data_using_kopia_server.go +++ b/pkg/function/restore_data_using_kopia_server.go @@ -210,7 +210,7 @@ func restoreDataFromServer( userPassphrase, sparseRestore, ) - return pr.RunEx(ctx, podFunc) + return pr.Run(ctx, podFunc) } func restoreDataFromServerPodFunc( diff --git a/pkg/kube/pod_runner.go b/pkg/kube/pod_runner.go index 64b864b0f7..2d0c2268dd 100644 --- a/pkg/kube/pod_runner.go +++ b/pkg/kube/pod_runner.go @@ -18,7 +18,6 @@ import ( "context" "github.com/pkg/errors" - v1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" "github.com/kanisterio/kanister/pkg/consts" @@ -28,16 +27,12 @@ import ( // PodRunner allows us to start / stop pod, write file to pod and execute command within it type PodRunner interface { - Run(ctx context.Context, fn func(context.Context, *v1.Pod) (map[string]interface{}, error)) (map[string]interface{}, error) - // RunEx utilizes the PodController interface and forwards it to the functor, simplifying the manipulation with - // particular pod from the functor. - // TODO: Since significant number of functions are currently using PodRunner, we'll keep Run for now. - // However, once all these functions have been refactored to use PodController, - // Run should be removed and RunEx has to be renamed to Run. - RunEx(ctx context.Context, fn func(context.Context, PodController) (map[string]interface{}, error)) (map[string]interface{}, error) + // Run creates pod using the PodController interface and forwards it to the functor. + // Pod will be deleted as soon as functor exits. + Run(ctx context.Context, fn func(context.Context, PodController) (map[string]interface{}, error)) (map[string]interface{}, error) } -// PodRunner specifies Kubernetes Client and PodOptions needed for creating Pod +// podRunner implements PodRunner interface type podRunner struct { pc PodController } @@ -60,14 +55,10 @@ func NewPodRunnerWithPodController(pc PodController) PodRunner { } // Run will create a new Pod based on PodRunner contents and execute the given function -func (p *podRunner) Run(ctx context.Context, fn func(context.Context, *v1.Pod) (map[string]interface{}, error)) (map[string]interface{}, error) { - return p.RunEx(ctx, func(innerCtx context.Context, pc PodController) (map[string]interface{}, error) { - return fn(innerCtx, pc.Pod()) - }) -} - -// RunEx will create a new Pod based on PodRunner contents and execute the given function -func (p *podRunner) RunEx(ctx context.Context, fn func(context.Context, PodController) (map[string]interface{}, error)) (map[string]interface{}, error) { +func (p *podRunner) Run( + ctx context.Context, + fn func(context.Context, PodController) (map[string]interface{}, error), +) (map[string]interface{}, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() diff --git a/pkg/kube/pod_runner_test.go b/pkg/kube/pod_runner_test.go index 900d7df852..779d58c080 100644 --- a/pkg/kube/pod_runner_test.go +++ b/pkg/kube/pod_runner_test.go @@ -109,8 +109,8 @@ func (s *PodRunnerTestSuite) TestPodRunnerForSuccessCase(c *C) { cancel() } -func makePodRunnerTestFunc(ch chan struct{}) func(ctx context.Context, pod *v1.Pod) (map[string]interface{}, error) { - return func(ctx context.Context, pod *v1.Pod) (map[string]interface{}, error) { +func makePodRunnerTestFunc(ch chan struct{}) func(ctx context.Context, pc PodController) (map[string]interface{}, error) { + return func(ctx context.Context, pc PodController) (map[string]interface{}, error) { <-ch return nil, nil }