Skip to content

Commit

Permalink
chore: update image cache config
Browse files Browse the repository at this point in the history
Make it nested, so that we can expand easily to support e.g. distributed
cache.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Nov 27, 2024
1 parent e10e90b commit af91c99
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
}))
Expand Down Expand Up @@ -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),
},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/machinery/config/config/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion pkg/machinery/config/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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": {
Expand Down
15 changes: 12 additions & 3 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
9 changes: 8 additions & 1 deletion pkg/machinery/config/types/v1alpha1/v1alpha1_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: |
Expand Down
28 changes: 27 additions & 1 deletion pkg/machinery/config/types/v1alpha1/v1alpha1_types_doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion website/content/v1.9/reference/configuration/v1alpha1/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ kubernetesTalosAPIAccess:
|`diskQuotaSupport` |bool |<details><summary>Enable XFS project quota support for EPHEMERAL partition and user disks.</summary>Also enables kubelet tracking of ephemeral disk usage in the kubelet via quota.</details> | |
|`kubePrism` |<a href="#Config.machine.features.kubePrism">KubePrism</a> |<details><summary>KubePrism - local proxy/load balancer on defined port that will distribute</summary>requests to all API servers in the cluster.</details> | |
|`hostDNS` |<a href="#Config.machine.features.hostDNS">HostDNSConfig</a> |Configures host DNS caching resolver. | |
|`imageCache` |bool |Enable Image Cache feature. | |
|`imageCache` |<a href="#Config.machine.features.imageCache">ImageCacheConfig</a> |Enable Image Cache feature. | |



Expand Down Expand Up @@ -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}
Expand Down
15 changes: 14 additions & 1 deletion website/content/v1.9/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit af91c99

Please sign in to comment.