这是indexloc提供的服务,不要输入任何密码
Skip to content

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

Merged
merged 9 commits into from
Sep 21, 2020

Conversation

taragu
Copy link
Contributor

@taragu taragu commented Sep 16, 2020

Moving autoscaling config constants into pkg/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 (see ValidateAnnotations(...)). 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 into ValidateAnnotations() 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

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 16, 2020
@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/API API objects and controllers labels Sep 16, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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 (see ValidateAnnotations(...)). 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 into ValidateAnnotations() 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.

@knative-prow-robot knative-prow-robot added area/autoscale area/test-and-release It flags unit/e2e/conformance/perf test issues for product features labels Sep 16, 2020
Copy link
Member

@mattmoor mattmoor left a 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)

@taragu taragu force-pushed the max-maxscale-move-asconsts branch 5 times, most recently from 9c6ab81 to e964caa Compare September 16, 2020 15:52
@taragu
Copy link
Contributor Author

taragu commented Sep 16, 2020

(The failed github action should be unrelated, but I don't have write access to the repo and can't rerun it.)

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"
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Member

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

@vagababov
Copy link
Contributor

😠
Everywhere else we have group in register.go.
Shrug. I am fine.
/assign mattmoor
Maybe Matt has more ideas.

Copy link
Contributor

@yanweiguo yanweiguo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 16, 2020
@vagababov
Copy link
Contributor

/lgtm

@vagababov
Copy link
Contributor

Duplication works too. ;)

@julz
Copy link
Member

julz commented Sep 17, 2020

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 // +k8s:deepcopy-gen=false incantations to the file and to doc.go?

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 17, 2020
@taragu taragu changed the title Move autoscaling config constants into pkg/autoscaler/config Move autoscaling config struct into new package Sep 18, 2020
@vagababov
Copy link
Contributor

I probably missed something, but why "config/autoscalerconfig"?
Why not just put everything under config. It's basically empty now.

@taragu
Copy link
Contributor Author

taragu commented Sep 18, 2020

@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.

@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-integration-tests 0/3

Failed non-flaky tests preventing automatic retry of pull-knative-serving-integration-tests:

test/scale.TestScaleToN/scale-200
test/scale.TestScaleToN

@taragu
Copy link
Contributor Author

taragu commented Sep 18, 2020

/retest

@taragu
Copy link
Contributor Author

taragu commented Sep 21, 2020

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"
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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 ?

Copy link
Member

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 🤷

Copy link
Member

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
Copy link

codecov bot commented Sep 21, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@9ceb85e). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ceb85e...bfcbb1b. Read the comment docs.

Copy link
Member

@julz julz left a 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestGlobalResyncOnUpdateasconfigMap(t *testing.T) {
func TestGlobalResyncOnUpdateAutoscalerConfigMap(t *testing.T) {

autoscalerConfig.InitialScale = 0
autoscalerConfig.EnableScaleToZero = true
return autoscalerConfig
asconfig, _ := asconfig.NewConfigFromMap(defaultConfigMapData())
Copy link
Member

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

Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 21, 2020
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 21, 2020
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/autoscaling/kpa/scaler.go 93.4% 94.3% 0.8

Copy link
Contributor

@vagababov vagababov left a 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

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 21, 2020
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 21, 2020
@knative-prow-robot knative-prow-robot merged commit 5b761f3 into knative:master Sep 21, 2020
@julz julz mentioned this pull request Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers area/autoscale area/test-and-release It flags unit/e2e/conformance/perf test issues for product features cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants