Skip to content

Commit

Permalink
Backport kubernetes#7335 and kubernetes#7338[CA]Adds injection metric…
Browse files Browse the repository at this point in the history
…s for fake pod injection and Report only injected pods after enforcing pod limit into CA1.31
  • Loading branch information
Shubham82 committed Oct 8, 2024
1 parent 07806e9 commit 29579df
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 29579df

Please sign in to comment.