Skip to content

Commit 6701261

Browse files
authored
Merge pull request kubernetes#124442 from neolit123/1.31-add-image-pull-policy-to-upgrade-config
kubeadm: support image pull mode and policy in UpgradeConfiguration
2 parents 6d4250e + df87a50 commit 6701261

File tree

11 files changed

+157
-22
lines changed

11 files changed

+157
-22
lines changed

cmd/kubeadm/app/apis/kubeadm/fuzzer/fuzzer.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@ func fuzzUpgradeConfiguration(obj *kubeadm.UpgradeConfiguration, c fuzz.Continue
162162

163163
// Pinning values for fields that get defaults if fuzz value is empty string or nil (thus making the round trip test fail)
164164
obj.Node.EtcdUpgrade = ptr.To(true)
165+
obj.Node.CertificateRenewal = ptr.To(false)
166+
obj.Node.ImagePullPolicy = corev1.PullIfNotPresent
167+
obj.Node.ImagePullSerial = ptr.To(true)
168+
165169
obj.Apply.EtcdUpgrade = ptr.To(true)
166170
obj.Apply.CertificateRenewal = ptr.To(false)
167-
obj.Node.CertificateRenewal = ptr.To(false)
171+
obj.Apply.ImagePullPolicy = corev1.PullIfNotPresent
172+
obj.Apply.ImagePullSerial = ptr.To(true)
173+
168174
kubeadm.SetDefaultTimeouts(&obj.Timeouts)
169175
}

cmd/kubeadm/app/apis/kubeadm/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,14 @@ type UpgradeApplyConfiguration struct {
588588
// SkipPhases is a list of phases to skip during command execution.
589589
// NOTE: This field is currently ignored for "kubeadm upgrade apply", but in the future it will be supported.
590590
SkipPhases []string
591+
592+
// ImagePullPolicy specifies the policy for image pulling during kubeadm "upgrade apply" operations.
593+
// The value of this field must be one of "Always", "IfNotPresent" or "Never".
594+
// If this field is unset kubeadm will default it to "IfNotPresent", or pull the required images if not present on the host.
595+
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
596+
597+
// ImagePullSerial specifies if image pulling performed by kubeadm must be done serially or in parallel.
598+
ImagePullSerial *bool
591599
}
592600

593601
// UpgradeDiffConfiguration contains a list of configurable options which are specific to the "kubeadm upgrade diff" command.
@@ -620,6 +628,14 @@ type UpgradeNodeConfiguration struct {
620628

621629
// Patches contains options related to applying patches to components deployed by kubeadm during "kubeadm upgrade".
622630
Patches *Patches
631+
632+
// ImagePullPolicy specifies the policy for image pulling during kubeadm "upgrade node" operations.
633+
// The value of this field must be one of "Always", "IfNotPresent" or "Never".
634+
// If this field is unset kubeadm will default it to "IfNotPresent", or pull the required images if not present on the host.
635+
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
636+
637+
// ImagePullSerial specifies if image pulling performed by kubeadm must be done serially or in parallel.
638+
ImagePullSerial *bool
623639
}
624640

625641
// UpgradePlanConfiguration contains a list of configurable options which are specific to the "kubeadm upgrade plan" command.

