Skip to content

Commit

Permalink
fix: imager disk image-cache generator
Browse files Browse the repository at this point in the history
Move things around so `talosctl` is not dependent on `go-blockdevice`.

Signed-off-by: Noel Georgi <git@frezbo.dev>
  • Loading branch information
frezbo committed Nov 26, 2024
1 parent 1bac0b1 commit 939c555
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
59 changes: 59 additions & 0 deletions internal/pkg/cache/cache.go
Original file line number Diff line number Diff line change
@@ -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,
)
}
46 changes: 0 additions & 46 deletions pkg/imager/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,15 @@ 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 (
blobsDir = "blob"
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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 939c555

Please sign in to comment.