Skip to content

Commit

Permalink
Fix crash in copyVolumeDataPodFunc when location type is not GCS (#2072)
Browse files Browse the repository at this point in the history
* FIx crash in copyVolumeDataPodFunc when location type is not GCS

* Address review comments

* Fix NopRemover receiver

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
e-sumin and mergify[bot] authored May 24, 2023
1 parent 4966084 commit 40fb249
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func copyVolumeDataPodFunc(cli kubernetes.Interface, tp param.TemplateParams, na
return nil, errors.Wrapf(err, "Failed to write credentials to Pod %s", pc.PodName())
}

// Parent context could already be dead, so removing file within new context
defer remover.Remove(context.Background()) //nolint:errcheck

pod := pc.Pod()
Expand Down
15 changes: 14 additions & 1 deletion pkg/function/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ func ValidateProfile(profile *param.Profile) error {
return nil
}

type nopRemover struct {
}

var _ kube.PodFileRemover = nopRemover{}

func (nr nopRemover) Remove(ctx context.Context) error {
return nil
}

func (nr nopRemover) Path() string {
return ""
}

// WriteCredsToPod creates a file with Google credentials if the given profile points to a GCS location
func WriteCredsToPod(ctx context.Context, writer kube.PodFileWriter, profile *param.Profile) (kube.PodFileRemover, error) {
if profile.Location.Type == crv1alpha1.LocationTypeGCS {
Expand All @@ -109,7 +122,7 @@ func WriteCredsToPod(ctx context.Context, writer kube.PodFileWriter, profile *pa

return remover, nil
}
return nil, nil
return nopRemover{}, nil
}

// GetPodWriter creates a file with Google credentials if the given profile points to a GCS location
Expand Down

0 comments on commit 40fb249

Please sign in to comment.