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

Keep the number of ReplicaSets to a minimum #15640

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions config/core/configmaps/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data:
# This is the Go import path for the binary that is containerized
# and substituted here.
queue-sidecar-image: ko://knative.dev/serving/cmd/queue
revisionHistoryLimit: "2"
_example: |-
################################
# #
Expand Down
15 changes: 15 additions & 0 deletions pkg/deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package deployment
import (
"errors"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -241,6 +242,17 @@ func NewConfigFromMap(configMap map[string]string) (*Config, error) {
}
}
}

if val, ok := configMap["revisionHistoryLimit"]; ok {
limit, err := strconv.Atoi(val)
if err != nil {
return nil, fmt.Errorf("invalid revisionHistoryLimit value %s: %w", val, err)
}
nc.RevisionHistoryLimit = int32(limit)
} else {
nc.RevisionHistoryLimit = 2 // Default value if not set
}

return nc, nil
}

Expand Down Expand Up @@ -309,4 +321,7 @@ type Config struct {

// RuntimeClassNames specifies which runtime the Pod will use
RuntimeClassNames map[string]RuntimeClassNameLabelSelector

// RevisionHistoryLimit is the maximum number of old replicas to retain.
RevisionHistoryLimit int32
}
7 changes: 7 additions & 0 deletions pkg/reconciler/revision/resources/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ func MakeDeployment(rev *v1.Revision, cfg *config.Config) (*appsv1.Deployment, e
labels := makeLabels(rev)
anns := makeAnnotations(rev)

// Set revisionHistoryLimit from config-deployment.yaml or use default
revisionHistoryLimit := int32(cfg.Deployment.RevisionHistoryLimit) // e.g., 2 or 0
if revisionHistoryLimit == 0 {
revisionHistoryLimit = 2 // Default to 2 if not configured as 0
}

// Slowly but steadily roll the deployment out, to have the least possible impact.
maxUnavailable := intstr.FromInt(0)
return &appsv1.Deployment{
Expand All @@ -390,6 +396,7 @@ func MakeDeployment(rev *v1.Revision, cfg *config.Config) (*appsv1.Deployment, e
Replicas: ptr.Int32(replicaCount),
Selector: makeSelector(rev),
ProgressDeadlineSeconds: ptr.Int32(progressDeadline),
RevisionHistoryLimit: ptr.Int32(revisionHistoryLimit),
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
Expand Down