diff --git a/pkg/kosmosctl/image/push.go b/pkg/kosmosctl/image/push.go index 01f082285..dd2e1fd3e 100644 --- a/pkg/kosmosctl/image/push.go +++ b/pkg/kosmosctl/image/push.go @@ -223,19 +223,15 @@ func (o *CommandPushOptions) PushCommand(imageName string) (err error) { } func (o *CommandPushOptions) DockerLoad() (imageList []string, err error) { - tar, err := os.Open(o.Artifact) + file, err := os.Open(o.Artifact) if err != nil { return nil, fmt.Errorf("open %s failed: %s", o.Artifact, err) } - imageLoadResponse, err := o.DockerClient.ImageLoad(context.Background(), tar, true) + defer file.Close() + imageLoadResponse, err := o.DockerClient.ImageLoad(context.Background(), file, true) if err != nil { return nil, fmt.Errorf("docker load failed: %s", err) } - defer func() { - if err = tar.Close(); err != nil { - klog.Errorf("tar close failed: %s", err) - } - }() body, err := io.ReadAll(imageLoadResponse.Body) if err != nil { @@ -308,11 +304,7 @@ func (o *CommandPushOptions) ContainerdImport() (imageList []string, err error) if err != nil { return nil, fmt.Errorf("open %s failed: %s", o.Artifact, err) } - defer func() { - if err = file.Close(); err != nil { - klog.Errorf("file close failed: %s", err) - } - }() + defer file.Close() images, err := o.ContainerdClient.Import(o.Context, file) if err != nil {