-
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.
Introduce ProvisioningRequest processors
- Loading branch information
1 parent
8f75e9c
commit b821e53
Showing
10 changed files
with
198 additions
and
118 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
105 changes: 105 additions & 0 deletions
105
cluster-autoscaler/processors/provreq/provisioning_request_pods_filter.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,105 @@ | ||
package provreq | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/autoscaler/cluster-autoscaler/context" | ||
"k8s.io/autoscaler/cluster-autoscaler/processors/pods" | ||
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/provreqclient" | ||
"k8s.io/autoscaler/cluster-autoscaler/utils/klogx" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
const provisioningRequestPodAnnotationKey = "cluster-autoscaler.kubernetes.io/consume-provisioning-request" | ||
|
||
// EventManager is an interface for handling events for provisioning request. | ||
type EventManager interface { | ||
LogIgnoredInScaleUpEvent(context *context.AutoscalingContext, now time.Time, pod *apiv1.Pod, prName string) | ||
Reset() | ||
} | ||
|
||
type defaultEventManager struct { | ||
prClient provreqclient.ProvisioningRequestClient | ||
} | ||
|
||
// NewDefautlEventManager return basic event manager. | ||
func NewDefautlEventManager(pr provreqclient.ProvisioningRequestClient) *defaultEventManager { | ||
return &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) { | ||
pr, err := e.prClient.ProvisioningRequest(pod.Namespace, prName) | ||
if err != nil { | ||
if !errors.IsNotFound(err) { | ||
klog.Warningf("While fetching Provisioning Request %s/%s got unrecognized error: %v", pod.Namespace, prName, err) | ||
return | ||
} | ||
} | ||
message := fmt.Sprintf("Unschedulable pod ignored in scale-up loop, because it's consuming ProvisioningRequest %s/%s", pr.Namespace(), pr.Name()) | ||
context.Recorder.Event(pod, apiv1.EventTypeWarning, "", message) | ||
} | ||
|
||
// Reset resets event manager internal structure. | ||
func (e *defaultEventManager) Reset() {} | ||
|
||
// ProvisioningRequestPodsFilter filter out pods that consumes Provisioning Request | ||
type ProvisioningRequestPodsFilter struct { | ||
e EventManager | ||
} | ||
|
||
// Process filters out all pods that are consuming a Provisioning Request from unschedulable pods list. | ||
func (p *ProvisioningRequestPodsFilter) Process( | ||
context *context.AutoscalingContext, | ||
unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) { | ||
now := time.Now() | ||
p.e.Reset() | ||
loggingQuota := klogx.PodsLoggingQuota() | ||
result := make([]*apiv1.Pod, 0, len(unschedulablePods)) | ||
for _, pod := range unschedulablePods { | ||
prName, found := provisioningRequestName(pod) | ||
if !found { | ||
result = append(result, pod) | ||
continue | ||
} | ||
klogx.V(1).UpTo(loggingQuota).Infof("Ignoring unschedulable pod %s/%s as it consumes ProvisioningRequest: %s/%s", pod.Namespace, pod.Name, pod.Namespace, prName) | ||
p.e.LogIgnoredInScaleUpEvent(context, now, pod, prName) | ||
} | ||
klogx.V(1).Over(loggingQuota).Infof("There are also %v other pods which were ignored", -loggingQuota.Left()) | ||
return result, nil | ||
} | ||
|
||
// CleanUp cleans up the processor's internal structures. | ||
func (p *ProvisioningRequestPodsFilter) CleanUp() {} | ||
|
||
// ProvisioningRequestPodsInjector is a processor that inject in-memory pods from ProvisioningRequest. | ||
type ProvisioningRequestPodsInjector struct{} | ||
|
||
// Process inject in-memory pods that consumes a Provisioning Request to unschedulable pods list. | ||
// TODO(yaroslava): implement | ||
func (p *ProvisioningRequestPodsInjector) Process( | ||
context *context.AutoscalingContext, | ||
unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) { | ||
return unschedulablePods, nil | ||
} | ||
|
||
// CleanUp cleans up the processor's internal structures. | ||
func (p *ProvisioningRequestPodsInjector) CleanUp() {} | ||
|
||
// AddProvisioningRequestProcessors appends Provisioning Request processor to the list of pods list processors | ||
func AddProvisioningRequestProcessors(p *pods.ListedPodListProcessor, e EventManager) *pods.ListedPodListProcessor { | ||
p.Processors = append(p.Processors, &ProvisioningRequestPodsFilter{e}, &ProvisioningRequestPodsInjector{}) | ||
return p | ||
} | ||
|
||
func provisioningRequestName(pod *v1.Pod) (string, bool) { | ||
if pod == nil || pod.Annotations == nil { | ||
return "", false | ||
} | ||
provReqName, found := pod.Annotations[provisioningRequestPodAnnotationKey] | ||
return provReqName, found | ||
} |
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
Oops, something went wrong.