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

fix: respect all required demands in azure pipeline scaler #4405

5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ issues:
- path: apis/keda/v1alpha1/scaledobject_webhook_test.go
linters:
- gci
# Exclude for azure_pipelines_scaler, reason:
# pkg/scalers/azure_pipelines_scaler.go:408:10: badCond: `countDemands == len(demandsInJob) && countDemands == len(demandsInScaler)` condition is suspicious (gocritic)
- path: azure_pipelines_scaler.go
linters:
- gocritic


linters-settings:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **Admission Webhooks**: Allow to remove the finalizer even if the ScaledObject isn't valid ([#4396](https://github.com/kedacore/keda/issue/4396))
- **AWS SQS Scaler**: Respect `scaleOnInFlight` value ([#4276](https://github.com/kedacore/keda/issue/4276))
- **Azure Pipelines**: Fix for disallowing `$top` on query when using `meta.parentID` method ([#4397])
- **Azure Pipelines**: Respect all required demands ([#4404](https://github.com/kedacore/keda/issues/4404))

### Deprecations

Expand Down
35 changes: 22 additions & 13 deletions pkg/scalers/azure_pipelines_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,35 @@ func stripDeadJobs(jobs []JobRequest) []JobRequest {
return filtered
}

func stripAgentVFromArray(array []string) []string {
var result []string

for _, item := range array {
if !strings.HasPrefix(item, "Agent.Version") {
result = append(result, item)
}
}
return result
}

// Determine if the scaledjob has the right demands to spin up
func getCanAgentDemandFulfilJob(jr JobRequest, metadata *azurePipelinesMetadata) bool {
var demandsReq = jr.Demands
var demandsAvail = strings.Split(metadata.demands, ",")
var countDemands = 0
for _, dr := range demandsReq {
for _, da := range demandsAvail {
strDr := fmt.Sprintf("%v", dr)
if !strings.HasPrefix(strDr, "Agent.Version") {
if strDr == da {
countDemands++
}
countDemands := 0
demandsInJob := stripAgentVFromArray(jr.Demands)
demandsInScaler := stripAgentVFromArray(strings.Split(metadata.demands, ","))

for _, demandInJob := range demandsInJob {
for _, demandInScaler := range demandsInScaler {
if demandInJob == demandInScaler {
countDemands++
}
}
}
matchDemands := countDemands == len(demandsReq)-1

if metadata.requireAllDemands {
return matchDemands && countDemands == len(demandsAvail)
return countDemands == len(demandsInJob) && countDemands == len(demandsInScaler)
}
return matchDemands
return countDemands == len(demandsInJob)
}

// Determine if the Job and Parent Agent Template have matching capabilities
Expand Down