Skip to content

Commit a2f8d31

Browse files
committed
kubeadm: improve some grammar issues and add some unit test cases
1 parent 595482d commit a2f8d31

File tree

9 files changed

+185
-102
lines changed

9 files changed

+185
-102
lines changed

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

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,27 @@ limitations under the License.
1818
package apply
1919

2020
import (
21-
"context"
2221
"fmt"
2322
"io"
2423

2524
"github.com/pkg/errors"
2625

27-
apierrors "k8s.io/apimachinery/pkg/api/errors"
28-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2926
clientset "k8s.io/client-go/kubernetes"
30-
"k8s.io/klog/v2"
3127

3228
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3329
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
3430
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
3531
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
36-
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
3732
dnsaddon "k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns"
3833
proxyaddon "k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/proxy"
3934
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
4035
)
4136

42-
// NewAddonPhase returns the addon Cobra command
37+
// NewAddonPhase returns a new addon phase.
4338
func NewAddonPhase() workflow.Phase {
4439
return workflow.Phase{
4540
Name: "addon",
46-
Short: "Install required addons for passing conformance tests",
41+
Short: "Install the default kubeadm addons",
4742
Long: cmdutil.MacroCommandLongDescription,
4843
Phases: []workflow.Phase{
4944
{
@@ -54,13 +49,13 @@ func NewAddonPhase() workflow.Phase {
5449
},
5550
{
5651
Name: "coredns",
57-
Short: "Install the CoreDNS addon to a Kubernetes cluster",
52+
Short: "Install the CoreDNS addon",
5853
InheritFlags: getAddonPhaseFlags("coredns"),
5954
Run: runCoreDNSAddon,
6055
},
6156
{
6257
Name: "kube-proxy",
63-
Short: "Install the kube-proxy addon to a Kubernetes cluster",
58+
Short: "Install the kube-proxy addon",
6459
InheritFlags: getAddonPhaseFlags("kube-proxy"),
6560
Run: runKubeProxyAddon,
6661
},
@@ -74,10 +69,9 @@ func shouldUpgradeAddons(client clientset.Interface, cfg *kubeadmapi.InitConfigu
7469
return false, errors.Wrapf(err, "failed to determine whether all the control plane instances have been upgraded")
7570
}
7671
if len(unupgradedControlPlanes) > 0 {
77-
fmt.Fprintf(out, "[upgrade/addons] skip upgrade addons because control plane instances %v have not been upgraded\n", unupgradedControlPlanes)
72+
fmt.Fprintf(out, "[upgrade/addons] Skipping upgrade of addons because control plane instances %v have not been upgraded\n", unupgradedControlPlanes)
7873
return false, nil
7974
}
80-
8175
return true, nil
8276
}
8377

@@ -89,7 +83,7 @@ func getInitData(c workflow.RunData) (*kubeadmapi.InitConfiguration, clientset.I
8983
return data.InitCfg(), data.Client(), data.PatchesDir(), data.OutputWriter(), data.DryRun(), nil
9084
}
9185

92-
// runCoreDNSAddon installs CoreDNS addon to a Kubernetes cluster
86+
// runCoreDNSAddon installs the CoreDNS addon.
9387
func runCoreDNSAddon(c workflow.RunData) error {
9488
cfg, client, patchesDir, out, dryRun, err := getInitData(c)
9589
if err != nil {
@@ -104,25 +98,6 @@ func runCoreDNSAddon(c workflow.RunData) error {
10498
return nil
10599
}
106100

107-
// If the coredns ConfigMap is missing, show a warning and assume that the
108-
// DNS addon was skipped during "kubeadm init", and that its redeployment on upgrade is not desired.
109-
//
110-
// TODO: remove this once "kubeadm upgrade apply" phases are supported:
111-
// https://github.com/kubernetes/kubeadm/issues/1318
112-
if _, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(
113-
context.TODO(),
114-
kubeadmconstants.CoreDNSConfigMap,
115-
metav1.GetOptions{},
116-
); err != nil && apierrors.IsNotFound(err) {
117-
klog.Warningf("the ConfigMaps %q in the namespace %q were not found. "+
118-
"Assuming that a DNS server was not deployed for this cluster. "+
119-
"Note that once 'kubeadm upgrade apply' supports phases you "+
120-
"will have to skip the DNS upgrade manually",
121-
kubeadmconstants.CoreDNSConfigMap,
122-
metav1.NamespaceSystem)
123-
return nil
124-
}
125-
126101
// Upgrade CoreDNS
127102
if err := dnsaddon.EnsureDNSAddon(&cfg.ClusterConfiguration, client, patchesDir, out, dryRun); err != nil {
128103
return err
@@ -131,7 +106,7 @@ func runCoreDNSAddon(c workflow.RunData) error {
131106
return nil
132107
}
133108

134-
// runKubeProxyAddon installs KubeProxy addon to a Kubernetes cluster
109+
// runKubeProxyAddon installs the KubeProxy addon.
135110
func runKubeProxyAddon(c workflow.RunData) error {
136111
cfg, client, _, out, dryRun, err := getInitData(c)
137112
if err != nil {
@@ -146,25 +121,6 @@ func runKubeProxyAddon(c workflow.RunData) error {
146121
return nil
147122
}
148123

149-
// If the kube-proxy ConfigMap is missing, show a warning and assume that kube-proxy
150-
// was skipped during "kubeadm init", and that its redeployment on upgrade is not desired.
151-
//
152-
// TODO: remove this once "kubeadm upgrade apply" phases are supported:
153-
// https://github.com/kubernetes/kubeadm/issues/1318
154-
if _, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(
155-
context.TODO(),
156-
kubeadmconstants.KubeProxyConfigMap,
157-
metav1.GetOptions{},
158-
); err != nil && apierrors.IsNotFound(err) {
159-
klog.Warningf("the ConfigMap %q in the namespace %q was not found. "+
160-
"Assuming that kube-proxy was not deployed for this cluster. "+
161-
"Note that once 'kubeadm upgrade apply' supports phases you "+
162-
"will have to skip the kube-proxy upgrade manually",
163-
kubeadmconstants.KubeProxyConfigMap,
164-
metav1.NamespaceSystem)
165-
return nil
166-
}
167-
168124
// Upgrade kube-proxy
169125
if err := proxyaddon.EnsureProxyAddon(&cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, client, out, dryRun); err != nil {
170126
return err

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ import (
3030
nodebootstraptoken "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/node"
3131
)
3232

33-
// NewBootstrapTokenPhase returns the phase to bootstrapToken
33+
// NewBootstrapTokenPhase returns a new bootstrap-token phase.
3434
func NewBootstrapTokenPhase() workflow.Phase {
3535
return workflow.Phase{
36-
Name: "bootstrap-token",
37-
Aliases: []string{"bootstraptoken"},
38-
Short: "Generates bootstrap tokens used to join a node to a cluster",
36+
Name: "bootstrap-token",
37+
Short: "Configures bootstrap token and cluster-info RBAC rules",
3938
InheritFlags: []string{
4039
options.CfgPath,
4140
options.KubeconfigPath,
@@ -56,7 +55,7 @@ func runBootstrapToken(c workflow.RunData) error {
5655
return nil
5756
}
5857

59-
fmt.Println("[bootstrap-token] Configuring cluster-info ConfigMap, RBAC Roles")
58+
fmt.Println("[bootstrap-token] Configuring the cluster-info ConfigMap and RBAC roles")
6059

6160
client := data.Client()
6261

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
3030
)
3131

32-
// NewControlPlanePhase creates a kubeadm workflow phase that implements handling of control-plane upgrade.
32+
// NewControlPlanePhase returns a new control-plane phase.
3333
func NewControlPlanePhase() workflow.Phase {
3434
phase := workflow.Phase{
3535
Name: "control-plane",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
2929
)
3030

31-
// NewKubeconfigPhase creates a kubeadm workflow phase that implements handling of kubeconfig upgrade.
31+
// NewKubeconfigPhase returns a new kubeconfig phase.
3232
func NewKubeconfigPhase() workflow.Phase {
3333
phase := workflow.Phase{
3434
Name: "kubeconfig",
@@ -59,7 +59,7 @@ func runKubeconfig() func(c workflow.RunData) error {
5959
}
6060
}
6161

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

6464
return nil
6565
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var (
3434
`)
3535
)
3636

37-
// NewKubeletConfigPhase creates a kubeadm workflow phase that implements handling of kubelet-config upgrade.
37+
// NewKubeletConfigPhase returns a new kubelet-config phase.
3838
func NewKubeletConfigPhase() workflow.Phase {
3939
phase := workflow.Phase{
4040
Name: "kubelet-config",
@@ -59,15 +59,14 @@ func runKubeletConfigPhase(c workflow.RunData) error {
5959

6060
initCfg, dryRun := data.InitCfg(), data.DryRun()
6161

62-
// Write the configuration for the kubelet down to disk and print the generated manifests instead if dry-running.
62+
// Write the configuration for the kubelet down to disk and print the generated manifests instead of dry-running.
6363
// If not dry-running, the kubelet config file will be backed up to /etc/kubernetes/tmp/ dir, so that it could be
64-
// recovered if there is anything goes wrong.
64+
// 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 configuration for this node was successfully updated!")
71-
fmt.Println("[upgrade] Now you should go ahead and upgrade the kubelet package using your package manager.")
70+
fmt.Println("[upgrade] The kubelet configuration for this node was successfully updated!")
7271
return nil
7372
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ import (
3838
"k8s.io/kubernetes/cmd/kubeadm/app/util/output"
3939
)
4040

41-
// NewPreflightPhase creates a kubeadm workflow phase that implements preflight checks for kubeadm upgrade apply.
41+
// NewPreflightPhase returns a new prefight phase.
4242
func NewPreflightPhase() workflow.Phase {
4343
return workflow.Phase{
4444
Name: "preflight",
45-
Short: "Run upgrade apply pre-flight checks",
46-
Long: "Run pre-flight checks for kubeadm upgrade apply.",
45+
Short: "Run upgrade apply preflight checks",
46+
Long: "Run preflight checks for kubeadm upgrade apply.",
4747
Run: runPreflight,
4848
InheritFlags: []string{
4949
options.CfgPath,
@@ -58,13 +58,12 @@ func NewPreflightPhase() workflow.Phase {
5858
}
5959
}
6060

61-
// runPreflight executes preflight checks logic.
6261
func runPreflight(c workflow.RunData) error {
6362
data, ok := c.(Data)
6463
if !ok {
6564
return errors.New("preflight phase invoked with an invalid data struct")
6665
}
67-
fmt.Println("[preflight] Running pre-flight checks")
66+
fmt.Println("[preflight] Running preflight checks")
6867

6968
printer := &output.TextPrinter{}
7069

@@ -81,7 +80,7 @@ func runPreflight(c workflow.RunData) error {
8180
}
8281

8382
// Run healthchecks against the cluster
84-
klog.V(1).Infoln("[upgrade/apply] verifying health of cluster")
83+
klog.V(1).Infoln("[upgrade/apply] Verifying the cluster health")
8584
if err := upgrade.CheckClusterHealth(client, &initCfg.ClusterConfiguration, ignorePreflightErrors, printer); err != nil {
8685
return err
8786
}
@@ -94,7 +93,7 @@ func runPreflight(c workflow.RunData) error {
9493
}
9594

9695
// Validate requested and validate actual version
97-
klog.V(1).Infoln("[upgrade/apply] validating requested and actual version")
96+
klog.V(1).Infoln("[upgrade/apply] Validating requested and actual version")
9897
if err := configutil.NormalizeKubernetesVersion(&initCfg.ClusterConfiguration); err != nil {
9998
return err
10099
}
@@ -110,7 +109,7 @@ func runPreflight(c workflow.RunData) error {
110109
}
111110

112111
versionGetter := upgrade.NewOfflineVersionGetter(upgrade.NewKubeVersionGetter(client), initCfg.KubernetesVersion)
113-
if err := EnforceVersionPolicies(initCfg.KubernetesVersion, upgradeVersion, data.AllowExperimentalUpgrades(), data.AllowRCUpgrades(), data.ForceUpgrade(), versionGetter); err != nil {
112+
if err := enforceVersionPolicies(initCfg.KubernetesVersion, upgradeVersion, data.AllowExperimentalUpgrades(), data.AllowRCUpgrades(), data.ForceUpgrade(), versionGetter); err != nil {
114113
return err
115114
}
116115

@@ -134,23 +133,23 @@ func runPreflight(c workflow.RunData) error {
134133
return nil
135134
}
136135

137-
// EnforceVersionPolicies makes sure that the version the user specified is valid to upgrade to
136+
// enforceVersionPolicies makes sure that the version the user specified is valid to upgrade to
138137
// There are both fatal and skippable (with --force) errors
139-
func EnforceVersionPolicies(newK8sVersionStr string, newK8sVersion *version.Version, allowExperimentalUpgrades, allowRCUpgrades, force bool, versionGetter upgrade.VersionGetter) error {
140-
fmt.Printf("[upgrade/version] You have chosen to change the cluster version to %q\n", newK8sVersionStr)
138+
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)
141140

142141
versionSkewErrs := upgrade.EnforceVersionPolicies(versionGetter, newK8sVersionStr, newK8sVersion, allowExperimentalUpgrades, allowRCUpgrades)
143142
if versionSkewErrs != nil {
144143

145144
if len(versionSkewErrs.Mandatory) > 0 {
146-
return errors.Errorf("the --version argument is invalid due to these fatal errors:\n\n%v\nPlease fix the misalignments highlighted above and try upgrading again",
145+
return errors.Errorf("the version argument is invalid due to these fatal errors:\n\n%v\nPlease fix the misalignments highlighted above and try upgrading again",
147146
kubeadmutil.FormatErrMsg(versionSkewErrs.Mandatory))
148147
}
149148

150149
if len(versionSkewErrs.Skippable) > 0 {
151150
// Return the error if the user hasn't specified the --force flag
152151
if !force {
153-
return errors.Errorf("the --version argument is invalid due to these errors:\n\n%v\nCan be bypassed if you pass the --force flag",
152+
return errors.Errorf("the version argument is invalid due to these errors:\n\n%v\nCan be bypassed if you pass the --force flag",
154153
kubeadmutil.FormatErrMsg(versionSkewErrs.Skippable))
155154
}
156155
// Soft errors found, but --force was specified

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func NewUploadConfigPhase() workflow.Phase {
3939
return workflow.Phase{
4040
Name: "upload-config",
4141
Aliases: []string{"uploadconfig"},
42-
Short: "Upload the kubeadm and kubelet configuration to a ConfigMap",
42+
Short: "Upload the kubeadm and kubelet configurations to a ConfigMaps",
4343
Long: cmdutil.MacroCommandLongDescription,
4444
Phases: []workflow.Phase{
4545
{
4646
Name: "all",
47-
Short: "Upload all configuration to a config map",
47+
Short: "Upload all the configurations to ConfigMaps",
4848
RunAllSiblings: true,
4949
InheritFlags: getUploadConfigPhaseFlags(),
5050
},
@@ -56,7 +56,7 @@ func NewUploadConfigPhase() workflow.Phase {
5656
},
5757
{
5858
Name: "kubelet",
59-
Short: "Upload the kubelet component config to a ConfigMap",
59+
Short: "Upload the kubelet configuration config to a ConfigMap",
6060
Run: runUploadKubeletConfig,
6161
InheritFlags: getUploadConfigPhaseFlags(),
6262
},
@@ -99,19 +99,19 @@ func runUploadKubeletConfig(c workflow.RunData) error {
9999
}
100100

101101
if dryRun {
102-
fmt.Println("[dryrun] Would upload the kubelet component config to a ConfigMap")
102+
fmt.Println("[dryrun] Would upload the kubelet configuration to a ConfigMap")
103103
fmt.Println("[dryrun] Would write the CRISocket annotation for the control-plane node")
104104
return nil
105105
}
106106

107-
klog.V(1).Infoln("[upload-config] Uploading the kubelet component config to a ConfigMap")
107+
klog.V(1).Infoln("[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

112112
klog.V(1).Infoln("[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 {
114-
return errors.Wrap(err, "Error writing Crisocket information for the control-plane node")
114+
return errors.Wrap(err, "error writing Crisocket information for the control-plane node")
115115
}
116116

117117
return nil

0 commit comments

Comments
 (0)