Skip to content

Commit ea61d04

Browse files
committed
kubeadm: improve some grammar issues and add post-upgrade phase
1 parent a2f8d31 commit ea61d04

File tree

10 files changed

+87
-80
lines changed

10 files changed

+87
-80
lines changed

cmd/kubeadm/app/cmd/phases/upgrade/apply/addons.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ import (
3838
func NewAddonPhase() workflow.Phase {
3939
return workflow.Phase{
4040
Name: "addon",
41-
Short: "Install the default kubeadm addons",
41+
Short: "Upgrade the default kubeadm addons",
4242
Long: cmdutil.MacroCommandLongDescription,
4343
Phases: []workflow.Phase{
4444
{
4545
Name: "all",
46-
Short: "Install all the addons",
46+
Short: "Upgrade all the addons",
4747
InheritFlags: getAddonPhaseFlags("all"),
4848
RunAllSiblings: true,
4949
},
5050
{
5151
Name: "coredns",
52-
Short: "Install the CoreDNS addon",
52+
Short: "Upgrade the CoreDNS addon",
5353
InheritFlags: getAddonPhaseFlags("coredns"),
5454
Run: runCoreDNSAddon,
5555
},
5656
{
5757
Name: "kube-proxy",
58-
Short: "Install the kube-proxy addon",
58+
Short: "Upgrade the kube-proxy addon",
5959
InheritFlags: getAddonPhaseFlags("kube-proxy"),
6060
Run: runKubeProxyAddon,
6161
},
@@ -69,7 +69,7 @@ func shouldUpgradeAddons(client clientset.Interface, cfg *kubeadmapi.InitConfigu
6969
return false, errors.Wrapf(err, "failed to determine whether all the control plane instances have been upgraded")
7070
}
7171
if len(unupgradedControlPlanes) > 0 {
72-
fmt.Fprintf(out, "[upgrade/addons] Skipping upgrade of addons because control plane instances %v have not been upgraded\n", unupgradedControlPlanes)
72+
fmt.Fprintf(out, "[upgrade/addon] Skipping upgrade of addons because control plane instances %v have not been upgraded\n", unupgradedControlPlanes)
7373
return false, nil
7474
}
7575
return true, nil
@@ -83,7 +83,7 @@ func getInitData(c workflow.RunData) (*kubeadmapi.InitConfiguration, clientset.I
8383
return data.InitCfg(), data.Client(), data.PatchesDir(), data.OutputWriter(), data.DryRun(), nil
8484
}
8585

86-
// runCoreDNSAddon installs the CoreDNS addon.
86+
// runCoreDNSAddon upgrades the CoreDNS addon.
8787
func runCoreDNSAddon(c workflow.RunData) error {
8888
cfg, client, patchesDir, out, dryRun, err := getInitData(c)
8989
if err != nil {
@@ -106,7 +106,7 @@ func runCoreDNSAddon(c workflow.RunData) error {
106106
return nil
107107
}
108108

109-
// runKubeProxyAddon installs the KubeProxy addon.
109+
// runKubeProxyAddon upgrades the KubeProxy addon.
110110
func runKubeProxyAddon(c workflow.RunData) error {
111111
cfg, client, _, out, dryRun, err := getInitData(c)
112112
if err != nil {

cmd/kubeadm/app/cmd/phases/upgrade/apply/bootstraptoken.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ func runBootstrapToken(c workflow.RunData) error {
5151
}
5252

5353
if data.DryRun() {
54-
fmt.Println("[dryrun] Would config cluster-info ConfigMap, RBAC Roles")
54+
fmt.Println("[dryrun] Would configure bootstrap token and cluster-info RBAC rules")
5555
return nil
5656
}
5757

58-
fmt.Println("[bootstrap-token] Configuring the cluster-info ConfigMap and RBAC roles")
58+
fmt.Println("[upgrade/bootstrap-token] Configuring bootstrap token and cluster-info RBAC rules")
5959

6060
client := data.Client()
6161

cmd/kubeadm/app/cmd/phases/upgrade/apply/controlplane.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ func runControlPlane(c workflow.RunData) error {
5656
initCfg, upgradeCfg, client, patchesDir := data.InitCfg(), data.Cfg(), data.Client(), data.PatchesDir()
5757

5858
if data.DryRun() {
59-
fmt.Printf("[dryrun] Would upgrade your Static Pod-hosted control plane to version %q", initCfg.KubernetesVersion)
59+
fmt.Printf("[dryrun] Would upgrade your static Pod-hosted control plane to version %q", initCfg.KubernetesVersion)
6060
return upgrade.DryRunStaticPodUpgrade(patchesDir, initCfg)
6161
}
6262

63-
fmt.Printf("[upgrade/apply] Upgrading your Static Pod-hosted control plane to version %q (timeout: %v)...\n",
63+
fmt.Printf("[upgrade/control-plane] Upgrading your static Pod-hosted control plane to version %q (timeout: %v)...\n",
6464
initCfg.KubernetesVersion, upgradeCfg.Timeouts.UpgradeManifests.Duration)
6565

6666
waiter := apiclient.NewKubeWaiter(client, upgradeCfg.Timeouts.UpgradeManifests.Duration, os.Stdout)
6767
if err := upgrade.PerformStaticPodUpgrade(client, waiter, initCfg, data.EtcdUpgrade(), data.RenewCerts(), patchesDir); err != nil {
6868
return errors.Wrap(err, "couldn't complete the static pod upgrade")
6969
}
7070

71-
fmt.Println("[upgrade] The control plane instance for this node was successfully updated!")
71+
fmt.Println("[upgrade/control-plane] The control plane instance for this node was successfully upgraded!")
7272

7373
return nil
7474
}

cmd/kubeadm/app/cmd/phases/upgrade/apply/kubeconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func runKubeconfig() func(c workflow.RunData) error {
5959
}
6060
}
6161

62-
fmt.Println("[upgrade] The kubeconfig files for this node were successfully updated!")
62+
fmt.Println("[upgrad/kubeconfig] The kubeconfig files for this node were successfully upgraded!")
6363

6464
return nil
6565
}

cmd/kubeadm/app/cmd/phases/upgrade/apply/kubeletconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func runKubeletConfigPhase(c workflow.RunData) error {
6060
initCfg, dryRun := data.InitCfg(), data.DryRun()
6161

6262
// Write the configuration for the kubelet down to disk and print the generated manifests instead of dry-running.
63-
// If not dry-running, the kubelet config file will be backed up to /etc/kubernetes/tmp/ dir, so that it could be
63+
// If not dry-running, the kubelet config file will be backed up to the /etc/kubernetes/tmp/ dir, so that it could be
6464
// recovered if anything goes wrong.
6565
err := upgrade.WriteKubeletConfigFiles(initCfg, data.PatchesDir(), dryRun, data.OutputWriter())
6666
if err != nil {
6767
return err
6868
}
6969

70-
fmt.Println("[upgrade] The kubelet configuration for this node was successfully updated!")
70+
fmt.Println("[upgrade/kubelet-config] The kubelet configuration for this node was successfully updated!")
7171
return nil
7272
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package apply implements phases of 'kubeadm upgrade apply'.
18+
package apply
19+
20+
import (
21+
"github.com/pkg/errors"
22+
23+
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
24+
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
25+
)
26+
27+
// NewPostUpgradePhase returns a new post-upgrade phase.
28+
func NewPostUpgradePhase() workflow.Phase {
29+
return workflow.Phase{
30+
Name: "post-upgrade",
31+
Short: "Run the post upgrade tasks",
32+
Run: runPostUpgrade,
33+
InheritFlags: []string{
34+
options.CfgPath,
35+
options.KubeconfigPath,
36+
options.DryRun,
37+
},
38+
}
39+
}
40+
41+
func runPostUpgrade(c workflow.RunData) error {
42+
_, ok := c.(Data)
43+
if !ok {
44+
return errors.New("preflight phase invoked with an invalid data struct")
45+
}
46+
// TODO: add the post upgrade tasks here when needed
47+
48+
return nil
49+
}

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ import (
4242
func NewPreflightPhase() workflow.Phase {
4343
return workflow.Phase{
4444
Name: "preflight",
45-
Short: "Run upgrade apply preflight checks",
46-
Long: "Run preflight checks for kubeadm upgrade apply.",
45+
Short: "Run preflight checks before upgrade",
4746
Run: runPreflight,
4847
InheritFlags: []string{
4948
options.CfgPath,
@@ -63,7 +62,7 @@ func runPreflight(c workflow.RunData) error {
6362
if !ok {
6463
return errors.New("preflight phase invoked with an invalid data struct")
6564
}
66-
fmt.Println("[preflight] Running preflight checks")
65+
fmt.Println("[upgrade/preflight] Running preflight checks")
6766

6867
printer := &output.TextPrinter{}
6968

@@ -80,20 +79,20 @@ func runPreflight(c workflow.RunData) error {
8079
}
8180

8281
// Run healthchecks against the cluster
83-
klog.V(1).Infoln("[upgrade/apply] Verifying the cluster health")
82+
klog.V(1).Infoln("[upgrade/preflight] Verifying the cluster health")
8483
if err := upgrade.CheckClusterHealth(client, &initCfg.ClusterConfiguration, ignorePreflightErrors, printer); err != nil {
8584
return err
8685
}
8786

8887
// Check if feature gate flags used in the cluster are consistent with the set of features currently supported by kubeadm
8988
if msg := features.CheckDeprecatedFlags(&features.InitFeatureGates, initCfg.FeatureGates); len(msg) > 0 {
9089
for _, m := range msg {
91-
_, _ = printer.Printf("[upgrade/config] %s\n", m)
90+
_, _ = printer.Printf("[upgrade/preflight] %s\n", m)
9291
}
9392
}
9493

9594
// Validate requested and validate actual version
96-
klog.V(1).Infoln("[upgrade/apply] Validating requested and actual version")
95+
klog.V(1).Infoln("[upgrade/preflight] Validating requested and actual version")
9796
if err := configutil.NormalizeKubernetesVersion(&initCfg.ClusterConfiguration); err != nil {
9897
return err
9998
}
@@ -120,14 +119,14 @@ func runPreflight(c workflow.RunData) error {
120119
}
121120

122121
if !data.DryRun() {
123-
fmt.Println("[preflight] Pulling images required for setting up a Kubernetes cluster")
124-
fmt.Println("[preflight] This might take a minute or two, depending on the speed of your internet connection")
125-
fmt.Println("[preflight] You can also perform this action beforehand using 'kubeadm config images pull'")
122+
fmt.Println("[upgrade/preflight] Pulling images required for setting up a Kubernetes cluster")
123+
fmt.Println("[upgrade/preflight] This might take a minute or two, depending on the speed of your internet connection")
124+
fmt.Println("[upgrade/preflight] You can also perform this action beforehand using 'kubeadm config images pull'")
126125
if err := preflight.RunPullImagesCheck(utilsexec.New(), initCfg, ignorePreflightErrors); err != nil {
127126
return err
128127
}
129128
} else {
130-
fmt.Println("[preflight] Would pull the required images (like 'kubeadm config images pull')")
129+
fmt.Println("[dryrun] Would pull the required images (like 'kubeadm config images pull')")
131130
}
132131

133132
return nil
@@ -136,7 +135,7 @@ func runPreflight(c workflow.RunData) error {
136135
// enforceVersionPolicies makes sure that the version the user specified is valid to upgrade to
137136
// There are both fatal and skippable (with --force) errors
138137
func enforceVersionPolicies(newK8sVersionStr string, newK8sVersion *version.Version, allowExperimentalUpgrades, allowRCUpgrades, force bool, versionGetter upgrade.VersionGetter) error {
139-
fmt.Printf("[upgrade/version] You have chosen to upgrade the cluster version to %q\n", newK8sVersionStr)
138+
fmt.Printf("[upgrade/preflight] You have chosen to upgrade the cluster version to %q\n", newK8sVersionStr)
140139

141140
versionSkewErrs := upgrade.EnforceVersionPolicies(versionGetter, newK8sVersionStr, newK8sVersion, allowExperimentalUpgrades, allowRCUpgrades)
142141
if versionSkewErrs != nil {
@@ -153,7 +152,7 @@ func enforceVersionPolicies(newK8sVersionStr string, newK8sVersion *version.Vers
153152
kubeadmutil.FormatErrMsg(versionSkewErrs.Skippable))
154153
}
155154
// Soft errors found, but --force was specified
156-
fmt.Printf("[upgrade/version] Found %d potential version compatibility errors but skipping since the --force flag is set: \n\n%v", len(versionSkewErrs.Skippable), kubeadmutil.FormatErrMsg(versionSkewErrs.Skippable))
155+
fmt.Printf("[upgrade/preflight] Found %d potential version compatibility errors but skipping since the --force flag is set: \n\n%v", len(versionSkewErrs.Skippable), kubeadmutil.FormatErrMsg(versionSkewErrs.Skippable))
157156
}
158157
}
159158
return nil

cmd/kubeadm/app/cmd/phases/upgrade/apply/uploadconfig.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import (
3434
"k8s.io/kubernetes/cmd/kubeadm/app/phases/uploadconfig"
3535
)
3636

37-
// NewUploadConfigPhase returns the phase to uploadConfig
37+
// NewUploadConfigPhase returns a new upload-config phase.
3838
func NewUploadConfigPhase() workflow.Phase {
3939
return workflow.Phase{
4040
Name: "upload-config",
4141
Aliases: []string{"uploadconfig"},
42-
Short: "Upload the kubeadm and kubelet configurations to a ConfigMaps",
42+
Short: "Upload the kubeadm and kubelet configurations to ConfigMaps",
4343
Long: cmdutil.MacroCommandLongDescription,
4444
Phases: []workflow.Phase{
4545
{
@@ -56,7 +56,7 @@ func NewUploadConfigPhase() workflow.Phase {
5656
},
5757
{
5858
Name: "kubelet",
59-
Short: "Upload the kubelet configuration config to a ConfigMap",
59+
Short: "Upload the kubelet configuration to a ConfigMap",
6060
Run: runUploadKubeletConfig,
6161
InheritFlags: getUploadConfigPhaseFlags(),
6262
},
@@ -84,7 +84,7 @@ func runUploadKubeadmConfig(c workflow.RunData) error {
8484
return nil
8585
}
8686

87-
klog.V(1).Infoln("[upload-config] Uploading the kubeadm ClusterConfiguration to a ConfigMap")
87+
klog.V(1).Infoln("[upgrade/upload-config] Uploading the kubeadm ClusterConfiguration to a ConfigMap")
8888
if err := uploadconfig.UploadConfiguration(cfg, client); err != nil {
8989
return errors.Wrap(err, "error uploading the kubeadm ClusterConfiguration")
9090
}
@@ -104,12 +104,12 @@ func runUploadKubeletConfig(c workflow.RunData) error {
104104
return nil
105105
}
106106

107-
klog.V(1).Infoln("[upload-config] Uploading the kubelet configuration to a ConfigMap")
107+
klog.V(1).Infoln("[upgrade/upload-config] Uploading the kubelet configuration to a ConfigMap")
108108
if err = kubeletphase.CreateConfigMap(&cfg.ClusterConfiguration, client); err != nil {
109109
return errors.Wrap(err, "error creating kubelet configuration ConfigMap")
110110
}
111111

112-
klog.V(1).Infoln("[upload-config] Preserving the CRISocket information for the control-plane node")
112+
klog.V(1).Infoln("[upgrade/upload-config] Preserving the CRISocket information for the control-plane node")
113113
if err := patchnodephase.AnnotateCRISocket(client, cfg.NodeRegistration.Name, cfg.NodeRegistration.CRISocket); err != nil {
114114
return errors.Wrap(err, "error writing Crisocket information for the control-plane node")
115115
}

cmd/kubeadm/app/cmd/upgrade/apply.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ func newCmdApply(apf *applyPlanFlags) *cobra.Command {
112112
}
113113

114114
fmt.Println("")
115-
fmt.Printf("[upgrade/successful] SUCCESS! A control plane node of your cluster was upgraded to %q.\n\n", applyData.InitCfg().KubernetesVersion)
116-
fmt.Println("[upgrade/kubelet] Now please proceed with upgrading the rest of the nodes by following the right order.")
115+
fmt.Printf("[upgrade] SUCCESS! A control plane node of your cluster was upgraded to %q.\n\n", applyData.InitCfg().KubernetesVersion)
116+
fmt.Println("[upgrade] Now please proceed with upgrading the rest of the nodes by following the right order.")
117117

118118
return nil
119119
},
@@ -137,6 +137,7 @@ func newCmdApply(apf *applyPlanFlags) *cobra.Command {
137137
applyRunner.AppendPhase(phases.NewKubeletConfigPhase())
138138
applyRunner.AppendPhase(phases.NewBootstrapTokenPhase())
139139
applyRunner.AppendPhase(phases.NewAddonPhase())
140+
applyRunner.AppendPhase(phases.NewPostUpgradePhase())
140141

141142
// Sets the data builder function, that will be used by the runner
142143
// both when running the entire workflow or single phases
@@ -229,12 +230,12 @@ func newApplyData(cmd *cobra.Command, args []string, applyFlags *applyFlags) (*a
229230
printer := &output.TextPrinter{}
230231

231232
// Fetches the cluster configuration
232-
klog.V(1).Infoln("[upgrade/apply] retrieving configuration from cluster")
233+
klog.V(1).Infoln("[upgrade] retrieving configuration from cluster")
233234
initCfg, err := configutil.FetchInitConfigurationFromCluster(client, nil, "upgrade", false, false)
234235
if err != nil {
235236
if apierrors.IsNotFound(err) {
236-
_, _ = printer.Printf("[upgrade/config] In order to upgrade, a ConfigMap called %q in the %q namespace must exist.\n", constants.KubeadmConfigConfigMap, metav1.NamespaceSystem)
237-
_, _ = printer.Printf("[upgrade/config] Use 'kubeadm init phase upload-config --config your-config.yaml' to re-upload it.\n")
237+
_, _ = printer.Printf("[upgrade] In order to upgrade, a ConfigMap called %q in the %q namespace must exist.\n", constants.KubeadmConfigConfigMap, metav1.NamespaceSystem)
238+
_, _ = printer.Printf("[upgrade] Use 'kubeadm init phase upload-config --config your-config.yaml' to re-upload it.\n")
238239
err = errors.Errorf("the ConfigMap %q in the %q namespace was not found", constants.KubeadmConfigConfigMap, metav1.NamespaceSystem)
239240
}
240241
return nil, errors.Wrap(err, "[upgrade/init config] FATAL")

cmd/kubeadm/app/cmd/upgrade/apply_test.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,6 @@ import (
2828
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
2929
)
3030

31-
func TestSessionIsInteractive(t *testing.T) {
32-
var tcases = []struct {
33-
name string
34-
data *applyData
35-
expected bool
36-
}{
37-
{
38-
name: "Explicitly non-interactive",
39-
data: &applyData{
40-
nonInteractiveMode: true,
41-
},
42-
expected: false,
43-
},
44-
{
45-
name: "Implicitly non-interactive since --dryRun is used",
46-
data: &applyData{
47-
dryRun: true,
48-
},
49-
expected: false,
50-
},
51-
{
52-
name: "Implicitly non-interactive since --force is used",
53-
data: &applyData{
54-
force: true,
55-
},
56-
expected: false,
57-
},
58-
{
59-
name: "Interactive session",
60-
data: &applyData{},
61-
expected: true,
62-
},
63-
}
64-
for _, tt := range tcases {
65-
t.Run(tt.name, func(t *testing.T) {
66-
if tt.data.SessionIsInteractive() != tt.expected {
67-
t.Error("unexpected result")
68-
}
69-
})
70-
}
71-
}
72-
7331
var testApplyConfig = fmt.Sprintf(`---
7432
apiVersion: %s
7533
apply:

0 commit comments

Comments
 (0)