Skip to content

Commit

Permalink
The rest of the review
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Gu committed Jun 18, 2020
1 parent 535e97f commit 4e28d00
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 53 deletions.
13 changes: 4 additions & 9 deletions pkg/reconciler/revision/resources/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,11 @@ func MakeDeployment(rev *v1.Revision,
return nil, fmt.Errorf("failed to create PodSpec: %w", err)
}

replicaCount := autoscalerConfig.InitialScale
replicaCount := int(autoscalerConfig.InitialScale)
ann, found := rev.ObjectMeta.Annotations[autoscaling.InitialScaleAnnotationKey]
if found {
initialScale, err := strconv.Atoi(ann)
if err != nil {
return nil, fmt.Errorf("failed to process initialScale annotation: %w", err)
}
if initialScale != 0 || autoscalerConfig.AllowZeroInitialScale {
replicaCount = int32(initialScale)
}
// Ignore errors and no error checking because already validated in webhook.
replicaCount, _ = strconv.Atoi(ann)
}

return &appsv1.Deployment{
Expand All @@ -256,7 +251,7 @@ func MakeDeployment(rev *v1.Revision,
OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(rev)},
},
Spec: appsv1.DeploymentSpec{
Replicas: ptr.Int32(replicaCount),
Replicas: ptr.Int32(int32(replicaCount)),
Selector: makeSelector(rev),
ProgressDeadlineSeconds: ptr.Int32(int32(deploymentConfig.ProgressDeadline.Seconds())),
Template: corev1.PodTemplateSpec{
Expand Down
44 changes: 0 additions & 44 deletions pkg/reconciler/revision/resources/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,50 +1063,6 @@ func TestMakeDeployment(t *testing.T) {
deploy.Spec.Template.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "20"}
deploy.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "20"}
}),
}, {
name: "cluster initial scale does not allow initial scale zero",
acMutator: func(ac *asconfig.Config) {
ac.InitialScale = 2
ac.AllowZeroInitialScale = false
},
rev: revision("bar", "foo",
withoutLabels,
withContainers([]corev1.Container{{
Name: servingContainerName,
Image: "ubuntu",
ReadinessProbe: withTCPReadinessProbe(12345),
}}),
func(revision *v1.Revision) {
revision.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "0"}
},
),
want: appsv1deployment(func(deploy *appsv1.Deployment) {
deploy.Spec.Replicas = ptr.Int32(int32(2))
deploy.Spec.Template.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "0"}
deploy.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "0"}
}),
}, {
name: "cluster initial scale allows initial scale zero",
acMutator: func(ac *asconfig.Config) {
ac.InitialScale = 2
ac.AllowZeroInitialScale = true
},
rev: revision("bar", "foo",
withoutLabels,
withContainers([]corev1.Container{{
Name: servingContainerName,
Image: "ubuntu",
ReadinessProbe: withTCPReadinessProbe(12345),
}}),
func(revision *v1.Revision) {
revision.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "0"}
},
),
want: appsv1deployment(func(deploy *appsv1.Deployment) {
deploy.Spec.Replicas = ptr.Int32(int32(0))
deploy.Spec.Template.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "0"}
deploy.ObjectMeta.Annotations = map[string]string{autoscaling.InitialScaleAnnotationKey: "0"}
}),
}}

for _, test := range tests {
Expand Down

0 comments on commit 4e28d00

Please sign in to comment.