Skip to content

Commit 88b9395

Browse files
authored
Merge pull request kubernetes#127289 from SataQiu/fix-node-20240911
kubeadm: skip addon phase on worker node
2 parents 1d3c003 + 036e072 commit 88b9395

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,26 @@ func shouldUpgradeAddons(client clientset.Interface, cfg *kubeadmapi.InitConfigu
7373
return true, nil
7474
}
7575

76-
func getInitData(c workflow.RunData) (*kubeadmapi.InitConfiguration, clientset.Interface, string, io.Writer, bool, error) {
76+
func getInitData(c workflow.RunData) (*kubeadmapi.InitConfiguration, clientset.Interface, string, io.Writer, bool, bool, error) {
7777
data, ok := c.(Data)
7878
if !ok {
79-
return nil, nil, "", nil, false, errors.New("addon phase invoked with an invalid data struct")
79+
return nil, nil, "", nil, false, false, errors.New("addon phase invoked with an invalid data struct")
8080
}
81-
return data.InitCfg(), data.Client(), data.PatchesDir(), data.OutputWriter(), data.DryRun(), nil
81+
return data.InitCfg(), data.Client(), data.PatchesDir(), data.OutputWriter(), data.DryRun(), data.IsControlPlaneNode(), nil
8282
}
8383

8484
// runCoreDNSAddon upgrades the CoreDNS addon.
8585
func runCoreDNSAddon(c workflow.RunData) error {
86-
cfg, client, patchesDir, out, dryRun, err := getInitData(c)
86+
cfg, client, patchesDir, out, dryRun, isControlPlaneNode, err := getInitData(c)
8787
if err != nil {
8888
return err
8989
}
9090

91+
if !isControlPlaneNode {
92+
fmt.Println("[upgrade/addon] Skipping addon/coredns phase. Not a control plane node.")
93+
return nil
94+
}
95+
9196
shouldUpgradeAddons, err := shouldUpgradeAddons(client, cfg, out)
9297
if err != nil {
9398
return err
@@ -105,11 +110,16 @@ func runCoreDNSAddon(c workflow.RunData) error {
105110

106111
// runKubeProxyAddon upgrades the kube-proxy addon.
107112
func runKubeProxyAddon(c workflow.RunData) error {
108-
cfg, client, _, out, dryRun, err := getInitData(c)
113+
cfg, client, _, out, dryRun, isControlPlaneNode, err := getInitData(c)
109114
if err != nil {
110115
return err
111116
}
112117

118+
if !isControlPlaneNode {
119+
fmt.Println("[upgrade/addon] Skipping addon/kube-proxy phase. Not a control plane node.")
120+
return nil
121+
}
122+
113123
shouldUpgradeAddons, err := shouldUpgradeAddons(client, cfg, out)
114124
if err != nil {
115125
return err

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (t *testData) RenewCerts() bool { return false }
3636
func (t *testData) DryRun() bool { return false }
3737
func (t *testData) Cfg() *kubeadmapi.UpgradeConfiguration { return nil }
3838
func (t *testData) InitCfg() *kubeadmapi.InitConfiguration { return nil }
39+
func (t *testData) IsControlPlaneNode() bool { return false }
3940
func (t *testData) Client() clientset.Interface { return nil }
4041
func (t *testData) IgnorePreflightErrors() sets.Set[string] { return nil }
4142
func (t *testData) PatchesDir() string { return "" }

cmd/kubeadm/app/cmd/phases/upgrade/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Data interface {
3333
DryRun() bool
3434
Cfg() *kubeadmapi.UpgradeConfiguration
3535
InitCfg() *kubeadmapi.InitConfiguration
36+
IsControlPlaneNode() bool
3637
Client() clientset.Interface
3738
IgnorePreflightErrors() sets.Set[string]
3839
PatchesDir() string

cmd/kubeadm/app/cmd/phases/upgrade/data_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func (t *testData) RenewCerts() bool { return false }
3636
func (t *testData) DryRun() bool { return false }
3737
func (t *testData) Cfg() *kubeadmapi.UpgradeConfiguration { return nil }
3838
func (t *testData) InitCfg() *kubeadmapi.InitConfiguration { return nil }
39+
func (t *testData) IsControlPlaneNode() bool { return false }
3940
func (t *testData) Client() clientset.Interface { return nil }
4041
func (t *testData) IgnorePreflightErrors() sets.Set[string] { return nil }
4142
func (t *testData) PatchesDir() string { return "" }

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ import (
2626
type Data interface {
2727
upgrade.Data
2828

29-
IsControlPlaneNode() bool
3029
KubeConfigPath() string
3130
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,9 @@ func (d *applyData) AllowRCUpgrades() bool {
351351
func (d *applyData) ForceUpgrade() bool {
352352
return d.force
353353
}
354+
355+
// IsControlPlaneNode returns if the node is a control-plane node.
356+
func (d *applyData) IsControlPlaneNode() bool {
357+
// `kubeadm upgrade apply` should always be executed on a control-plane node
358+
return true
359+
}

0 commit comments

Comments
 (0)