-
Notifications
You must be signed in to change notification settings - Fork 41k
Prevent running two HPA cachers for different API versions #132924
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
Conversation
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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-sigs/prow repository. |
/cc @deads2k |
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
LGTM label has been added. Git tree hash: f2421c7febc6ee4a403d8957149ab3f589a9f8cd
|
/assign @smarterclayton |
/cc @liggitt |
I don't think this is a regression, this has always been this way, right? |
Right, it dates to introduction of v2 horizontalpodautoscalers API in K8s 1.6. /kind feature |
if storageMap, err := p.v2Storage(apiResourceConfigSource, restOptionsGetter); err != nil { | ||
return genericapiserver.APIGroupInfo{}, err | ||
} else if len(storageMap) > 0 { | ||
apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv2.SchemeGroupVersion.Version] = storageMap | ||
} | ||
|
||
if storageMap, err := p.v1Storage(apiResourceConfigSource, restOptionsGetter); err != nil { | ||
return genericapiserver.APIGroupInfo{}, err | ||
} else if len(storageMap) > 0 { | ||
apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv1.SchemeGroupVersion.Version] = storageMap | ||
} |
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 really want the API group/version setup to be isolated / independent... combining these two into a single function makes it easier to accidentally reuse shared variables incorrectly. If the thing we want to accomplish is only constructing HPA storage once, let's structure the code to accomplish that without losing isolated version setup:
var (
hpaOnce sync.Once
hpaStorage *REST
hpaStatusStorage *StatusREST
hpaStorageErr error
)
hpaStorageGetter := func() (*REST, *StatusREST, error) {
hpaOnce.Do(func(){
hpaStorage, hpaStatusStorage, hpaStorageErr := horizontalpodautoscalerstore.NewREST(restOptionsGetter)
})
return hpaStorage, hpaStatusStorage, hpaStorageErr
}
if storageMap, err := p.v2Storage(apiResourceConfigSource, hpaStorageGetter); err != nil {
return genericapiserver.APIGroupInfo{}, err
} else if len(storageMap) > 0 {
apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv2.SchemeGroupVersion.Version] = storageMap
}
if storageMap, err := p.v1Storage(apiResourceConfigSource, hpaStorageGetter); err != nil {
return genericapiserver.APIGroupInfo{}, err
} else if len(storageMap) > 0 {
apiGroupInfo.VersionedResourcesStorageMap[autoscalingapiv1.SchemeGroupVersion.Version] = storageMap
}
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.
the existing code is also ~identical to the versioned setup code used for ~every other API group currently ... this isn't an issue isolated to HPA, it just happens to only manifest with default config for HPA because it's the only thing that has two GA API versions of the same group
it would be ideal to fix this systemically and consistently so we don't have the same issue everywhere
edit: actually, I think events has the same issue in default configs, constructing twice to serve via events/v1 and core/v1
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.
Makes sense, I didn't notice the events as it doesn't have watch cache enabled. I noticed that we create 2 cachers for serviceaccounts
but we shutdown one of 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.
Done
e778049
to
e60a4d5
Compare
var hpaStorage *horizontalpodautoscalerstore.REST | ||
var hpaStatusStorage *horizontalpodautoscalerstore.StatusREST | ||
var hpaStorageErr error |
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.
Making these local means that on subsequent invocations, this function will return nil, nil, nil
. These variables have to live outside the closure.
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.
Right
@@ -50,12 +63,12 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag | |||
return apiGroupInfo, nil | |||
} | |||
|
|||
func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) { | |||
func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter hpaStorageGetter) (map[string]rest.Storage, error) { |
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 (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter hpaStorageGetter) (map[string]rest.Storage, error) { | |
func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, storageGetter hpaStorageGetter) (map[string]rest.Storage, error) { |
e60a4d5
to
20914ef
Compare
/lgtm |
LGTM label has been added. Git tree hash: 42dee923e5c40eeeee1d8c312c0dd493baa9837a
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jpbetz, liggitt, serathius 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 |
/sig autoscaling api-machinery |
/kind regression
Reuse single REST for different HPA versions, reducing resource usage.
Allocating REST is not free as if watch cache is enabled, each will LIST and WATCH etcd independently and cache all objects in memory.
/assign @jpbetz