Skip to content

Commit

Permalink
feat: enhanced in-place update module to support vertical scaling
Browse files Browse the repository at this point in the history
Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>
  • Loading branch information
LavenderQAQ committed Aug 7, 2023
1 parent 915b0ab commit 04b5eb8
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 33 deletions.
3 changes: 3 additions & 0 deletions apis/apps/pub/inplace_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type InPlaceUpdateState struct {
// NextContainerRefMetadata is the containers with lower priority that waiting for in-place update labels/annotations in next batch.
NextContainerRefMetadata map[string]metav1.ObjectMeta `json:"nextContainerRefMetadata,omitempty"`

// NextContainerResources is the containers with lower priority that waiting for in-place update resources in next batch.
NextContainerResources map[string]v1.ResourceRequirements `json:"nextContainerResources,omitempty"`

// PreCheckBeforeNext is the pre-check that must pass before the next containers can be in-place update.
PreCheckBeforeNext *InPlaceUpdatePreCheckBeforeNext `json:"preCheckBeforeNext,omitempty"`

Expand Down
8 changes: 8 additions & 0 deletions apis/apps/pub/zz_generated.deepcopy.go

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

14 changes: 7 additions & 7 deletions pkg/client/clientset/versioned/fake/register.go

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

14 changes: 7 additions & 7 deletions pkg/client/clientset/versioned/scheme/register.go

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

5 changes: 5 additions & 0 deletions pkg/features/kruise_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const (
// PreparingUpdateAsUpdate enable CloneSet/Advanced StatefulSet controller to regard preparing-update Pod
// as updated when calculating update/current revision during scaling.
PreparingUpdateAsUpdate featuregate.Feature = "PreparingUpdateAsUpdate"

// InPlaceWorkloadVerticalScaling enable CloneSet/Advanced StatefulSet controller to support vertical scaling
// of managed Pods.
InPlaceWorkloadVerticalScaling featuregate.Feature = "InPlaceWorkloadVerticalScaling"
)

var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
Expand All @@ -129,6 +133,7 @@ var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
PreDownloadImageForDaemonSetUpdate: {Default: false, PreRelease: featuregate.Alpha},
CloneSetEventHandlerOptimization: {Default: false, PreRelease: featuregate.Alpha},
PreparingUpdateAsUpdate: {Default: false, PreRelease: featuregate.Alpha},
InPlaceWorkloadVerticalScaling: {Default: false, PreRelease: featuregate.Alpha},
}

func init() {
Expand Down
19 changes: 11 additions & 8 deletions pkg/util/inplaceupdate/inplace_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import (
)

var (
containerImagePatchRexp = regexp.MustCompile("^/spec/containers/([0-9]+)/image$")
rfc6901Decoder = strings.NewReplacer("~1", "/", "~0", "~")
containerImagePatchRexp = regexp.MustCompile("^/spec/containers/([0-9]+)/image$")
containerResourcesPatchRexp = regexp.MustCompile("^/spec/containers/([0-9]+)/resources/.*$")
rfc6901Decoder = strings.NewReplacer("~1", "/", "~0", "~")

Clock clock.Clock = clock.RealClock{}
)
Expand Down Expand Up @@ -79,11 +80,12 @@ type Interface interface {
type UpdateSpec struct {
Revision string `json:"revision"`

ContainerImages map[string]string `json:"containerImages,omitempty"`
ContainerRefMetadata map[string]metav1.ObjectMeta `json:"containerRefMetadata,omitempty"`
MetaDataPatch []byte `json:"metaDataPatch,omitempty"`
UpdateEnvFromMetadata bool `json:"updateEnvFromMetadata,omitempty"`
GraceSeconds int32 `json:"graceSeconds,omitempty"`
ContainerImages map[string]string `json:"containerImages,omitempty"`
ContainerRefMetadata map[string]metav1.ObjectMeta `json:"containerRefMetadata,omitempty"`
ContainerResources map[string]v1.ResourceRequirements `json:"containerResources,omitempty"`
MetaDataPatch []byte `json:"metaDataPatch,omitempty"`
UpdateEnvFromMetadata bool `json:"updateEnvFromMetadata,omitempty"`
GraceSeconds int32 `json:"graceSeconds,omitempty"`

OldTemplate *v1.PodTemplateSpec `json:"oldTemplate,omitempty"`
NewTemplate *v1.PodTemplateSpec `json:"newTemplate,omitempty"`
Expand Down Expand Up @@ -131,7 +133,7 @@ func (c *realControl) Refresh(pod *v1.Pod, opts *UpdateOptions) RefreshResult {
}

// check if there are containers with lower-priority that have to in-place update in next batch
if len(state.NextContainerImages) > 0 || len(state.NextContainerRefMetadata) > 0 {
if len(state.NextContainerImages) > 0 || len(state.NextContainerRefMetadata) > 0 || len(state.NextContainerResources) > 0 {

// pre-check the previous updated containers
if checkErr := doPreCheckBeforeNext(pod, state.PreCheckBeforeNext); checkErr != nil {
Expand Down Expand Up @@ -254,6 +256,7 @@ func (c *realControl) updateNextBatch(pod *v1.Pod, opts *UpdateOptions) (bool, e
ContainerImages: state.NextContainerImages,
ContainerRefMetadata: state.NextContainerRefMetadata,
UpdateEnvFromMetadata: state.UpdateEnvFromMetadata,
ContainerResources: state.NextContainerResources,
}
if clone, err = opts.PatchSpecToPod(clone, &spec, &state); err != nil {
return err
Expand Down
Loading

0 comments on commit 04b5eb8

Please sign in to comment.