Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds injection metrics for fake pod injection #7335

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ 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 +46,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) {
injectedFakePodsCount += 1
if removedFakePodsCount < numberOfFakePodsToRemove {
removedFakePodsCount += 1
continue
}
}

unschedulablePodsAfterProcessing = append(unschedulablePodsAfterProcessing, pod)
}

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

return unschedulablePodsAfterProcessing, nil
}

Expand Down
Loading