-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add service initial scale annotation and validation #7678
Add service initial scale annotation and validation #7678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taragu: 2 warnings.
In response to this:
Add new autoscaling annotation initialScale and validation.
/lint
/hold
for Part 1Part 2 of #4098
Release Note
NONE
/assign @dprotaso @markusthoemmes @vagababov
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
fae5677
to
2cb3a98
Compare
/hold cancel |
if len(anns) == 0 { | ||
return nil | ||
} | ||
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns))) | ||
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns).Also(validateInitialScale(allowInitScaleZero, anns)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please break this line.
@@ -37,11 +37,12 @@ func getIntGE0(m map[string]string, k string) (int64, *apis.FieldError) { | |||
return i, nil | |||
} | |||
|
|||
func ValidateAnnotations(anns map[string]string) *apis.FieldError { | |||
// ValidateAnnotations verifies the autoscaling annotations. | |||
func ValidateAnnotations(allowInitScaleZero bool, anns map[string]string) *apis.FieldError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the context get passed in here? With more switches, we'd otherwise grow the signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markusthoemmes there's a cyclic package import problem if we do so because we have to import knative.dev/serving/pkg/apis/config
in knative.dev/serving/pkg/apis/autoscaling
to get the configmap.
can't load package: import cycle not allowed
package knative.dev/serving/pkg/apis/autoscaling
imports knative.dev/serving/pkg/apis/config
imports knative.dev/serving/pkg/autoscaler/config
imports knative.dev/serving/pkg/apis/autoscaling
Is there any workaround for this problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, probably not an easy one 🤔. Maybe it's fine for now 🤷♂️
pkg/apis/autoscaling/register.go
Outdated
// InitialScaleAnnotationKey is the annotation to specify the initial scale of | ||
// a revision when a service is initially deployed. This number can be set to 0 iff | ||
// allow-zero-initial-scale of config-autoscaler is true. | ||
InitialScaleAnnotationKey = GroupName + "/initialScale" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Put this next to min and maxscale.
allowZeroInitialScale := false | ||
if config.FromContext(ctx) != nil { | ||
autoscalerConfig := config.FromContext(ctx).Autoscaler | ||
if autoscalerConfig != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this ever be nil? Just for tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is just for the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably annotate tests instead? If we have cruft, I'd rather have it in tests than in production code.
@@ -160,11 +162,40 @@ func TestValidateObjectMetadata(t *testing.T) { | |||
}, | |||
}, | |||
expectErr: (*apis.FieldError)(nil), | |||
}, { | |||
name: "cluster allows zero revision initial scale", | |||
ctx: config.ToContext(context.Background(), asCfg(map[string]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not manually construct the config here?
allowZeroInitialScale := false | ||
if apisconfig.FromContext(ctx) != nil { | ||
autoscalerConfig := apisconfig.FromContext(ctx).Autoscaler | ||
if autoscalerConfig != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: When would this ever be nil? Same for the config in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the tests. Would it be better if we make sure all of the test contexts has the config instead of making this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, yeah. This feels a little weird to reason about in production code.
@@ -57,8 +58,15 @@ func (r *Revision) Validate(ctx context.Context) *apis.FieldError { | |||
|
|||
// Validate ensures RevisionTemplateSpec is properly configured. | |||
func (rt *RevisionTemplateSpec) Validate(ctx context.Context) *apis.FieldError { | |||
allowZeroInitialScale := false | |||
if apisconfig.FromContext(ctx) != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
allowZeroInitialScale := false | ||
if config.FromContext(ctx) != nil { | ||
autoscalerConfig := config.FromContext(ctx).Autoscaler | ||
if autoscalerConfig != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably annotate tests instead? If we have cruft, I'd rather have it in tests than in production code.
@vagababov @markusthoemmes this is ready for another look |
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns). | ||
Also(validateInitialScale(allowInitScaleZero, anns)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns). | |
Also(validateInitialScale(allowInitScaleZero, anns)))) | |
return validateMinMaxScale(anns).Also(validateFloats(anns)) | |
.Also(validateWindows(anns).Also(validateMetric(anns) | |
.Also(validateInitialScale(allowInitScaleZero, anns)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make it three lines, but I'm getting compiler errors if I put the dot at the beginning of the new line
expectErr: (&apis.FieldError{Message: "", Paths: []string(nil), Details: ""}).Also( | ||
(&apis.FieldError{Message: "", Paths: []string(nil), Details: ""}).Also( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have those empty errors? We should be able to delete them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a result of the chained .Also
s
return validateMinMaxScale(anns).Also(validateFloats(anns)).Also(validateWindows(anns).Also(validateMetric(anns). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just removed the empty errors here: #7752
They are completely redundant and unnecessary. FieldError code removes them anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah i see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see the empty errors. Did you push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♀️ I missed those. they are updated now
37bfa31
to
1596cc9
Compare
allowZeroInitialScale := false | ||
autoscalerConfig := apisconfig.FromContextOrDefaults(ctx).Autoscaler | ||
allowZeroInitialScale = autoscalerConfig.AllowZeroInitialScale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allowZeroInitialScale := false | |
autoscalerConfig := apisconfig.FromContextOrDefaults(ctx).Autoscaler | |
allowZeroInitialScale = autoscalerConfig.AllowZeroInitialScale | |
allowZeroInitialScale = apisconfig.FromContextOrDefaults(ctx).Autoscaler.AllowZeroInitialScale |
For all other occasions too.
@@ -147,11 +150,62 @@ func TestValidateObjectMetadata(t *testing.T) { | |||
"testAnnotation": "testValue", | |||
}, | |||
}, | |||
}, { | |||
name: "revision initial scale not parseable", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't all the negative test live close to the implementation, i.e. in the autoscaling validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Should we remove these negative test cases here then?
@markusthoemmes @vagababov would you please take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly fine by me.
There seem some unresolved comments with Markus, so I'll let him approve.
/lgtm
|
||
func autoscalerConfigCtx(allowInitialScaleZero bool, initialScale int) context.Context { | ||
testConfigs := &config.Config{} | ||
testConfigs.Autoscaler, _ = autoscalerconfig.NewConfigFromMap(map[string]string{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just populate the map?
The following is the coverage report on the affected files.
|
The following jobs failed:
Automatically retrying due to test flakiness... |
/lgtm |
/lgtm cancel This should setup Markus to lgtm it and it should merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, markusthoemmes, taragu The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Add new autoscaling annotation initialScale and validation.
/lint
/hold
for Part 1
Part 2 of #7682
Release Note
/assign @dprotaso @markusthoemmes @vagababov