Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(platform): support master scale #908

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/openapi/zz_generated.openapi.go

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

7 changes: 6 additions & 1 deletion api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ type ClusterSpec struct {
Properties ClusterProperty
// +optional
Machines []ClusterMachine

// +optional
ScalingMachines []ClusterMachine
// +optional
DockerExtraArgs map[string]string
// +optional
Expand Down Expand Up @@ -216,6 +217,10 @@ const (
ClusterUpgrading ClusterPhase = "Upgrading"
// ClusterTerminating means the cluster is undergoing graceful termination.
ClusterTerminating ClusterPhase = "Terminating"
// ClusterUpscaling means the cluster is undergoing graceful up scaling.
ClusterUpscaling ClusterPhase = "Upscaling"
// ClusterDownscaling means the cluster is undergoing graceful down scaling.
ClusterDownscaling ClusterPhase = "Downscaling"
)

// ClusterCondition contains details for the current condition of this cluster.
Expand Down
11 changes: 9 additions & 2 deletions api/platform/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ func (in *Cluster) GetCondition(conditionType string) *ClusterCondition {
return nil
}

func (in *Cluster) SetCondition(newCondition ClusterCondition) {
func (in *Cluster) KeepHistory(keepHistory bool, condition ClusterCondition) bool {
if !keepHistory {
return false
}
return condition.Status == ConditionTrue
}

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

exist := false
Expand All @@ -101,7 +108,7 @@ func (in *Cluster) SetCondition(newCondition ClusterCondition) {
newCondition.LastProbeTime = metav1.Now()
}
for _, condition := range in.Status.Conditions {
if condition.Type == newCondition.Type {
if condition.Type == newCondition.Type && !in.KeepHistory(keepHistory, condition) {
exist = true
if newCondition.LastTransitionTime.IsZero() {
newCondition.LastTransitionTime = condition.LastTransitionTime
Expand Down
774 changes: 419 additions & 355 deletions api/platform/v1/generated.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/platform/v1/generated.proto

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

6 changes: 6 additions & 0 deletions api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ type ClusterSpec struct {
HostnameAsNodename bool `json:"hostnameAsNodename,omitempty" protobuf:"bytes,23,opt,name=hostnameAsNodename"`
// +optional
NetworkArgs map[string]string `json:"networkArgs,omitempty" protobuf:"bytes,24,name=networkArgs"`
// +optional
ScalingMachines []ClusterMachine `json:"scalingMachines,omitempty" protobuf:"bytes,25,rep,name=scalingMachines"`
}

// ClusterStatus represents information about the status of a cluster.
Expand Down Expand Up @@ -221,6 +223,10 @@ const (
ClusterUpgrading ClusterPhase = "Upgrading"
// ClusterTerminating means the cluster is undergoing graceful termination.
ClusterTerminating ClusterPhase = "Terminating"
// ClusterUpscaling means the cluster is undergoing graceful up scaling.
ClusterUpscaling ClusterPhase = "Upscaling"
// ClusterDownscaling means the cluster is undergoing graceful down scaling.
ClusterDownscaling ClusterPhase = "Downscaling"
)

// ClusterCondition contains details for the current condition of this cluster.
Expand Down
2 changes: 2 additions & 0 deletions api/platform/v1/zz_generated.conversion.go

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

7 changes: 7 additions & 0 deletions api/platform/v1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions api/platform/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"tkestack.io/tke/api/platform"
clusterutil "tkestack.io/tke/pkg/platform/provider/baremetal/cluster"
clusterprovider "tkestack.io/tke/pkg/platform/provider/cluster"
"tkestack.io/tke/pkg/platform/types"
utilmath "tkestack.io/tke/pkg/util/math"
Expand Down Expand Up @@ -62,11 +63,22 @@ func ValidateClusterUpdate(cluster *types.Cluster, oldCluster *types.Cluster) fi
allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(cluster.Spec.ControllerManagerExtraArgs, oldCluster.Spec.ControllerManagerExtraArgs, fldPath.Child("controllerManagerExtraArgs"))...)
allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(cluster.Spec.SchedulerExtraArgs, oldCluster.Spec.SchedulerExtraArgs, fldPath.Child("schedulerExtraArgs"))...)

allErrs = append(allErrs, ValidateClusterScale(cluster.Cluster, oldCluster.Cluster, fldPath.Child("machines"))...)
allErrs = append(allErrs, ValidateCluster(cluster)...)

return allErrs
}

// ValidateClusterScale tests if master scale up/down to a cluster is valid.
func ValidateClusterScale(cluster *platform.Cluster, oldCluster *platform.Cluster, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
_, err := clusterutil.PrepareClusterScale(cluster, oldCluster)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, cluster.Spec.Machines, err.Error()))
}
return allErrs
}

