-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash in copyVolumeDataPodFunc when location type is not GCS #2072
Conversation
Thanks for submitting this pull request 🎉. The team will review it soon and get back to you. If you haven't already, please take a moment to review our project contributing guideline and Code of Conduct document. |
5a62060
to
7c974f1
Compare
pkg/function/copy_volume_data.go
Outdated
if remover != nil { // WriteCredsToPod might return nil when nothing was written | ||
defer remover.Remove(context.Background()) //nolint:errcheck | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the parent context instead of creating new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the parent context dies, the clean up call will be aborted as well. Thus, I think there's no issue here. But maybe it makes sense to put a note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, I'll add a comment
I think the real cause of the failure is that the remover is unexpectedly nil (see: https://github.com/kanisterio/kanister/blob/2babd1ad48c4f408f614c50ded06a2f3eb2a13b0/pkg/function/utils.go#LL102C1-L113C2). I strongly believe (however, my beliefs might be wrong) that returning nil for the object when there is no error (thus If we check // 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 {
remover, err := writer.Write(ctx, consts.GoogleCloudCredsFilePath, bytes.NewBufferString(profile.Credential.KeyPair.Secret))
if err != nil {
return nil, errors.Wrapf(err, "Unable to write Google credentials to the pod.")
}
return remover, nil
}
return nil, nil
} I'd instead implement a |
pkg/function/copy_volume_data.go
Outdated
@@ -99,7 +99,9 @@ func copyVolumeDataPodFunc(cli kubernetes.Interface, tp param.TemplateParams, na | |||
return nil, errors.Wrapf(err, "Failed to write credentials to Pod %s", pc.PodName()) | |||
} | |||
|
|||
defer remover.Remove(context.Background()) //nolint:errcheck | |||
if remover != nil { // WriteCredsToPod might return nil when nothing was written |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check my PR comment: #2072 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I agree with NopRemover. I thought about this but decided that probably it's an overkill. But since this came not only to my mind, it probably makes sense.
pkg/function/utils.go
Outdated
var _ kube.PodFileRemover = (*nopRemover)(nil) | ||
|
||
func (nr *nopRemover) Remove(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
func (nr *nopRemover) Path() string { | ||
return "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var _ kube.PodFileRemover = (*nopRemover)(nil) | |
func (nr *nopRemover) Remove(ctx context.Context) error { | |
return nil | |
} | |
func (nr *nopRemover) Path() string { | |
return "" | |
} | |
var _ kube.PodFileRemover = (nopRemover)(nil) | |
func (nr nopRemover) Remove(ctx context.Context) error { | |
return nil | |
} | |
func (nr nopRemover) Path() string { | |
return "" | |
} |
pkg/function/utils.go
Outdated
@@ -109,7 +122,7 @@ func WriteCredsToPod(ctx context.Context, writer kube.PodFileWriter, profile *pa | |||
|
|||
return remover, nil | |||
} | |||
return nil, nil | |||
return &nopRemover{}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return &nopRemover{}, nil | |
return nopRemover{}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Change Overview
copyVolumeDataPodFunc is crashing when location type is not GCS
Pull request type
Please check the type of change your PR introduces: