-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Move autoscaling config struct into new package #9434
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
Move autoscaling config struct into new package #9434
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: 0 warnings.
In response to this:
Moving autoscaling config constants into
pkg/autoscaler/config
.This is needed because currently in order to pass the autoscaler configmap into
pkg/apis/autoscaling/annotation_validation.go
, we can only pass in individual values in the configmap (seeValidateAnnotations(...)
). The reason we cannot pass in the configmap directly is because there will be a cyclic dependency. This can get ugly as we would need to pass in another variable MaxScaleLimit intoValidateAnnotations()
for issue #8628.This PR fixes such cyclic dependency so we don't have to do so, and can pass the entire autoscaler configmap into
ValidateAnnotations()
./lint
Part of #8628
/assign @vagababov @markusthoemmes @julz @yanweiguo
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.
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.
Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)
9c6ab81
to
e964caa
Compare
(The failed github action should be unrelated, but I don't have write access to the repo and can't rerun it.) |
pkg/apis/autoscaling/register.go
Outdated
const ( | ||
domain = ".knative.dev" | ||
|
||
// InternalGroupName is the internal autoscaling group name. This is used for CRDs. | ||
InternalGroupName = "autoscaling.internal.knative.dev" | ||
|
||
// GroupName is the the public autoscaling group name. This is used for annotations, labels, etc. | ||
GroupName = "autoscaling.knative.dev" |
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.
We should be keeping GroupName here, I think.
Rest, I guess we can move.
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 don't think we can keep the GroupName here, because it's used by the other annotation keys, so we will have to import knative.dev/serving/pkg/apis/autoscaling
into pkg/autoscaler/config/config.go
and the cyclic dependency issue won't be solved.
import cycle not allowed
package knative.dev/serving/cmd/activator
imports knative.dev/serving/pkg/activator/handler
imports knative.dev/serving/pkg/activator/util
imports knative.dev/serving/pkg/apis/serving/v1
imports knative.dev/serving/pkg/apis/autoscaling
imports knative.dev/serving/pkg/autoscaler/config
imports knative.dev/serving/pkg/apis/autoscaling
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.
would it be the end of the world if we just duplicated GroupName in both places?
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.
keep in mind it's 2020, the world's probably ending 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.
/lgtm
/lgtm |
Duplication works too. ;) |
hmm @taragu surely the DeepCopy is a public method on the struct so is (must be?) in whatever package the struct is in? Any chance you just need to add the right |
I probably missed something, but why "config/autoscalerconfig"? |
This reverts commit babe472.
@vagababov actually I moved too much in the last commit, and we are back to the cyclic dependency issue. Looks like we can only move the Config struct. |
The following jobs failed:
Failed non-flaky tests preventing automatic retry of pull-knative-serving-integration-tests:
|
/retest |
This is ready for another look. |
@@ -26,7 +26,7 @@ import ( | |||
|
|||
"knative.dev/pkg/apis" | |||
"knative.dev/serving/pkg/apis/autoscaling" | |||
autoscalerconfig "knative.dev/serving/pkg/autoscaler/config" | |||
"knative.dev/serving/pkg/autoscaler/config/sharedconfig" |
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 may well be a terrible idea, but what if we called this package autoscalerconfig
? Then we'd maybe only have to change the imports - since we're always importing autoscaler/config
as this anyway - and the diff would be much smaller (also it seems like maybe a better name for this anyway). Unless there's a place we import both autoscaler/config/sharedconfig
and autoscaler/config
, but I don't think there can be because it'd be circular then 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.
There are a few places that we need to import both, such as test/e2e/e2e.go
. It's mostly ConfigName
and NewConfigFromMap(...)
that we are importing from autoscaler/config
. I tried to move them to sharedconfig
but then we were going back to the circular dependency we had to begin with.
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.
can't you just import them with different names in those couple places? I guess at that point it becomes a bit icky 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. So instead of autoscalerconfig "knative.dev/serving/pkg/autoscaler/config"
we call it asconfig "knative.dev/serving/pkg/autoscaler/config"
, and rename autoscaler/config/sharedconfig
to autoscaler/config/autoscalerconfig
?
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.
yeah, dont honestly know if that's better or worse if we end up having to import both asconfig
and autoscalerconfig
in the same file tho. Not that autoscalerconfig
+ sharedconfig
is a ton better so 🤷
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.
certainly makes the diff look nicer this way 🤷♂️👍️.
Codecov Report
@@ Coverage Diff @@
## master #9434 +/- ##
=========================================
Coverage ? 88.57%
=========================================
Files ? 209
Lines ? 9378
Branches ? 0
=========================================
Hits ? 8307
Misses ? 817
Partials ? 254 Continue to review full report at Codecov.
|
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.
Package names still make me sad, but I don't have a better solution and this looks pretty good 🤷. Looks good to me apart from couple nits
@@ -1229,7 +1230,7 @@ func deploy(namespace, name string, opts ...deploymentOption) *appsv1.Deployment | |||
return s | |||
} | |||
|
|||
func TestGlobalResyncOnUpdateAutoscalerConfigMap(t *testing.T) { | |||
func TestGlobalResyncOnUpdateasconfigMap(t *testing.T) { |
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.
func TestGlobalResyncOnUpdateasconfigMap(t *testing.T) { | |
func TestGlobalResyncOnUpdateAutoscalerConfigMap(t *testing.T) { |
autoscalerConfig.InitialScale = 0 | ||
autoscalerConfig.EnableScaleToZero = true | ||
return autoscalerConfig | ||
asconfig, _ := asconfig.NewConfigFromMap(defaultConfigMapData()) |
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.
maybe worth avoiding shadowing the package name with the local variable here
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
The following is the coverage report on the affected files.
|
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 really don't like the stutter in the package naming, but it's ok for now.
when I think of a good name, I'll rename it 😄
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: taragu, vagababov 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 |
Moving autoscaling config constants intopkg/autoscaler/config
.Move autoscaling config struct into new package
This is needed because currently in order to pass the autoscaler configmap into
pkg/apis/autoscaling/annotation_validation.go
, we can only pass in individual values in the configmap (seeValidateAnnotations(...)
). The reason we cannot pass in the configmap directly is because there will be a cyclic dependency. This can get ugly as we would need to pass in another variable MaxScaleLimit intoValidateAnnotations()
for issue #8628.This PR fixes such cyclic dependency so we don't have to do so, and can pass the entire autoscaler configmap into
ValidateAnnotations()
./lint
Part of #8628
/assign @vagababov @markusthoemmes @julz @yanweiguo