Skip to content

Commit

Permalink
feat(cluster): support upgrade kubernetes version
Browse files Browse the repository at this point in the history
  • Loading branch information
QianChenglong authored and tke-robot committed Jun 24, 2020
1 parent 130e0b4 commit c7703cc
Show file tree
Hide file tree
Showing 40 changed files with 2,081 additions and 621 deletions.
58 changes: 57 additions & 1 deletion api/openapi/zz_generated.openapi.go

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

42 changes: 38 additions & 4 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// +genclient
Expand Down Expand Up @@ -116,7 +117,11 @@ type ClusterSpec struct {
ClusterCredentialRef *corev1.LocalObjectReference

// Etcd holds configuration for etcd.
// +optional
Etcd *Etcd
// Upgrade control upgrade process.
// +optional
Upgrade Upgrade
}

// ClusterStatus represents information about the status of a cluster.
Expand Down Expand Up @@ -186,12 +191,14 @@ const (
type ClusterPhase string

const (
// ClusterRunning is the normal running phase.
ClusterRunning ClusterPhase = "Running"
// ClusterInitializing is the initialize phase.
ClusterInitializing ClusterPhase = "Initializing"
// ClusterRunning is the normal running phase.
ClusterRunning ClusterPhase = "Running"
// ClusterFailed is the failed phase.
ClusterFailed ClusterPhase = "Failed"
// ClusterUpgrading means that the cluster is in upgrading process.
ClusterUpgrading ClusterPhase = "Upgrading"
// ClusterTerminating means the cluster is undergoing graceful termination.
ClusterTerminating ClusterPhase = "Terminating"
)
Expand Down Expand Up @@ -408,6 +415,31 @@ type ExternalEtcd struct {
KeyFile string
}

type Upgrade struct {
// Upgrade mode, default value is Auto.
Mode UpgradeMode
// Upgrade strategy config.
Strategy UpgradeStrategy
}

type UpgradeMode string

const (
// Upgrade nodes automatically.
UpgradeModeAuto = UpgradeMode("Auto")
// Manual upgrade nodes which means user need label node with `platform.tkestack.io/need-upgrade`.
UpgradeModeManual = UpgradeMode("Manual")
)

// UpgradeStrategy used to control the upgrade process.
type UpgradeStrategy struct {
// The maximum number of pods that can be unready during the upgrade.
// 0% means all pods need to be ready after evition.
// 100% means ignore any pods unready which may be used in one worker node, use this carefully!
// default value is 0%.
MaxUnready intstr.IntOrString
}

// ResourceList is a set of (resource name, quantity) pairs.
type ResourceList map[string]resource.Quantity

Expand Down Expand Up @@ -1387,12 +1419,14 @@ type MachineCondition struct {
type MachinePhase string

const (
// MachineRunning is the normal running phase
MachineRunning MachinePhase = "Running"
// MachineInitializing is the initialize phase
MachineInitializing MachinePhase = "Initializing"
// MachineRunning is the normal running phase
MachineRunning MachinePhase = "Running"
// MachineFailed is the failed phase
MachineFailed MachinePhase = "Failed"
// MachineUpgrading means that the machine is in upgrading process.
MachineUpgrading MachinePhase = "Upgrading"
// MachineTerminating is the terminating phase
MachineTerminating MachinePhase = "Terminating"
)
Expand Down
10 changes: 10 additions & 0 deletions api/platform/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func (in *Cluster) RemoveAddress(addrType AddressType) {
in.Status.Addresses = addrs
}

func (in *Cluster) GetCondition(conditionType string) *ClusterCondition {
for _, condition := range in.Status.Conditions {
if condition.Type == conditionType {
return &condition
}
}

return nil
}

func (in *Cluster) SetCondition(newCondition ClusterCondition) {
var conditions []ClusterCondition

Expand Down
11 changes: 11 additions & 0 deletions api/platform/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ package v1

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

func SetDefaults_ClusterSpec(obj *ClusterSpec) {
if obj.Upgrade.Mode == "" {
obj.Upgrade.Mode = UpgradeModeAuto
}
if obj.Upgrade.Strategy.MaxUnready == nil {
maxUnready := intstr.FromInt(0)
obj.Upgrade.Strategy.MaxUnready = &maxUnready
}
}

func SetDefaults_ClusterStatus(obj *ClusterStatus) {
if obj.Phase == "" {
obj.Phase = ClusterInitializing
Expand Down
Loading

0 comments on commit c7703cc

Please sign in to comment.