// ValidateCluster validates a given ClusterSpec.
func ValidatClusterSpec(spec *platform.ClusterSpec, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
Expand Down
7 changes: 7 additions & 0 deletions api/platform/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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/coreos/prometheus-operator v0.38.1-0.20200506070354-4231c1d4b313
github.com/cyphar/filepath-securejoin v0.2.2
github.com/deckarep/golang-set v1.7.1
github.com/dexidp/dex v0.0.0-20200408064242-83d8853fd969
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.2-0.20200708230840-70e0022e42fd+incompatible
Expand All @@ -35,6 +36,7 @@ require (
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.3.5 // indirect
github.com/google/gofuzz v1.1.0
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de
github.com/gorilla/mux v1.7.3
github.com/gorilla/websocket v1.4.0
github.com/gosuri/uitable v0.0.4
Expand Down Expand Up @@ -73,6 +75,7 @@ require (
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/grpc v1.26.0
gopkg.in/fatih/set.v0 v0.2.1
gopkg.in/go-playground/validator.v9 v9.29.1
gopkg.in/ldap.v2 v2.5.1
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v0.0.0-20160507010035-511bcaf42ccd/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g=
github.com/deislabs/oras v0.8.0 h1:WZqPI25DlEmth2VE/pIcnEh6msL2yHrzS5lV5gwaCsQ=
github.com/deislabs/oras v0.8.0/go.mod h1:v1Vmv0oHch7HS/gK7CGIdIp7s5lEiLlKvwMxZ34sQDs=
Expand Down Expand Up @@ -1354,6 +1356,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fatih/set.v0 v0.2.1 h1:Xvyyp7LXu34P0ROhCyfXkmQCAoOUKb1E2JS9I7SE5CY=
gopkg.in/fatih/set.v0 v0.2.1/go.mod h1:5eLWEndGL4zGGemXWrKuts+wTJR0y+w+auqUJZbmyBg=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/fsnotify/fsnotify.v1 v1.4.7/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE=
Expand Down Expand Up @@ -1429,6 +1433,7 @@ k8s.io/apimachinery v0.0.0-20191121175448-79c2a76c473a/go.mod h1:b9qmWdKlLuU9EBh
k8s.io/apimachinery v0.18.0/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.18.2 h1:44CmtbmkzVDAhCpRVSiP2R5PPrC2RtlIv/MoB8xpdRA=
k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA=
k8s.io/apimachinery v0.19.3 h1:bpIQXlKjB4cB/oNpnNnV+BybGPR7iP5oYpsOTEJ4hgc=
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad/go.mod h1:XPCXEwhjaFN29a8NldXA901ElnKeKLrLtREO9ZhFyhg=
k8s.io/apiserver v0.0.0-20191122221311-9d521947b1e1/go.mod h1:RbsZY5zzBIWnz4KbctZsTVjwIuOpTp4Z8oCgFHN4kZQ=
k8s.io/apiserver v0.18.0/go.mod h1:3S2O6FeBBd6XTo0njUrLxiqk8GNy6wWOftjhJcXYnjw=
Expand Down
10 changes: 9 additions & 1 deletion pkg/platform/controller/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func (c *Controller) needsUpdate(old *platformv1.Cluster, new *platformv1.Cluste
if !reflect.DeepEqual(old.Spec, new.Spec) {
return true
}
if !reflect.DeepEqual(old.ResourceVersion, new.ResourceVersion) {
return true
}

if old.Status.Phase == platformv1.ClusterRunning && new.Status.Phase == platformv1.ClusterTerminating {
return true
Expand Down Expand Up @@ -227,6 +230,7 @@ func (c *Controller) processNextWorkItem() bool {
// concurrently with the same key.
func (c *Controller) syncCluster(key string) error {
ctx := c.log.WithValues("cluster", key).WithContext(context.TODO())

startTime := time.Now()
defer func() {
log.FromContext(ctx).Info("Finished syncing cluster", "processTime", time.Since(startTime).String())
Expand Down Expand Up @@ -261,6 +265,10 @@ func (c *Controller) reconcile(ctx context.Context, key string, cluster *platfor
err = c.onCreate(ctx, cluster)
case platformv1.ClusterRunning, platformv1.ClusterFailed, platformv1.ClusterUpgrading:
err = c.onUpdate(ctx, cluster)
case platformv1.ClusterUpscaling:
err = c.onUpdate(ctx, cluster)
case platformv1.ClusterDownscaling:
err = c.onUpdate(ctx, cluster)
case platformv1.ClusterTerminating:
log.FromContext(ctx).Info("Cluster has been terminated. Attempting to cleanup resources")
err = c.deleter.Delete(ctx, key)
Expand Down Expand Up @@ -448,7 +456,7 @@ func (c *Controller) checkHealth(ctx context.Context, cluster *typesv1.Cluster)
}
}

cluster.SetCondition(healthCheckCondition)
cluster.SetCondition(healthCheckCondition, false)

log.FromContext(ctx).Info("Update cluster health status",
"version", cluster.Status.Version,
Expand Down
Loading