Skip to content

Commit

Permalink
Merge pull request #7372 from Shubham82/cherry-picked-of-#7335_and_#7…
Browse files Browse the repository at this point in the history
…338-upstream-cluster-autoscaler-release-1.31

Backport #7335 and #7338[CA]Adds injection metrics for fake pod injection and Report only injected pods after enforcing pod limit into CA1.31
  • Loading branch information
k8s-ci-robot authored Oct 11, 2024
2 parents 07806e9 + 29579df commit 802cf01
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ package podinjection
import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/context"
"k8s.io/autoscaler/cluster-autoscaler/metrics"
)

const (
// InjectedMetricsLabel is the label for unschedulable pods metric for injected pods.
InjectedMetricsLabel = "injected"
// SkippedInjectionMetricsLabel is the label for unschedulable pods metric for pods that was not injected due to limit.
SkippedInjectionMetricsLabel = "skipped_injection"
)

// EnforceInjectedPodsLimitProcessor is a PodListProcessor used to limit the number of injected fake pods.
Expand All @@ -37,17 +45,25 @@ func NewEnforceInjectedPodsLimitProcessor(podLimit int) *EnforceInjectedPodsLimi
func (p *EnforceInjectedPodsLimitProcessor) Process(ctx *context.AutoscalingContext, unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) {

numberOfFakePodsToRemove := len(unschedulablePods) - p.podLimit
removedFakePodsCount := 0
injectedFakePodsCount := 0
var unschedulablePodsAfterProcessing []*apiv1.Pod

for _, pod := range unschedulablePods {
if IsFake(pod) && numberOfFakePodsToRemove > 0 {
numberOfFakePodsToRemove -= 1
continue
if IsFake(pod) {
if removedFakePodsCount < numberOfFakePodsToRemove {
removedFakePodsCount += 1
continue
}
injectedFakePodsCount += 1
}

unschedulablePodsAfterProcessing = append(unschedulablePodsAfterProcessing, pod)
}

metrics.UpdateUnschedulablePodsCountWithLabel(injectedFakePodsCount, InjectedMetricsLabel)
metrics.UpdateUnschedulablePodsCountWithLabel(removedFakePodsCount, SkippedInjectionMetricsLabel)

return unschedulablePodsAfterProcessing, nil
}

Expand Down

0 comments on commit 802cf01

Please sign in to comment.