-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Enable configurable parallel image pulls #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
docs/content/customization/generic/parallel-image-pulls.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| +++ | ||
| title = "Parallel Image Pulls" | ||
| +++ | ||
|
|
||
| This customization will be available when the | ||
| [provider-specific cluster configuration patch]({{< ref "..">}}) is included in the `ClusterClass`. | ||
|
|
||
| The parallel image pull configuration can then be manipulated via the cluster variables. | ||
| If the `maxParallelImagePullsPerNode` property is not specified, then the default value of `1` will be used | ||
| which is equivalent to serialized image pulls. | ||
|
|
||
| Setting this value to `0` results in unlimited parallel image pulls. | ||
|
|
||
| ### Example | ||
|
|
||
| ```yaml | ||
| apiVersion: cluster.x-k8s.io/v1beta1 | ||
| kind: Cluster | ||
| metadata: | ||
| name: <NAME> | ||
| spec: | ||
| topology: | ||
| variables: | ||
| - name: clusterConfig | ||
| value: | ||
| maxParallelImagePullsPerNodePerNode: 10 | ||
| ``` | ||
|
|
||
| Applying this configuration will result in a `KubeletConfiguration` patch being added which will be | ||
| applied by `kubeadm` on `init` and `join`: | ||
|
|
||
| - `KubeadmControlPlaneTemplate`: | ||
|
|
||
| - ```yaml | ||
| spec: | ||
| template: | ||
| spec: | ||
| kubeadmConfigSpec: | ||
| files: | ||
| - path: "/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json" | ||
| owner: "root:root" | ||
| permissions: "0644" | ||
| content: |- | ||
| --- | ||
| apiVersion: kubelet.config.k8s.io/v1beta1 | ||
| kind: KubeletConfiguration | ||
| serializeImagePulls: false | ||
| maxParallelImagePulls: 10 | ||
| ``` | ||
|
|
||
| - `KubeadmConfigTemplate` | ||
|
|
||
| - ```yaml | ||
| spec: | ||
| kubeadmConfigSpec: | ||
| files: | ||
| - path: "/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json" | ||
| owner: "root:root" | ||
| permissions: "0644" | ||
| content: |- | ||
| --- | ||
| apiVersion: kubelet.config.k8s.io/v1beta1 | ||
| kind: KubeletConfiguration | ||
| serializeImagePulls: false | ||
| maxParallelImagePulls: 10 | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
pkg/handlers/generic/mutation/parallelimagepulls/embedded/kubeletconfigpatch.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| apiVersion: kubelet.config.k8s.io/v1beta1 | ||
| kind: KubeletConfiguration | ||
| serializeImagePulls: false | ||
| {{- if gt .MaxParallelImagePullsPerNode 0 }} | ||
| maxParallelImagePulls: {{ .MaxParallelImagePullsPerNode }} | ||
| {{- end }} |
179 changes: 179 additions & 0 deletions
179
pkg/handlers/generic/mutation/parallelimagepulls/inject.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| // Copyright 2025 Nutanix. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package parallelimagepulls | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| _ "embed" | ||
| "fmt" | ||
| "text/template" | ||
|
|
||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" | ||
| controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" | ||
| runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" | ||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" | ||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches" | ||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors" | ||
| "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables" | ||
| ) | ||
|
|
||
| const ( | ||
| // VariableName is the external patch variable name. | ||
| VariableName = "maxParallelImagePullsPerNode" | ||
|
|
||
| kubeletConfigurationPatchFilePath = "/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json" | ||
| ) | ||
|
|
||
| var ( | ||
| //go:embed embedded/kubeletconfigpatch.yaml | ||
| kubeletConfigPatchYAML []byte | ||
|
|
||
| kubeletConfigPatchTemplate = template.Must(template.New("kubeletConfigPatch").Parse(string(kubeletConfigPatchYAML))) | ||
| ) | ||
|
|
||
| type maxParallelImagePullsPerNode struct { | ||
| variableName string | ||
| variableFieldPath []string | ||
| } | ||
|
|
||
| func NewPatch() *maxParallelImagePullsPerNode { | ||
| return newMaxParallelImagePullsPerNodePatch( | ||
| v1alpha1.ClusterConfigVariableName, | ||
| VariableName, | ||
| ) | ||
| } | ||
|
|
||
| func newMaxParallelImagePullsPerNodePatch( | ||
| variableName string, | ||
| variableFieldPath ...string, | ||
| ) *maxParallelImagePullsPerNode { | ||
| return &maxParallelImagePullsPerNode{ | ||
| variableName: variableName, | ||
| variableFieldPath: variableFieldPath, | ||
| } | ||
| } | ||
|
|
||
| func (h *maxParallelImagePullsPerNode) Mutate( | ||
| ctx context.Context, | ||
| obj *unstructured.Unstructured, | ||
| vars map[string]apiextensionsv1.JSON, | ||
| holderRef runtimehooksv1.HolderReference, | ||
| _ client.ObjectKey, | ||
| clusterGetter mutation.ClusterGetter, | ||
| ) error { | ||
| log := ctrl.LoggerFrom(ctx).WithValues( | ||
| "holderRef", holderRef, | ||
| ) | ||
|
|
||
| maxParallelImagePullsPerNode, err := variables.Get[int32]( | ||
| vars, | ||
| h.variableName, | ||
| h.variableFieldPath..., | ||
| ) | ||
| if err != nil { | ||
| if variables.IsNotFoundError(err) { | ||
| log.V(5).Info("max parallel image pulls is not set, skipping mutation") | ||
| return nil | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| if maxParallelImagePullsPerNode == 1 { | ||
| log.V(5).Info("max parallel image pulls is set to 1, skipping mutation resulting in serialized image pulls") | ||
| return nil | ||
| } | ||
|
|
||
| log = log.WithValues( | ||
| "variableName", | ||
| h.variableName, | ||
| "variableFieldPath", | ||
| h.variableFieldPath, | ||
| "variableValue", | ||
| maxParallelImagePullsPerNode, | ||
| ) | ||
|
|
||
| kubeletConfigPatch, err := templateMaxParallelImagePullsPerNodeConfigFile(maxParallelImagePullsPerNode) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := patches.MutateIfApplicable( | ||
| obj, | ||
| vars, | ||
| &holderRef, | ||
| selectors.ControlPlane(), | ||
| log, | ||
| func(obj *controlplanev1.KubeadmControlPlaneTemplate) error { | ||
| log.WithValues( | ||
| "patchedObjectKind", obj.GetObjectKind().GroupVersionKind().String(), | ||
| "patchedObjectName", client.ObjectKeyFromObject(obj), | ||
| ).Info("adding max parallel image pulls patch to control plane kubeadm config spec") | ||
|
|
||
| obj.Spec.Template.Spec.KubeadmConfigSpec.Files = append( | ||
| obj.Spec.Template.Spec.KubeadmConfigSpec.Files, | ||
| *kubeletConfigPatch, | ||
| ) | ||
|
|
||
| return nil | ||
| }, | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := patches.MutateIfApplicable( | ||
| obj, | ||
| vars, | ||
| &holderRef, | ||
| selectors.WorkersKubeadmConfigTemplateSelector(), | ||
| log, | ||
| func(obj *bootstrapv1.KubeadmConfigTemplate) error { | ||
| log.WithValues( | ||
| "patchedObjectKind", obj.GetObjectKind().GroupVersionKind().String(), | ||
| "patchedObjectName", client.ObjectKeyFromObject(obj), | ||
| ).Info("adding max parallel image pulls patch to worker node kubeadm config template") | ||
|
|
||
| obj.Spec.Template.Spec.Files = append( | ||
| obj.Spec.Template.Spec.Files, | ||
| *kubeletConfigPatch, | ||
| ) | ||
|
|
||
| return nil | ||
| }, | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // templateMaxParallelImagePullsPerNodeConfigFile adds the max parallel image pulls configuration patch file | ||
| // to the KCPTemplate. | ||
| func templateMaxParallelImagePullsPerNodeConfigFile( | ||
| maxParallelImagePullsPerNode int32, | ||
| ) (*bootstrapv1.File, error) { | ||
| templateInput := struct { | ||
| MaxParallelImagePullsPerNode int32 | ||
| }{ | ||
| MaxParallelImagePullsPerNode: maxParallelImagePullsPerNode, | ||
| } | ||
| var b bytes.Buffer | ||
| err := kubeletConfigPatchTemplate.Execute(&b, templateInput) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed executing kubeletconfig patch template: %w", err) | ||
| } | ||
|
|
||
| return &bootstrapv1.File{ | ||
| Path: kubeletConfigurationPatchFilePath, | ||
| Owner: "root:root", | ||
| Permissions: "0644", | ||
| Content: b.String(), | ||
| }, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.