Skip to content

Commit

Permalink
feat: remove offstream when vertical update only
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 22, 2023
1 parent ff3e27e commit cf9de87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/util/inplaceupdate/inplace_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type UpdateSpec struct {
MetaDataPatch []byte `json:"metaDataPatch,omitempty"`
UpdateEnvFromMetadata bool `json:"updateEnvFromMetadata,omitempty"`
GraceSeconds int32 `json:"graceSeconds,omitempty"`
VerticalUpdateOnly bool `json:"verticalUpdate,omitempty"`

OldTemplate *v1.PodTemplateSpec `json:"oldTemplate,omitempty"`
NewTemplate *v1.PodTemplateSpec `json:"newTemplate,omitempty"`
Expand Down Expand Up @@ -286,7 +287,8 @@ func (c *realControl) Update(pod *v1.Pod, oldRevision, newRevision *apps.Control
// TODO(FillZpp): maybe we should check if the previous in-place update has completed

// 2. update condition for pod with readiness-gate
if containsReadinessGate(pod) {
// When only workload resources are updated, they are marked as not needing to remove traffic
if !spec.VerticalUpdateOnly && containsReadinessGate(pod) {
newCondition := v1.PodCondition{
Type: appspub.InPlaceUpdateReady,
LastTransitionTime: metav1.NewTime(Clock.Now()),
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/inplaceupdate/inplace_update_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ func defaultCalculateInPlaceUpdateSpec(oldRevision, newRevision *apps.Controller
updateSpec := &UpdateSpec{
Revision: newRevision.Name,
ContainerImages: make(map[string]string),
ContainerResources: make(map[string]v1.ResourceRequirements),
ContainerRefMetadata: make(map[string]metav1.ObjectMeta),
GraceSeconds: opts.GracePeriodSeconds,
VerticalUpdateOnly: false,
}
if opts.GetRevision != nil {
updateSpec.Revision = opts.GetRevision(newRevision)
Expand Down Expand Up @@ -665,6 +667,7 @@ func defaultCalculateInPlaceUpdateSpecWithVerticalUpdate(oldRevision, newRevisio
ContainerRefMetadata: make(map[string]metav1.ObjectMeta),
ContainerResources: make(map[string]v1.ResourceRequirements),
GraceSeconds: opts.GracePeriodSeconds,
VerticalUpdateOnly: false,
}
if opts.GetRevision != nil {
updateSpec.Revision = opts.GetRevision(newRevision)
Expand Down Expand Up @@ -731,6 +734,11 @@ func defaultCalculateInPlaceUpdateSpecWithVerticalUpdate(oldRevision, newRevisio
}
}

// Need to distinguish whether only resources have been updated
if len(updateSpec.ContainerResources) > 0 && len(updateSpec.ContainerImages) == 0 {
updateSpec.VerticalUpdateOnly = true
}

if len(metadataPatches) > 0 {
if utilfeature.DefaultFeatureGate.Enabled(features.InPlaceUpdateEnvFromMetadata) {
// for example: /metadata/labels/my-label-key
Expand Down

0 comments on commit cf9de87

Please sign in to comment.