Skip to content

Commit

Permalink
fix: respect all required demands in azure pipeline scaler (kedacore#…
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneLugovtsov authored and JorTurFer committed Apr 13, 2023
1 parent 6ac7099 commit 91bf046
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ issues:
- path: mongo_scaler.go
linters:
- dupl
# Exclude gci check for //+kubebuilder:scaffold:imports comments. Waiting to
# resolve https://github.com/kedacore/keda/issues/4379
- path: cmd/operator/main.go
linters:
- gci
- path: cmd/webhooks/main.go
linters:
- gci
- path: controllers/keda/suite_test.go
linters:
- gci
- 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:
funlen:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio

- **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

0 comments on commit 91bf046

Please sign in to comment.