Skip to content

Commit

Permalink
Keep the number of ReplicaSets to a minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
subha-91 committed Nov 29, 2024
1 parent 5717d19 commit 5048628
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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

0 comments on commit 5048628

Please sign in to comment.