diff --git a/cmd/installer/pkg/install/install.go b/cmd/installer/pkg/install/install.go index c5edf68af4..07170b9481 100644 --- a/cmd/installer/pkg/install/install.go +++ b/cmd/installer/pkg/install/install.go @@ -27,9 +27,9 @@ import ( "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/board" "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader" bootloaderoptions "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/options" + "github.com/siderolabs/talos/internal/pkg/cache" "github.com/siderolabs/talos/internal/pkg/meta" "github.com/siderolabs/talos/internal/pkg/partition" - "github.com/siderolabs/talos/pkg/imager/cache" "github.com/siderolabs/talos/pkg/imager/overlay/executor" "github.com/siderolabs/talos/pkg/machinery/compatibility" "github.com/siderolabs/talos/pkg/machinery/constants" diff --git a/internal/pkg/cache/cache.go b/internal/pkg/cache/cache.go new file mode 100644 index 0000000000..a47a3c8afc --- /dev/null +++ b/internal/pkg/cache/cache.go @@ -0,0 +1,59 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Package cache provides methods to install an image cache +package cache + +import ( + "fmt" + "os" + + "github.com/siderolabs/go-blockdevice/v2/blkid" + "github.com/siderolabs/go-copy/copy" + + "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/mount" + "github.com/siderolabs/talos/internal/pkg/partition" + "github.com/siderolabs/talos/pkg/machinery/constants" +) + +// InstallOptions contains the options for installing the cache. +type InstallOptions struct { + // The disk where cache partition is present. + CacheDisk string + // Source of the cache from where it will be copied. + CachePath string + // Optional: blkid probe result. + BlkidInfo *blkid.Info +} + +// Install installs the cache to the given disk. +func (i *InstallOptions) Install() error { + tempMountDir, err := os.MkdirTemp("", "talos-image-cache-install") + if err != nil { + return fmt.Errorf("creating temporary directory for talos-image-cache-install: %w", err) + } + + defer os.RemoveAll(tempMountDir) //nolint:errcheck + + return mount.PartitionOp( + i.CacheDisk, + []mount.Spec{ + { + PartitionLabel: constants.ImageCachePartitionLabel, + FilesystemType: partition.FileSystemTypeExt4, + MountTarget: tempMountDir, + }, + }, + func() error { + return copy.Dir(i.CachePath, tempMountDir) + }, + []blkid.ProbeOption{ + // installation happens with locked blockdevice + blkid.WithSkipLocking(true), + }, + nil, + nil, + i.BlkidInfo, + ) +} diff --git a/pkg/imager/cache/cache.go b/pkg/imager/cache/cache.go index dba3d0e269..df2c12ed22 100644 --- a/pkg/imager/cache/cache.go +++ b/pkg/imager/cache/cache.go @@ -28,13 +28,8 @@ import ( "github.com/google/go-containerregistry/pkg/v1/mutate" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/types" - "github.com/siderolabs/go-blockdevice/v2/blkid" - "github.com/siderolabs/go-copy/copy" - "github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/mount" - "github.com/siderolabs/talos/internal/pkg/partition" "github.com/siderolabs/talos/pkg/imager/filemap" - "github.com/siderolabs/talos/pkg/machinery/constants" ) const ( @@ -42,16 +37,6 @@ const ( manifestsDir = "manifests" ) -// InstallOptions contains the options for installing the cache. -type InstallOptions struct { - // The disk where cache partition is present. - CacheDisk string - // Source of the cache from where it will be copied. - CachePath string - // Optional: blkid probe result. - BlkidInfo *blkid.Info -} - // Generate generates a cache tarball from the given images. // //nolint:gocyclo,cyclop @@ -246,37 +231,6 @@ func Generate(images []string, platform string, insecure bool, imageLayerCachePa return removeAll() } -// Install installs the cache to the given disk. -func (i *InstallOptions) Install() error { - tempMountDir, err := os.MkdirTemp("", "talos-image-cache-install") - if err != nil { - return fmt.Errorf("creating temporary directory for talos-image-cache-install: %w", err) - } - - defer os.RemoveAll(tempMountDir) //nolint:errcheck - - return mount.PartitionOp( - i.CacheDisk, - []mount.Spec{ - { - PartitionLabel: constants.ImageCachePartitionLabel, - FilesystemType: partition.FileSystemTypeExt4, - MountTarget: tempMountDir, - }, - }, - func() error { - return copy.Dir(i.CachePath, tempMountDir) - }, - []blkid.ProbeOption{ - // installation happens with locked blockdevice - blkid.WithSkipLocking(true), - }, - nil, - nil, - i.BlkidInfo, - ) -} - func processLayer(layer v1.Layer, dstDir string) error { digest, err := layer.Digest() if err != nil {