mirror of https://github.com/kubernetes/kops.git
Get VFSContext from caller in CopyFile
This commit is contained in:
parent
1358851c7d
commit
5c343b0f80
|
@ -141,7 +141,7 @@ func RunGetAssets(ctx context.Context, f *util.Factory, out io.Writer, options *
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Copy {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,14 @@ import (
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type assetTask interface {
|
type assetTask interface {
|
||||||
Run() error
|
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{}
|
tasks := map[string]assetTask{}
|
||||||
|
|
||||||
for _, imageAsset := range imageAssets {
|
for _, imageAsset := range imageAssets {
|
||||||
|
@ -56,6 +57,7 @@ func Copy(imageAssets []*ImageAsset, fileAssets []*FileAsset, cluster *kops.Clus
|
||||||
TargetFile: fileAsset.DownloadURL.String(),
|
TargetFile: fileAsset.DownloadURL.String(),
|
||||||
SourceFile: fileAsset.CanonicalURL.String(),
|
SourceFile: fileAsset.CanonicalURL.String(),
|
||||||
SHA: fileAsset.SHAValue,
|
SHA: fileAsset.SHAValue,
|
||||||
|
VFSContext: vfsContext,
|
||||||
Cluster: cluster,
|
Cluster: cluster,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ type CopyFile struct {
|
||||||
SourceFile string
|
SourceFile string
|
||||||
TargetFile string
|
TargetFile string
|
||||||
SHA string
|
SHA string
|
||||||
|
VFSContext *vfs.VFSContext
|
||||||
Cluster *kops.Cluster
|
Cluster *kops.Cluster
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ func (e *CopyFile) Run() error {
|
||||||
|
|
||||||
targetSHAFile := e.TargetFile + shaExtension
|
targetSHAFile := e.TargetFile + shaExtension
|
||||||
|
|
||||||
targetSHABytes, err := vfs.Context.ReadFile(targetSHAFile)
|
targetSHABytes, err := e.VFSContext.ReadFile(targetSHAFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
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",
|
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)
|
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)
|
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,
|
// transferFile downloads a file from the source location, validates the file matches the SHA,
|
||||||
// and uploads the file to the target location.
|
// 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 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
|
// 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 err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return fmt.Errorf("file not found %q: %v", source, 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadVFS, err := vfs.Context.BuildVfsPath(objectStore)
|
uploadVFS, err := vfsContext.BuildVfsPath(objectStore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error building path %q: %v", objectStore, err)
|
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
|
shaTarget := objectStore + shaExtension
|
||||||
shaVFS, err := vfs.Context.BuildVfsPath(shaTarget)
|
shaVFS, err := vfsContext.BuildVfsPath(shaTarget)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error building path %q: %v", shaTarget, err)
|
return fmt.Errorf("error building path %q: %v", shaTarget, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue