From 5c343b0f80a9970eb047617b32c45724cf7bc593 Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Tue, 18 Jul 2023 08:55:22 -0700 Subject: [PATCH] Get VFSContext from caller in CopyFile --- cmd/kops/get_assets.go | 2 +- pkg/assets/copy.go | 4 +++- pkg/assets/copyfile.go | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/kops/get_assets.go b/cmd/kops/get_assets.go index 061c2c9c65714..2b51599215a1c 100644 --- a/cmd/kops/get_assets.go +++ b/cmd/kops/get_assets.go @@ -141,7 +141,7 @@ func RunGetAssets(ctx context.Context, f *util.Factory, out io.Writer, options * } if options.Copy { - err := assets.Copy(updateClusterResults.ImageAssets, updateClusterResults.FileAssets, updateClusterResults.Cluster) + err := assets.Copy(updateClusterResults.ImageAssets, updateClusterResults.FileAssets, f.VFSContext(), updateClusterResults.Cluster) if err != nil { return err } diff --git a/pkg/assets/copy.go b/pkg/assets/copy.go index 7167334065161..a561a9cd12070 100644 --- a/pkg/assets/copy.go +++ b/pkg/assets/copy.go @@ -22,13 +22,14 @@ import ( "k8s.io/klog/v2" "k8s.io/kops/pkg/apis/kops" + "k8s.io/kops/util/pkg/vfs" ) type assetTask interface { Run() error } -func Copy(imageAssets []*ImageAsset, fileAssets []*FileAsset, cluster *kops.Cluster) error { +func Copy(imageAssets []*ImageAsset, fileAssets []*FileAsset, vfsContext *vfs.VFSContext, cluster *kops.Cluster) error { tasks := map[string]assetTask{} for _, imageAsset := range imageAssets { @@ -56,6 +57,7 @@ func Copy(imageAssets []*ImageAsset, fileAssets []*FileAsset, cluster *kops.Clus TargetFile: fileAsset.DownloadURL.String(), SourceFile: fileAsset.CanonicalURL.String(), SHA: fileAsset.SHAValue, + VFSContext: vfsContext, Cluster: cluster, } diff --git a/pkg/assets/copyfile.go b/pkg/assets/copyfile.go index 7a46315a42854..68957f1f7d11b 100644 --- a/pkg/assets/copyfile.go +++ b/pkg/assets/copyfile.go @@ -38,6 +38,7 @@ type CopyFile struct { SourceFile string TargetFile string SHA string + VFSContext *vfs.VFSContext Cluster *kops.Cluster } @@ -66,7 +67,7 @@ func (e *CopyFile) Run() error { targetSHAFile := e.TargetFile + shaExtension - targetSHABytes, err := vfs.Context.ReadFile(targetSHAFile) + targetSHABytes, err := e.VFSContext.ReadFile(targetSHAFile) if err != nil { if os.IsNotExist(err) { klog.V(4).Infof("unable to download: %q, assuming target file is not present, and if not present may not be an error: %v", @@ -91,7 +92,7 @@ func (e *CopyFile) Run() error { klog.V(2).Infof("copying bits from %q to %q", source, target) - if err := transferFile(ctx, e.Cluster, source, target, sourceSha); err != nil { + if err := transferFile(ctx, e.VFSContext, e.Cluster, source, target, sourceSha); err != nil { return fmt.Errorf("unable to transfer %q to %q: %v", source, target, err) } @@ -100,11 +101,11 @@ func (e *CopyFile) Run() error { // transferFile downloads a file from the source location, validates the file matches the SHA, // and uploads the file to the target location. -func transferFile(ctx context.Context, cluster *kops.Cluster, source string, target string, sha string) error { +func transferFile(ctx context.Context, vfsContext *vfs.VFSContext, cluster *kops.Cluster, source string, target string, sha string) error { // TODO drop file to disk, as vfs reads file into memory. We load kubelet into memory for instance. // TODO in s3 can we do a copy file ... would need to test - data, err := vfs.Context.ReadFile(source) + data, err := vfsContext.ReadFile(source) if err != nil { if os.IsNotExist(err) { return fmt.Errorf("file not found %q: %v", source, err) @@ -118,7 +119,7 @@ func transferFile(ctx context.Context, cluster *kops.Cluster, source string, tar return err } - uploadVFS, err := vfs.Context.BuildVfsPath(objectStore) + uploadVFS, err := vfsContext.BuildVfsPath(objectStore) if err != nil { return fmt.Errorf("error building path %q: %v", objectStore, err) } @@ -129,7 +130,7 @@ func transferFile(ctx context.Context, cluster *kops.Cluster, source string, tar } shaTarget := objectStore + shaExtension - shaVFS, err := vfs.Context.BuildVfsPath(shaTarget) + shaVFS, err := vfsContext.BuildVfsPath(shaTarget) if err != nil { return fmt.Errorf("error building path %q: %v", shaTarget, err) }