// It's safe to use args[0] here as the slice has been validated above
flags.newK8sVersionStr=args[0]
// Default the flags dynamically, based on each others' value
err=SetImplicitFlags(flags)
kubeadmutil.CheckErr(err)
err=RunApply(flags)
kubeadmutil.CheckErr(err)
},
}
// Specify the valid flags specific for apply
cmd.Flags().BoolVarP(&flags.nonInteractiveMode,"yes","y",flags.nonInteractiveMode,"Perform the upgrade and do not prompt for confirmation (non-interactive mode).")
cmd.Flags().BoolVarP(&flags.force,"force","f",flags.force,"Force upgrading although some requirements might not be met. This also implies non-interactive mode.")
cmd.Flags().BoolVar(&flags.dryRun,"dry-run",flags.dryRun,"Do not change any state, just output what actions would be applied.")
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.")
returncmd
}
// RunApply takes care of the actual upgrade functionality
// It does the following things:
// - Checks if the cluster is healthy
// - Gets the configuration from the kubeadm-config ConfigMap in the cluster
// - Enforces all version skew policies
// - Asks the user if they really want to upgrade
// - Makes sure the control plane images are available locally on the master(s)
// - Upgrades the control plane components
// - Applies the other resources that'd be created with kubeadm init as well, like
// - Creating the RBAC rules for the Bootstrap Tokens and the cluster-info ConfigMap
// - Applying new kube-dns and kube-proxy manifests
// - Uploads the newly used configuration to the cluster ConfigMap
funcRunApply(flags*applyFlags)error{
// Start with the basics, verify that the cluster is healthy and get the configuration from the cluster (using the ConfigMap)
returnfmt.Errorf("The --version argument is invalid due to these fatal errors: %v",versionSkewErrs.Mandatory)
}
iflen(versionSkewErrs.Skippable)>0{
// Return the error if the user hasn't specified the --force flag
if!flags.force{
returnfmt.Errorf("The --version argument is invalid due to these errors: %v. Can be bypassed if you pass the --force flag",versionSkewErrs.Mandatory)
}
// Soft errors found, but --force was specified
fmt.Printf("[upgrade/version] Found %d potential version compatibility errors but skipping since the --force flag is set: %v\n",len(versionSkewErrs.Skippable),versionSkewErrs.Skippable)
}
}
returnnil
}
// PerformControlPlaneUpgrade actually performs the upgrade procedure for the cluster of your type (self-hosted or static-pod-hosted)
// The tabwriter should be flushed at this stage as we have now put in all the required content for this time. This is required for the tabs' size to be correct.
tabw.Flush()
fmt.Fprintln(w,"")
fmt.Fprintln(w,"You can now apply the upgrade by executing the following command:")
// cmdUpgradeFlags holds the values for the common flags in `kubeadm upgrade`
typecmdUpgradeFlagsstruct{
kubeConfigPathstring
cfgPathstring
allowExperimentalUpgradesbool
allowRCUpgradesbool
printConfigbool
skipPreFlightbool
}
// NewCmdUpgrade returns the cobra command for `kubeadm upgrade`
funcNewCmdUpgrade(outio.Writer)*cobra.Command{
flags:=&cmdUpgradeFlags{
kubeConfigPath:"/etc/kubernetes/admin.conf",
cfgPath:"",
allowExperimentalUpgrades:false,
allowRCUpgrades:false,
printConfig:false,
skipPreFlight:false,
}
cmd:=&cobra.Command{
Use:"upgrade",
Short:"Upgrade your cluster smoothly to a newer version with this command.",
RunE:cmdutil.SubCmdRunE("upgrade"),
}
cmd.PersistentFlags().StringVar(&flags.kubeConfigPath,"kubeconfig",flags.kubeConfigPath,"The KubeConfig file to use for talking to the cluster.")
cmd.PersistentFlags().StringVar(&flags.cfgPath,"config",flags.cfgPath,"Path to kubeadm config file (WARNING: Usage of a configuration file is experimental).")
cmd.PersistentFlags().BoolVar(&flags.allowExperimentalUpgrades,"allow-experimental-upgrades",flags.allowExperimentalUpgrades,"Show unstable versions of Kubernetes as an upgrade alternative and allow upgrading to an alpha/beta/release candidate versions of Kubernetes.")
cmd.PersistentFlags().BoolVar(&flags.allowRCUpgrades,"allow-release-candidate-upgrades",flags.allowRCUpgrades,"Show release candidate versions of Kubernetes as an upgrade alternative and allow upgrading to a release candidate versions of Kubernetes.")
cmd.PersistentFlags().BoolVar(&flags.printConfig,"print-config",flags.printConfig,"Whether the configuration file that will be used in the upgrade should be printed or not.")
cmd.PersistentFlags().BoolVar(&flags.skipPreFlight,"skip-preflight-checks",flags.skipPreFlight,"Skip preflight checks normally run before modifying the system")