cmd/kubeadm/app/apis/kubeadm/v1beta4/defaults.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,29 @@ func SetDefaults_UpgradeConfiguration(obj *UpgradeConfiguration) {
278278
if obj.Node.EtcdUpgrade == nil {
279279
obj.Node.EtcdUpgrade = ptr.To(true)
280280
}
281-
282281
if obj.Node.CertificateRenewal == nil {
283282
obj.Node.CertificateRenewal = ptr.To(true)
284283
}
284+
if len(obj.Node.ImagePullPolicy) == 0 {
285+
obj.Node.ImagePullPolicy = DefaultImagePullPolicy
286+
}
287+
if obj.Node.ImagePullSerial == nil {
288+
obj.Node.ImagePullSerial = ptr.To(true)
289+
}
285290

286291
if obj.Apply.EtcdUpgrade == nil {
287292
obj.Apply.EtcdUpgrade = ptr.To(true)
288293
}
289-
290294
if obj.Apply.CertificateRenewal == nil {
291295
obj.Apply.CertificateRenewal = ptr.To(true)
292296
}
297+
if len(obj.Apply.ImagePullPolicy) == 0 {
298+
obj.Apply.ImagePullPolicy = DefaultImagePullPolicy
299+
}
300+
if obj.Apply.ImagePullSerial == nil {
301+
obj.Apply.ImagePullSerial = ptr.To(true)
302+
}
303+
293304
if obj.Timeouts == nil {
294305
obj.Timeouts = &Timeouts{}
295306
}

cmd/kubeadm/app/apis/kubeadm/v1beta4/types.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,17 @@ type UpgradeApplyConfiguration struct {
663663
// SkipPhases is a list of phases to skip during command execution.
664664
// NOTE: This field is currently ignored for "kubeadm upgrade apply", but in the future it will be supported.
665665
SkipPhases []string
666+
667+
// ImagePullPolicy specifies the policy for image pulling during kubeadm "upgrade apply" operations.
668+
// The value of this field must be one of "Always", "IfNotPresent" or "Never".
669+
// If this field is unset kubeadm will default it to "IfNotPresent", or pull the required images if not present on the host.
670+
// +optional
671+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
672+
673+
// ImagePullSerial specifies if image pulling performed by kubeadm must be done serially or in parallel.
674+
// Default: true
675+
// +optional
676+
ImagePullSerial *bool `json:"imagePullSerial,omitempty"`
666677
}
667678

668679
// UpgradeDiffConfiguration contains a list of configurable options which are specific to the "kubeadm upgrade diff" command.
@@ -705,6 +716,17 @@ type UpgradeNodeConfiguration struct {
705716
// Patches contains options related to applying patches to components deployed by kubeadm during "kubeadm upgrade".
706717
// +optional
707718
Patches *Patches `json:"patches,omitempty"`
719+
720+
// ImagePullPolicy specifies the policy for image pulling during kubeadm "upgrade node" operations.
721+
// The value of this field must be one of "Always", "IfNotPresent" or "Never".
722+
// If this field is unset kubeadm will default it to "IfNotPresent", or pull the required images if not present on the host.
723+
// +optional
724+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
725+
726+
// ImagePullSerial specifies if image pulling performed by kubeadm must be done serially or in parallel.
727+
// Default: true
728+
// +optional
729+
ImagePullSerial *bool `json:"imagePullSerial,omitempty"`
708730
}
709731

710732
// UpgradePlanConfiguration contains a list of configurable options which are specific to the "kubeadm upgrade plan" command.

cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.conversion.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/apis/kubeadm/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/cmd/phases/upgrade/node/preflight.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ func runPreflight(c workflow.RunData) error {
5454
return err
5555
}
5656

57-
// if this is a control-plane node, pull the basic images
57+
// If this is a control-plane node, pull the basic images
5858
if data.IsControlPlaneNode() {
59+
// Update the InitConfiguration used for RunPullImagesCheck with ImagePullPolicy and ImagePullSerial
60+
// that come from UpgradeNodeConfiguration.
61+
initConfig := data.InitCfg()
62+
initConfig.NodeRegistration.ImagePullPolicy = data.Cfg().Node.ImagePullPolicy
63+
initConfig.NodeRegistration.ImagePullSerial = data.Cfg().Node.ImagePullSerial
64+
5965
if !data.DryRun() {
6066
fmt.Println("[preflight] Pulling images required for setting up a Kubernetes cluster")
6167
fmt.Println("[preflight] This might take a minute or two, depending on the speed of your internet connection")
6268
fmt.Println("[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'")
63-
if err := preflight.RunPullImagesCheck(utilsexec.New(), data.InitCfg(), data.IgnorePreflightErrors()); err != nil {
69+
if err := preflight.RunPullImagesCheck(utilsexec.New(), initConfig, data.IgnorePreflightErrors()); err != nil {
6470
return err
6571
}
6672
} else {

cmd/kubeadm/app/cmd/upgrade/common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ func enforceRequirements(flagSet *pflag.FlagSet, flags *applyPlanFlags, args []s
106106
return nil, nil, nil, nil, errors.Wrap(err, "[upgrade/init config] FATAL")
107107
}
108108

109+
// Set the ImagePullPolicy and ImagePullSerial from the UpgradeApplyConfiguration to the InitConfiguration.
110+
// These are used by preflight.RunPullImagesCheck() when running 'apply'.
111+
if upgradeApply {
112+
initCfg.NodeRegistration.ImagePullPolicy = upgradeCfg.Apply.ImagePullPolicy
113+
initCfg.NodeRegistration.ImagePullSerial = upgradeCfg.Apply.ImagePullSerial
114+
}
115+
109116
newK8sVersion := upgradeCfg.Plan.KubernetesVersion
110117
if upgradeApply {
111118
newK8sVersion = upgradeCfg.Apply.KubernetesVersion

cmd/kubeadm/app/cmd/upgrade/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ func newNodeData(cmd *cobra.Command, args []string, nodeOptions *nodeOptions, ou
180180
return nil, errors.Wrap(err, "unable to fetch the kubeadm-config ConfigMap")
181181
}
182182

183-
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(nodeOptions.ignorePreflightErrors, initCfg.NodeRegistration.IgnorePreflightErrors)
183+
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(nodeOptions.ignorePreflightErrors, upgradeCfg.Node.IgnorePreflightErrors)
184184
if err != nil {
185185
return nil, err
186186
}
187-
// Also set the union of pre-flight errors to JoinConfiguration, to provide a consistent view of the runtime configuration:
187+
// Also set the union of pre-flight errors to InitConfiguration, to provide a consistent view of the runtime configuration:
188188
initCfg.NodeRegistration.IgnorePreflightErrors = sets.List(ignorePreflightErrorsSet)
189189

190190
var patchesDir string

0 commit comments

Comments
 (0)