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
kubeadm: delete pre-pull ds and add pull images check in upgrade apply and upgrade node #90788
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package node | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/preflight" | ||
utilsexec "k8s.io/utils/exec" | ||
) | ||
|
||
// NewPreflightPhase creates a kubeadm workflow phase that implements preflight checks for a new node join | ||
func NewPreflightPhase() workflow.Phase { | ||
return workflow.Phase{ | ||
Name: "preflight", | ||
Short: "Run upgrade node pre-flight checks", | ||
Long: "Run pre-flight checks for kubeadm upgrade node.", | ||
Run: runPreflight, | ||
InheritFlags: []string{ | ||
options.IgnorePreflightErrors, | ||
}, | ||
} | ||
} | ||
|
||
// runPreflight executes preflight checks logic. | ||
func runPreflight(c workflow.RunData) error { | ||
data, ok := c.(Data) | ||
if !ok { | ||
return errors.New("preflight phase invoked with an invalid data struct") | ||
} | ||
fmt.Println("[preflight] Running pre-flight checks") | ||
|
||
// First, check if we're root separately from the other preflight checks and fail fast | ||
if err := preflight.RunRootCheckOnly(data.IgnorePreflightErrors()); err != nil { | ||
return err | ||
} | ||
|
||
// if this is a control-plane node, pull the basic images | ||
if data.IsControlPlaneNode() { | ||
if !data.DryRun() { | ||
fmt.Println("[preflight] Pulling images required for setting up a Kubernetes cluster") | ||
fmt.Println("[preflight] This might take a minute or two, depending on the speed of your internet connection") | ||
fmt.Println("[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'") | ||
if err := preflight.RunPullImagesCheck(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors()); err != nil { | ||
return err | ||
} | ||
} else { | ||
fmt.Println("[preflight] Would pull the required images (like 'kubeadm config images pull')") | ||
} | ||
} else { | ||
fmt.Println("[preflight] Skipping prepull. Not a control plane node.") | ||
return nil | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,17 +22,19 @@ import ( | |
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/apimachinery/pkg/util/version" | ||
clientset "k8s.io/client-go/kubernetes" | ||
"k8s.io/klog" | ||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/constants" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/features" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/preflight" | ||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient" | ||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config" | ||
utilsexec "k8s.io/utils/exec" | ||
) | ||
|
||
const ( | ||
|
@@ -89,6 +91,8 @@ func NewCmdApply(apf *applyPlanFlags) *cobra.Command { | |
cmd.Flags().BoolVar(&flags.etcdUpgrade, "etcd-upgrade", flags.etcdUpgrade, "Perform the upgrade of etcd.") | ||
cmd.Flags().BoolVar(&flags.renewCerts, options.CertificateRenewal, flags.renewCerts, "Perform the renewal of certificates used by component changed during upgrades.") | ||
cmd.Flags().DurationVar(&flags.imagePullTimeout, "image-pull-timeout", flags.imagePullTimeout, "The maximum amount of time to wait for the control plane pods to be downloaded.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should go through deprecation... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if we should keep this flag operational until we can remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically the flag should be operational until we remove it, which might be a bit difficult given we are removing the backend that it targets. |
||
// TODO: The flag was deprecated in 1.19; remove the flag following a GA deprecation policy of 12 months or 2 releases (whichever is longer) | ||
cmd.Flags().MarkDeprecated("image-pull-timeout", "This flag is deprecated and will be removed in a future version.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a comment on top of this deprecation line:
xref https://kubernetes.io/docs/reference/using-api/deprecation-policy/#deprecating-a-flag-or-cli There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
options.AddKustomizePodsFlag(cmd.Flags(), &flags.kustomizeDir) | ||
|
||
return cmd | ||
|
@@ -145,22 +149,18 @@ func runApply(flags *applyFlags, userVersion string) error { | |
} | ||
} | ||
|
||
// Set the timeout as flags.imagePullTimeout to ensure that Prepuller truly respects 'image-pull-timeout' flag | ||
waiter := getWaiter(flags.dryRun, client, flags.imagePullTimeout) | ||
|
||
// Use a prepuller implementation based on creating DaemonSets | ||
// and block until all DaemonSets are ready; then we know for sure that all control plane images are cached locally | ||
klog.V(1).Infoln("[upgrade/apply] creating prepuller") | ||
prepuller := upgrade.NewDaemonSetPrepuller(client, waiter, &cfg.ClusterConfiguration) | ||
componentsToPrepull := constants.ControlPlaneComponents | ||
if cfg.Etcd.External == nil && flags.etcdUpgrade { | ||
componentsToPrepull = append(componentsToPrepull, constants.Etcd) | ||
} | ||
if err := upgrade.PrepullImagesInParallel(prepuller, flags.imagePullTimeout, componentsToPrepull); err != nil { | ||
return errors.Wrap(err, "[upgrade/prepull] Failed prepulled the images for the control plane components error") | ||
if !flags.dryRun { | ||
fmt.Println("[upgrade/prepull] Pulling images required for setting up a Kubernetes cluster") | ||
fmt.Println("[upgrade/prepull] This might take a minute or two, depending on the speed of your internet connection") | ||
fmt.Println("[upgrade/prepull] You can also perform this action in beforehand using 'kubeadm config images pull'") | ||
if err := preflight.RunPullImagesCheck(utilsexec.New(), cfg, sets.NewString(cfg.NodeRegistration.IgnorePreflightErrors...)); err != nil { | ||
return err | ||
} | ||
} else { | ||
fmt.Println("[upgrade/prepull] Would pull the required images (like 'kubeadm config images pull')") | ||
} | ||
|
||
waiter = getWaiter(flags.dryRun, client, upgrade.UpgradeManifestTimeout) | ||
waiter := getWaiter(flags.dryRun, client, upgrade.UpgradeManifestTimeout) | ||
|
||
// Now; perform the upgrade procedure | ||
klog.V(1).Infoln("[upgrade/apply] performing upgrade") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the fact, that we are introducing a new phase here. Makes things much more symmetric with the rest of the phased commands.