-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed6ebbe
commit 28376c7
Showing
18 changed files
with
464 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package loopstart | ||
|
||
import "errors" | ||
|
||
// Observer interface is used to store object that needed to be refreshed in each CA loop. | ||
// It returns error and a bool value whether the loop should be skipped. | ||
type Observer interface { | ||
Refresh() (bool, error) | ||
} | ||
|
||
// ObserversList interface is used to store objects that needed to be refreshed in each CA loop. | ||
type ObserversList struct { | ||
observers []Observer | ||
} | ||
|
||
// Refresh refresh observers each CA loop. | ||
func (l *ObserversList) Refresh() (stopLoop bool, err error) { | ||
var resultErr error | ||
if l.observers == nil { | ||
return false, nil | ||
} | ||
for _, observer := range l.observers { | ||
stopLoop, err := observer.Refresh() | ||
if stopLoop { | ||
return true, nil | ||
} | ||
resultErr = errors.Join(resultErr, err) | ||
} | ||
return false, resultErr | ||
} | ||
|
||
// NewObserversList return new ObserversList. | ||
func NewObserversList(observers []Observer) *ObserversList { | ||
return &ObserversList{observers} | ||
} |
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
cluster-autoscaler/processors/provreq/provsioning_request_processor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package provreq | ||
|
||
import ( | ||
"k8s.io/autoscaler/cluster-autoscaler/observers/loopstart" | ||
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/provreqclient" | ||
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/provreqwrapper" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
// ProvisioningRequestProcessor process ProvisionignRequests in the cluster. | ||
type ProvisioningRequestProcessor interface { | ||
Process([]*provreqwrapper.ProvisioningRequest) error | ||
CleanUp() | ||
} | ||
|
||
type provisioningRequestClient interface { | ||
ProvisioningRequests() ([]*provreqwrapper.ProvisioningRequest, error) | ||
ProvisioningRequest(namespace, name string) (*provreqwrapper.ProvisioningRequest, error) | ||
} | ||
|
||
// CombinedProvReqProcessor contains ProvisioningClassProcessor for each ProvisioningClass. | ||
type CombinedProvReqProcessor struct { | ||
client provisioningRequestClient | ||
processors []ProvisioningRequestProcessor | ||
} | ||
|
||
// NewCombinedProvReqProcessor return new CombinedProvReqProcessor. | ||
func NewCombinedProvReqProcessor(kubeConfig *rest.Config, processors []ProvisioningRequestProcessor) (loopstart.Observer, error) { | ||
client, err := provreqclient.NewProvisioningRequestClient(kubeConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &CombinedProvReqProcessor{client: client, processors: processors}, nil | ||
} | ||
|
||
// Refresh iterates over ProvisioningRequests and updates its conditions/state. | ||
func (cp *CombinedProvReqProcessor) Refresh() (bool, error) { | ||
provReqs, err := cp.client.ProvisioningRequests() | ||
if err != nil { | ||
return true, err | ||
} | ||
for _, p := range cp.processors { | ||
if err := p.Process(provReqs); err != nil { | ||
return false, err | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
// CleanUp cleans up internal state | ||
func (cp *CombinedProvReqProcessor) CleanUp() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.