Skip to content

Commit

Permalink
Rename PodRunner's RunEx to Run (#2369)
Browse files Browse the repository at this point in the history
* Rename PodRunner's RunEx to Run

* Improve readability

Co-authored-by: Pavan Navarathna <[email protected]>

---------

Co-authored-by: Pavan Navarathna <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and Le Tran committed Oct 18, 2023
1 parent 27de287 commit ea51da6
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/function/backup_data_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/checkRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/delete_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/delete_data_using_kopia_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func deleteDataFromServer(
username,
userPassphrase,
)
return pr.RunEx(ctx, podFunc)
return pr.Run(ctx, podFunc)
}

func deleteDataFromServerPodFunc(
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/describe_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/kube_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/prepare_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/restore_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/restore_data_using_kopia_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func restoreDataFromServer(
userPassphrase,
sparseRestore,
)
return pr.RunEx(ctx, podFunc)
return pr.Run(ctx, podFunc)
}

func restoreDataFromServerPodFunc(
Expand Down
25 changes: 8 additions & 17 deletions pkg/kube/pod_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/pod_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ea51da6

Please sign in to comment.