Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslava-serdiuk committed Jan 2, 2024
1 parent a4bb50c commit b7672fc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import (

// NewDefaultPodListProcessor returns a default implementation of the pod list
// processor, which wraps and sequentially runs other sub-processors.
func NewDefaultPodListProcessor(predicateChecker predicatechecker.PredicateChecker) *pods.ListedPodListProcessor {
return &pods.ListedPodListProcessor{
Processors: []pods.PodListProcessor{
func NewDefaultPodListProcessor(predicateChecker predicatechecker.PredicateChecker) *pods.CombinedPodListProcessor {
return pods.NewCombinedPodListProcessor([]pods.PodListProcessor{
NewClearTPURequestsPodListProcessor(),
NewFilterOutExpendablePodListProcessor(),
NewCurrentlyDrainedNodesPodListProcessor(),
NewFilterOutSchedulablePodListProcessor(predicateChecker),
NewFilterOutDaemonSetPodListProcessor(),
},
}
})
}
2 changes: 1 addition & 1 deletion cluster-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
opts.Processors.TemplateNodeInfoProvider = nodeinfosprovider.NewDefaultTemplateNodeInfoProvider(nodeInfoCacheExpireTime, *forceDaemonSets)
podListProcessor := podlistprocessor.NewDefaultPodListProcessor(opts.PredicateChecker)
if autoscalingOptions.ProvisioningRequestEnabled {
podListProcessor.AppendProcessor(provreq.NewProvisioningRequestPodsFilter(provreq.NewDefautlEventManager()))
podListProcessor.AddProcessor(provreq.NewProvisioningRequestPodsFilter(provreq.NewDefautlEventManager()))
}
opts.Processors.PodListProcessor = podListProcessor
scaleDownCandidatesComparers := []scaledowncandidates.CandidatesComparer{}
Expand Down
29 changes: 17 additions & 12 deletions cluster-autoscaler/processors/pods/pod_list_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ func (p *NoOpPodListProcessor) Process(
func (p *NoOpPodListProcessor) CleanUp() {
}

// ListedPodListProcessor is a list of PodListProcessors
type ListedPodListProcessor struct {
Processors []PodListProcessor
// CombinedPodListProcessor is a list of PodListProcessors
type CombinedPodListProcessor struct {
processors []PodListProcessor
}

//NewCombinedPodListProcessor construct CombinedPodListProcessor.
func NewCombinedPodListProcessor(processors []PodListProcessor) *CombinedPodListProcessor {
return &CombinedPodListProcessor{processors}
}

// AddProcessor append processor to the list.
func (p *CombinedPodListProcessor) AddProcessor(processor PodListProcessor) {
p.processors = append(p.processors, processor)
}

// Process runs sub-processors sequentially
func (p *ListedPodListProcessor) Process(ctx *context.AutoscalingContext, unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) {
func (p *CombinedPodListProcessor) Process(ctx *context.AutoscalingContext, unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) {
var err error
for _, processor := range p.Processors {
for _, processor := range p.processors {
unschedulablePods, err = processor.Process(ctx, unschedulablePods)
if err != nil {
return nil, err
Expand All @@ -67,13 +77,8 @@ func (p *ListedPodListProcessor) Process(ctx *context.AutoscalingContext, unsche
}

// CleanUp cleans up the processor's internal structures.
func (p *ListedPodListProcessor) CleanUp() {
for _, processor := range p.Processors {
func (p *CombinedPodListProcessor) CleanUp() {
for _, processor := range p.processors {
processor.CleanUp()
}
}

// AppendProcessor append processor to the list.
func (p *ListedPodListProcessor) AppendProcessor(processor PodListProcessor) {
p.Processors = append(p.Processors, processor)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewDefautlEventManager() *defaultEventManager {

// LogIgnoredInScaleUpEvent adds event about ignored scale up for unscheduled pod, that consumes Provisioning Request.
func (e *defaultEventManager) LogIgnoredInScaleUpEvent(context *context.AutoscalingContext, now time.Time, pod *apiv1.Pod, prName string) {
message := fmt.Sprintf("Unschedulable pod ignored in scale-up loop, because it's consuming ProvisioningRequest %s/%s", pod.Namespace, prName)
message := fmt.Sprintf("Unschedulable pod didn't trigger scale-up, because it's consuming ProvisioningRequest %s/%s", pod.Namespace, prName)
if e.loggedEvents < e.limit {
context.Recorder.Event(pod, apiv1.EventTypeNormal, "", message)
e.loggedEvents++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ const (
provisioningRequestClientCallTimeout = 4 * time.Second
)

// ProvisioningRequestClient represents the service that is able to list
// and access different Provisioning Requests.
type ProvisioningRequestClient interface {
ProvisioningRequest(namespace, name string) (*provreqwrapper.ProvisioningRequest, error)
ProvisioningRequests() ([]*provreqwrapper.ProvisioningRequest, error)
}

// ProvisioningRequestClientV1beta1 represents client for v1beta1 ProvReq CRD.
type ProvisioningRequestClientV1beta1 struct {
client versioned.Interface
Expand All @@ -56,7 +49,7 @@ type ProvisioningRequestClientV1beta1 struct {
}

// NewProvisioningRequestClient configures and returns a provisioningRequestClient.
func NewProvisioningRequestClient(kubeConfig *rest.Config) (ProvisioningRequestClient, error) {
func NewProvisioningRequestClient(kubeConfig *rest.Config) (*ProvisioningRequestClientV1beta1, error) {
prClient, err := newPRClient(kubeConfig)
if err != nil {
return nil, fmt.Errorf("Failed to create Provisioning Request client: %v", err)
Expand Down

0 comments on commit b7672fc

Please sign in to comment.