From af91c99ba1fec22f09951034f6b0786917e326bc Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 27 Nov 2024 18:18:36 +0400 Subject: [PATCH] chore: update image cache config Make it nested, so that we can expand easily to support e.g. distributed cache. Signed-off-by: Andrey Smirnov --- .github/ISSUE_TEMPLATE/config.yml | 5 +++- .../pkg/controllers/cri/image_cache_config.go | 2 +- .../cri/image_cache_config_test.go | 8 ++++-- .../pkg/runtime/v1alpha1/v1alpha1_runtime.go | 2 +- pkg/machinery/config/config/machine.go | 7 ++++- .../config/schemas/config.schema.json | 15 +++++++++- .../types/v1alpha1/v1alpha1_features.go | 15 ++++++++-- .../config/types/v1alpha1/v1alpha1_types.go | 9 +++++- .../types/v1alpha1/v1alpha1_types_doc.go | 28 ++++++++++++++++++- .../configuration/v1alpha1/config.md | 18 +++++++++++- .../content/v1.9/schemas/config.schema.json | 15 +++++++++- 11 files changed, 110 insertions(+), 14 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 40e15de154..2a7ec48650 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,8 @@ blank_issues_enabled: false contact_links: - name: Question + url: https://github.com/siderolabs/talos/discussions + about: Ask a question about Talos Linux. + - name: Community url: https://taloscommunity.slack.com - about: Ask a question. Get your invite by visiting https://slack.dev.talos-systems.io. + about: Join the community. Get your invite by visiting https://slack.dev.talos-systems.io. diff --git a/internal/app/machined/pkg/controllers/cri/image_cache_config.go b/internal/app/machined/pkg/controllers/cri/image_cache_config.go index 370109c658..b03b2ce807 100644 --- a/internal/app/machined/pkg/controllers/cri/image_cache_config.go +++ b/internal/app/machined/pkg/controllers/cri/image_cache_config.go @@ -119,7 +119,7 @@ func (ctrl *ImageCacheConfigController) Run(ctx context.Context, r controller.Ru } // image cache is disabled - imageCacheDisabled := cfg == nil || cfg.Config().Machine() == nil || !cfg.Config().Machine().Features().ImageCacheEnabled() + imageCacheDisabled := cfg == nil || cfg.Config().Machine() == nil || !cfg.Config().Machine().Features().ImageCache().LocalEnabled() var ( status cri.ImageCacheStatus diff --git a/internal/app/machined/pkg/controllers/cri/image_cache_config_test.go b/internal/app/machined/pkg/controllers/cri/image_cache_config_test.go index 131c6992c9..c86f26cf83 100644 --- a/internal/app/machined/pkg/controllers/cri/image_cache_config_test.go +++ b/internal/app/machined/pkg/controllers/cri/image_cache_config_test.go @@ -51,7 +51,9 @@ func (suite *ImageCacheConfigSuite) TestReconcileFeatureEnabled() { cfg := config.NewMachineConfig(container.NewV1Alpha1(&v1alpha1.Config{ MachineConfig: &v1alpha1.MachineConfig{ MachineFeatures: &v1alpha1.FeaturesConfig{ - ImageCache: pointer.To(true), + ImageCacheSupport: &v1alpha1.ImageCacheConfig{ + CacheLocalEnabled: pointer.To(true), + }, }, }, })) @@ -117,7 +119,9 @@ func (suite *ImageCacheConfigSuite) TestReconcileWithImageCacheVolume() { v1alpha1Cfg := &v1alpha1.Config{ MachineConfig: &v1alpha1.MachineConfig{ MachineFeatures: &v1alpha1.FeaturesConfig{ - ImageCache: pointer.To(true), + ImageCacheSupport: &v1alpha1.ImageCacheConfig{ + CacheLocalEnabled: pointer.To(true), + }, }, }, } diff --git a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_runtime.go b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_runtime.go index 7a83916cf8..1a7ddae5ab 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_runtime.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_runtime.go @@ -164,7 +164,7 @@ func (r *Runtime) CanApplyImmediate(cfg config.Provider) error { newConfig.MachineConfig.MachineFeatures.KubernetesTalosAPIAccessConfig = currentConfig.MachineConfig.MachineFeatures.KubernetesTalosAPIAccessConfig newConfig.MachineConfig.MachineFeatures.KubePrismSupport = currentConfig.MachineConfig.MachineFeatures.KubePrismSupport newConfig.MachineConfig.MachineFeatures.HostDNSSupport = currentConfig.MachineConfig.MachineFeatures.HostDNSSupport - newConfig.MachineConfig.MachineFeatures.ImageCache = currentConfig.MachineConfig.MachineFeatures.ImageCache + newConfig.MachineConfig.MachineFeatures.ImageCacheSupport = currentConfig.MachineConfig.MachineFeatures.ImageCacheSupport } } diff --git a/pkg/machinery/config/config/machine.go b/pkg/machinery/config/config/machine.go index e1f449ea35..242cda16ad 100644 --- a/pkg/machinery/config/config/machine.go +++ b/pkg/machinery/config/config/machine.go @@ -448,7 +448,7 @@ type Features interface { DiskQuotaSupportEnabled() bool HostDNS() HostDNS KubePrism() KubePrism - ImageCacheEnabled() bool + ImageCache() ImageCache } // KubernetesTalosAPIAccess describes the Kubernetes Talos API access features. @@ -471,6 +471,11 @@ type HostDNS interface { ResolveMemberNames() bool } +// ImageCache describes the image cache configuration. +type ImageCache interface { + LocalEnabled() bool +} + // UdevConfig describes configuration for udev. type UdevConfig interface { Rules() []string diff --git a/pkg/machinery/config/schemas/config.schema.json b/pkg/machinery/config/schemas/config.schema.json index 3b502d8787..7e68ccfb6e 100644 --- a/pkg/machinery/config/schemas/config.schema.json +++ b/pkg/machinery/config/schemas/config.schema.json @@ -2072,7 +2072,7 @@ "x-intellij-html-description": "\u003cp\u003eConfigures host DNS caching resolver.\u003c/p\u003e\n" }, "imageCache": { - "type": "boolean", + "$ref": "#/$defs/v1alpha1.ImageCacheConfig", "title": "imageCache", "description": "Enable Image Cache feature.\n", "markdownDescription": "Enable Image Cache feature.", @@ -2125,6 +2125,19 @@ "additionalProperties": false, "type": "object" }, + "v1alpha1.ImageCacheConfig": { + "properties": { + "localEnabled": { + "type": "boolean", + "title": "localEnabled", + "description": "Enable local image cache.\n", + "markdownDescription": "Enable local image cache.", + "x-intellij-html-description": "\u003cp\u003eEnable local image cache.\u003c/p\u003e\n" + } + }, + "additionalProperties": false, + "type": "object" + }, "v1alpha1.InstallConfig": { "properties": { "disk": { diff --git a/pkg/machinery/config/types/v1alpha1/v1alpha1_features.go b/pkg/machinery/config/types/v1alpha1/v1alpha1_features.go index de60ab836e..448cee3cfd 100644 --- a/pkg/machinery/config/types/v1alpha1/v1alpha1_features.go +++ b/pkg/machinery/config/types/v1alpha1/v1alpha1_features.go @@ -57,9 +57,13 @@ func (f *FeaturesConfig) KubePrism() config.KubePrism { return f.KubePrismSupport } -// ImageCacheEnabled implements config.Features interface. -func (f *FeaturesConfig) ImageCacheEnabled() bool { - return pointer.SafeDeref(f.ImageCache) +// ImageCache implements config.Features interface. +func (f *FeaturesConfig) ImageCache() config.ImageCache { + if f.ImageCacheSupport == nil { + return &ImageCacheConfig{} + } + + return f.ImageCacheSupport } const defaultKubePrismPort = 7445 @@ -92,3 +96,8 @@ func (h *HostDNSConfig) ForwardKubeDNSToHost() bool { func (h *HostDNSConfig) ResolveMemberNames() bool { return pointer.SafeDeref(h.HostDNSResolveMemberNames) } + +// LocalEnabled implements config.ImageCache. +func (i *ImageCacheConfig) LocalEnabled() bool { + return pointer.SafeDeref(i.CacheLocalEnabled) +} diff --git a/pkg/machinery/config/types/v1alpha1/v1alpha1_types.go b/pkg/machinery/config/types/v1alpha1/v1alpha1_types.go index d97b9cc780..8e170fc137 100644 --- a/pkg/machinery/config/types/v1alpha1/v1alpha1_types.go +++ b/pkg/machinery/config/types/v1alpha1/v1alpha1_types.go @@ -2169,7 +2169,7 @@ type FeaturesConfig struct { HostDNSSupport *HostDNSConfig `yaml:"hostDNS,omitempty"` // description: | // Enable Image Cache feature. - ImageCache *bool `yaml:"imageCache,omitempty"` + ImageCacheSupport *ImageCacheConfig `yaml:"imageCache,omitempty"` } // KubePrism describes the configuration for the KubePrism load balancer. @@ -2182,6 +2182,13 @@ type KubePrism struct { ServerPort int `yaml:"port,omitempty"` } +// ImageCacheConfig describes the configuration for the Image Cache feature. +type ImageCacheConfig struct { + // description: | + // Enable local image cache. + CacheLocalEnabled *bool `yaml:"localEnabled,omitempty"` +} + // KubernetesTalosAPIAccessConfig describes the configuration for the Talos API access from Kubernetes pods. type KubernetesTalosAPIAccessConfig struct { // description: | diff --git a/pkg/machinery/config/types/v1alpha1/v1alpha1_types_doc.go b/pkg/machinery/config/types/v1alpha1/v1alpha1_types_doc.go index c4d2a1b41d..b795db8426 100644 --- a/pkg/machinery/config/types/v1alpha1/v1alpha1_types_doc.go +++ b/pkg/machinery/config/types/v1alpha1/v1alpha1_types_doc.go @@ -3467,7 +3467,7 @@ func (FeaturesConfig) Doc() *encoder.Doc { }, { Name: "imageCache", - Type: "bool", + Type: "ImageCacheConfig", Note: "", Description: "Enable Image Cache feature.", Comments: [3]string{"" /* encoder.HeadComment */, "Enable Image Cache feature." /* encoder.LineComment */, "" /* encoder.FootComment */}, @@ -3514,6 +3514,31 @@ func (KubePrism) Doc() *encoder.Doc { return doc } +func (ImageCacheConfig) Doc() *encoder.Doc { + doc := &encoder.Doc{ + Type: "ImageCacheConfig", + Comments: [3]string{"" /* encoder.HeadComment */, "ImageCacheConfig describes the configuration for the Image Cache feature." /* encoder.LineComment */, "" /* encoder.FootComment */}, + Description: "ImageCacheConfig describes the configuration for the Image Cache feature.", + AppearsIn: []encoder.Appearance{ + { + TypeName: "FeaturesConfig", + FieldName: "imageCache", + }, + }, + Fields: []encoder.Doc{ + { + Name: "localEnabled", + Type: "bool", + Note: "", + Description: "Enable local image cache.", + Comments: [3]string{"" /* encoder.HeadComment */, "Enable local image cache." /* encoder.LineComment */, "" /* encoder.FootComment */}, + }, + }, + } + + return doc +} + func (KubernetesTalosAPIAccessConfig) Doc() *encoder.Doc { doc := &encoder.Doc{ Type: "KubernetesTalosAPIAccessConfig", @@ -4193,6 +4218,7 @@ func GetFileDoc() *encoder.FileDoc { SystemDiskEncryptionConfig{}.Doc(), FeaturesConfig{}.Doc(), KubePrism{}.Doc(), + ImageCacheConfig{}.Doc(), KubernetesTalosAPIAccessConfig{}.Doc(), HostDNSConfig{}.Doc(), VolumeMountConfig{}.Doc(), diff --git a/website/content/v1.9/reference/configuration/v1alpha1/config.md b/website/content/v1.9/reference/configuration/v1alpha1/config.md index 237bb6db18..675933fc99 100644 --- a/website/content/v1.9/reference/configuration/v1alpha1/config.md +++ b/website/content/v1.9/reference/configuration/v1alpha1/config.md @@ -2627,7 +2627,7 @@ kubernetesTalosAPIAccess: |`diskQuotaSupport` |bool |
Enable XFS project quota support for EPHEMERAL partition and user disks.Also enables kubelet tracking of ephemeral disk usage in the kubelet via quota.
| | |`kubePrism` |KubePrism |
KubePrism - local proxy/load balancer on defined port that will distributerequests to all API servers in the cluster.
| | |`hostDNS` |HostDNSConfig |Configures host DNS caching resolver. | | -|`imageCache` |bool |Enable Image Cache feature. | | +|`imageCache` |ImageCacheConfig |Enable Image Cache feature. | | @@ -2698,6 +2698,22 @@ HostDNSConfig describes the configuration for the host DNS resolver. +#### imageCache {#Config.machine.features.imageCache} + +ImageCacheConfig describes the configuration for the Image Cache feature. + + + + +| Field | Type | Description | Value(s) | +|-------|------|-------------|----------| +|`localEnabled` |bool |Enable local image cache. | | + + + + + + ### udev {#Config.machine.udev} diff --git a/website/content/v1.9/schemas/config.schema.json b/website/content/v1.9/schemas/config.schema.json index 3b502d8787..7e68ccfb6e 100644 --- a/website/content/v1.9/schemas/config.schema.json +++ b/website/content/v1.9/schemas/config.schema.json @@ -2072,7 +2072,7 @@ "x-intellij-html-description": "\u003cp\u003eConfigures host DNS caching resolver.\u003c/p\u003e\n" }, "imageCache": { - "type": "boolean", + "$ref": "#/$defs/v1alpha1.ImageCacheConfig", "title": "imageCache", "description": "Enable Image Cache feature.\n", "markdownDescription": "Enable Image Cache feature.", @@ -2125,6 +2125,19 @@ "additionalProperties": false, "type": "object" }, + "v1alpha1.ImageCacheConfig": { + "properties": { + "localEnabled": { + "type": "boolean", + "title": "localEnabled", + "description": "Enable local image cache.\n", + "markdownDescription": "Enable local image cache.", + "x-intellij-html-description": "\u003cp\u003eEnable local image cache.\u003c/p\u003e\n" + } + }, + "additionalProperties": false, + "type": "object" + }, "v1alpha1.InstallConfig": { "properties": { "disk": {