Skip to content

Commit

Permalink
feat: implement image cache configuration
Browse files Browse the repository at this point in the history
Implement a feature flag, a resource which controls the flow.

This controls the volume configuration, mounting, etc.

Fixes #9767

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Nov 21, 2024
1 parent 0ffb218 commit 66617b4
Show file tree
Hide file tree
Showing 36 changed files with 1,281 additions and 111 deletions.
7 changes: 7 additions & 0 deletions api/resource/definitions/cri/cri.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ option go_package = "github.com/siderolabs/talos/pkg/machinery/api/resource/defi
option java_package = "dev.talos.api.resource.definitions.cri";

import "google/protobuf/struct.proto";
import "resource/definitions/enums/enums.proto";

// ImageCacheConfigSpec represents the ImageCacheConfig.
message ImageCacheConfigSpec {
talos.resource.definitions.enums.CriImageCacheStatus status = 1;
repeated string roots = 2;
}

// SeccompProfileSpec represents the SeccompProfile.
message SeccompProfileSpec {
Expand Down
8 changes: 8 additions & 0 deletions api/resource/definitions/enums/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ enum BlockVolumeType {
VOLUME_TYPE_TMPFS = 2;
}

// CriImageCacheStatus describes image cache status type.
enum CriImageCacheStatus {
IMAGE_CACHE_STATUS_UNKNOWN = 0;
IMAGE_CACHE_STATUS_DISABLED = 1;
IMAGE_CACHE_STATUS_PREPARING = 2;
IMAGE_CACHE_STATUS_READY = 3;
}

// KubespanPeerState is KubeSpan peer current state.
enum KubespanPeerState {
PEER_STATE_UNKNOWN = 0;
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0
github.com/golang/mock v1.6.0
github.com/google/cadvisor v0.51.0
github.com/google/cel-go v0.22.0
github.com/google/go-containerregistry v0.20.2
github.com/google/go-tpm v0.9.1
github.com/google/nftables v0.2.0
Expand Down Expand Up @@ -140,7 +141,7 @@ require (
github.com/siderolabs/gen v0.7.0
github.com/siderolabs/go-api-signature v0.3.6
github.com/siderolabs/go-blockdevice v0.4.8
github.com/siderolabs/go-blockdevice/v2 v2.0.5
github.com/siderolabs/go-blockdevice/v2 v2.0.6
github.com/siderolabs/go-circular v0.2.1
github.com/siderolabs/go-cmd v0.1.3
github.com/siderolabs/go-copy v0.1.0
Expand All @@ -160,7 +161,6 @@ require (
github.com/siderolabs/kms-client v0.1.0
github.com/siderolabs/net v0.4.0
github.com/siderolabs/proto-codec v0.1.1
github.com/siderolabs/protoenc v0.2.1 // indirect
github.com/siderolabs/siderolink v0.3.11
github.com/siderolabs/talos/pkg/machinery v1.9.0-alpha.2
github.com/spf13/cobra v1.8.1
Expand All @@ -177,7 +177,6 @@ require (
go.etcd.io/etcd/etcdutl/v3 v3.5.17
go.uber.org/zap v1.27.0
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.31.0
golang.org/x/oauth2 v0.24.0
golang.org/x/sync v0.9.0
Expand Down Expand Up @@ -267,7 +266,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/cel-go v0.22.0 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
Expand Down Expand Up @@ -328,6 +326,7 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/siderolabs/protoenc v0.2.1 // indirect
github.com/siderolabs/tcpproxy v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.10.0 // indirect
Expand All @@ -353,6 +352,7 @@ require (
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ github.com/siderolabs/go-api-signature v0.3.6 h1:wDIsXbpl7Oa/FXvxB6uz4VL9INA9fmr
github.com/siderolabs/go-api-signature v0.3.6/go.mod h1:hoH13AfunHflxbXfh+NoploqV13ZTDfQ1mQJWNVSW9U=
github.com/siderolabs/go-blockdevice v0.4.8 h1:KfdWvIx0Jft5YVuCsFIJFwjWEF1oqtzkgX9PeU9cX4c=
github.com/siderolabs/go-blockdevice v0.4.8/go.mod h1:4PeOuk71pReJj1JQEXDE7kIIQJPVe8a+HZQa+qjxSEA=
github.com/siderolabs/go-blockdevice/v2 v2.0.5 h1:VLmIdDB/1P30Inrpe94FQAz4WUpByGwun5ZeTekxIQc=
github.com/siderolabs/go-blockdevice/v2 v2.0.5/go.mod h1:74htzCV913UzaLZ4H+NBXkwWlYnBJIq5m/379ZEcu8w=
github.com/siderolabs/go-blockdevice/v2 v2.0.6 h1:/NAy3MbNZhjLWo28asZyS/hmf86PEPDMc9i6wIcgbwI=
github.com/siderolabs/go-blockdevice/v2 v2.0.6/go.mod h1:74htzCV913UzaLZ4H+NBXkwWlYnBJIq5m/379ZEcu8w=
github.com/siderolabs/go-circular v0.2.1 h1:a++iVCn9jyhICX3POQZZX8n72p2h5JGdGU6w1ulmpcA=
github.com/siderolabs/go-circular v0.2.1/go.mod h1:ZDItzVyXK+B/XuqTBV5MtQtSv06VI+oCmWGRnNCATo8=
github.com/siderolabs/go-cmd v0.1.3 h1:JrgZwqhJQeoec3QRON0LK+fv+0y7d0DyY7zsfkO6ciw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Format establishes a filesystem on a block device.
//
//nolint:gocyclo
//nolint:gocyclo,cyclop
func Format(ctx context.Context, logger *zap.Logger, volumeContext ManagerContext) error {
// lock either the parent device or the device itself
devPath := volumeContext.Status.ParentLocation
Expand Down Expand Up @@ -111,6 +111,16 @@ func Format(ctx context.Context, logger *zap.Logger, volumeContext ManagerContex
if err = makefs.XFS(volumeContext.Status.MountLocation, makefsOptions...); err != nil {
return fmt.Errorf("error formatting XFS: %w", err)
}
case block.FilesystemTypeEXT4:
var makefsOptions []makefs.Option

if volumeContext.Cfg.TypedSpec().Provisioning.FilesystemSpec.Label != "" {
makefsOptions = append(makefsOptions, makefs.WithLabel(volumeContext.Cfg.TypedSpec().Provisioning.FilesystemSpec.Label))
}

if err = makefs.Ext4(volumeContext.Status.MountLocation, makefsOptions...); err != nil {
return fmt.Errorf("error formatting ext4: %w", err)
}
default:
return fmt.Errorf("unsupported filesystem type: %s", volumeContext.Cfg.TypedSpec().Provisioning.FilesystemSpec.Type)
}
Expand Down Expand Up @@ -148,6 +158,14 @@ func GrowFilesystem(logger *zap.Logger, volumeContext ManagerContext) error {
return fmt.Errorf("error growing XFS: %w", err)
}

return nil
case block.FilesystemTypeEXT4:
logger.Info("growing ext4 filesystem", zap.String("device", volumeContext.Status.MountLocation))

if err := makefs.Ext4Resize(volumeContext.Status.MountLocation); err != nil {
return fmt.Errorf("error growing ext4: %w", err)
}

return nil
default:
return fmt.Errorf("unsupported filesystem type to grow: %s", volumeContext.Cfg.TypedSpec().Provisioning.FilesystemSpec.Type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (ctrl *VolumeConfigController) Run(ctx context.Context, r controller.Runtim

func (ctrl *VolumeConfigController) manageEphemeral(config cfg.Config) func(vc *block.VolumeConfig) error {
return func(vc *block.VolumeConfig) error {
extraVolumeConfig := config.Volumes().ByName(constants.EphemeralPartitionLabel)
extraVolumeConfig, _ := config.Volumes().ByName(constants.EphemeralPartitionLabel)

vc.TypedSpec().Type = block.VolumeTypePartition

Expand Down
1 change: 1 addition & 0 deletions internal/app/machined/pkg/controllers/cri/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// 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 cri provides CRI related controllers.
package cri
Loading

0 comments on commit 66617b4

Please sign in to comment.