Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
add support to skip kube-proxy at first and upgrade it after all apis…
Browse files Browse the repository at this point in the history
…erver upgraded
  • Loading branch information
pacoxu committed Jun 10, 2022
1 parent 9e155aa commit 5d25344
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 6 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/command_descriptor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type CommandDescriptor struct {
// +optional
KubectlUncordon *KubectlUncordonCommandSpec `json:"kubectlUncordon,omitempty"`

// +optional
// not implemented yet
KubeadmUpgradeKubeProxy *KubeadmUpgradeKubeProxySpec `json:"kubeadmUpgradeKubeProxy,omitempty"`

// Pass provide a dummy command for testing the kubeadm-operator workflow.
// +optional
Pass *PassCommandSpec `json:"pass,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/operation_descriptor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type UpgradeOperationSpec struct {
// If this is true, kube-proxy will not be upgraded at first. See more details in https://github.com/kubernetes/kubeadm/issues/2346
// Then kube-proxy will be upgraded after all apiserver are upgraded.
// +optional
UpgradeKubeProxyAtLast bool `json:upgradeKubeProxyAtLast,omitempty`
UpgradeKubeProxyAtLast bool `json:"upgradeKubeProxyAtLast,omitempty"`

// INSERT ADDITIONAL SPEC FIELDS -
// Important: Run "make" to regenerate code after modifying this file
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions commands/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func RunCommand(c *operatorv1.CommandDescriptor, log logr.Logger) error {
if c.UpgradeKubeletAndKubeactl != nil {
return runUpgradeKubectlAndKubelet(c.UpgradeKubeletAndKubeactl, log)
}
if c.KubeadmUpgradeKubeProxy != nil {
return runUpgradeKubeProxy(c.KubeadmUpgradeKubeProxy, log)
}

if c.Pass != nil {
return nil
Expand Down
2 changes: 2 additions & 0 deletions commands/kubeadm_upgrade_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (

// runKubeadmUpgradeApply runs the kubeadm upgrade apply command
func runKubeadmUpgradeApply(spec *operatorv1.KubeadmUpgradeApplyCommandSpec, log logr.Logger) error {
// TODO spec.SkipKubeProxy is not implemented yet

var cmd *cmd
// TODO: add real dry run support
cmd = newCmd("kubeadm", "upgrade", "apply", spec.KubernetesVersion, "--yes", "--v=4")
Expand Down
29 changes: 29 additions & 0 deletions commands/upgrade_kubeproxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2022 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 commands

import (
"github.com/go-logr/logr"

operatorv1 "k8s.io/kubeadm/operator/api/v1alpha1"
)

// TODO it depends on https://github.com/kubernetes/kubeadm/issues/1318
// Currently, kubeadm upgrade apply doesn't support phase
func runUpgradeKubeProxy(spec *operatorv1.KubeadmUpgradeKubeProxySpec, log logr.Logger) error {
return nil
}
30 changes: 30 additions & 0 deletions config/crd/bases/operator.kubeadm.x-k8s.io_operations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ spec:
the version is empty, we will skip
this command.
type: string
skipKubePorxy:
description: skip kube-proxy upgrade
type: boolean
required:
- kubernetesVersion
type: object
kubeadmUpgradeKubeProxy:
description: KubeadmUpgradeApplyCommandSpec
provides...
properties:
kubernetesVersion:
description: KubernetesVersion specifies
the target kubernetes version If
the version is empty, we will skip
this command.
type: string
required:
- kubernetesVersion
type: object
kubeadmUpgradeNode:
description: TODO download the specified
Expand Down Expand Up @@ -323,6 +341,8 @@ spec:
download the binary from official
websites
type: boolean
required:
- kubernetesVersion
type: object
wait:
description: Wait pauses the execution
Expand Down Expand Up @@ -435,6 +455,16 @@ spec:
version
type: string
local:
description: Local is used to determine whether to use local binary
or download from internet.
type: boolean
upgradeKubeProxyAtLast:
description: UpgradeKubeProxyAtLast by default is false. TODO
UpgradeKubeProxyAtLast can be true by default if this should
be default behavior, needs more disscussions. If this is true,
kube-proxy will not be upgraded at first. See more details in
https://github.com/kubernetes/kubeadm/issues/2346 Then kube-proxy
will be upgraded after all apiserver are upgraded.
type: boolean
required:
- kubernetesVersion
Expand Down
18 changes: 18 additions & 0 deletions config/crd/bases/operator.kubeadm.x-k8s.io_runtimetaskgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ spec:
kubernetes version If the version is empty, we
will skip this command.
type: string
skipKubePorxy:
description: skip kube-proxy upgrade
type: boolean
required:
- kubernetesVersion
type: object
kubeadmUpgradeKubeProxy:
description: KubeadmUpgradeApplyCommandSpec provides...
properties:
kubernetesVersion:
description: KubernetesVersion specifies the target
kubernetes version If the version is empty, we
will skip this command.
type: string
required:
- kubernetesVersion
type: object
kubeadmUpgradeNode:
description: TODO download the specified version bin
Expand Down Expand Up @@ -268,6 +284,8 @@ spec:
operator will download the binary from official
websites
type: boolean
required:
- kubernetesVersion
type: object
wait:
description: Wait pauses the execution on the next command
Expand Down
17 changes: 17 additions & 0 deletions config/crd/bases/operator.kubeadm.x-k8s.io_runtimetasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ spec:
description: KubernetesVersion specifies the target kubernetes
version If the version is empty, we will skip this command.
type: string
skipKubePorxy:
description: skip kube-proxy upgrade
type: boolean
required:
- kubernetesVersion
type: object
kubeadmUpgradeKubeProxy:
description: KubeadmUpgradeApplyCommandSpec provides...
properties:
kubernetesVersion:
description: KubernetesVersion specifies the target kubernetes
version If the version is empty, we will skip this command.
type: string
required:
- kubernetesVersion
type: object
kubeadmUpgradeNode:
description: TODO download the specified version bin and replace
Expand Down Expand Up @@ -143,6 +158,8 @@ spec:
will use the binary in /usr/bin If not, operator will
download the binary from official websites
type: boolean
required:
- kubernetesVersion
type: object
wait:
description: Wait pauses the execution on the next command for
Expand Down
23 changes: 18 additions & 5 deletions operations/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperat
KubeadmUpgradeApply: &operatorv1.KubeadmUpgradeApplyCommandSpec{
DryRun: dryRun,
KubernetesVersion: operation.Spec.Upgrade.KubernetesVersion,
SkipKubeProxy: operation.Spec.Upgrade.UpgradeKubeProxyAtLast,
},
},
)
Expand Down Expand Up @@ -128,17 +129,29 @@ func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperat
items = append(items, t2)
}

if operation.Spec.Upgrade.UpgradeKubeProxyAtLast {
t3 := createBasicTaskGroup(operation, "03", "upgrade-kube-proxy")
t3.Spec.Template.Spec.Commands = append(t3.Spec.Template.Spec.Commands,
operatorv1.CommandDescriptor{
KubeadmUpgradeKubeProxy: &operatorv1.KubeadmUpgradeKubeProxySpec{
KubernetesVersion: operation.Spec.Upgrade.KubernetesVersion,
},
},
)
items = append(items, t3)
}

// this can be skipped if there are no worker nodes.
// currently it depends on the selector
t3 := createBasicTaskGroup(operation, "02", "upgrade-w")
setWSelector(&t3)
workerNodes, err := listNodesBySelector(c, &t3.Spec.NodeSelector)
t4 := createBasicTaskGroup(operation, "04", "upgrade-w")
setWSelector(&t4)
workerNodes, err := listNodesBySelector(c, &t4.Spec.NodeSelector)
if err != nil {
fmt.Printf("failed to list nodes: %v", err)
return nil
}
if len(workerNodes.Items) > 0 {
t3.Spec.Template.Spec.Commands = append(t3.Spec.Template.Spec.Commands,
t4.Spec.Template.Spec.Commands = append(t4.Spec.Template.Spec.Commands,
operatorv1.CommandDescriptor{
KubectlDrain: &operatorv1.KubectlDrainCommandSpec{},
},
Expand All @@ -163,7 +176,7 @@ func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperat
KubectlUncordon: &operatorv1.KubectlUncordonCommandSpec{},
},
)
items = append(items, t3)
items = append(items, t4)
}

return &operatorv1.RuntimeTaskGroupList{
Expand Down

0 comments on commit 5d25344

Please sign in to comment.