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

Added a demand checker for Azure Pipelines #2707

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- **Azure Queue:** Don't call Azure queue GetProperties API unnecessarily ([#2613](https://github.com/kedacore/keda/pull/2613))
- **Datadog Scaler:** Validate query to contain `{` to prevent panic on invalid query ([#2625](https://github.com/kedacore/keda/issues/2625))
- **Kafka Scaler** Make "disable" a valid value for tls auth parameter ([#2608](https://github.com/kedacore/keda/issues/2608))
- **Azure Pipelines:** Added the ability to support ADO demands by referencing a master template ([#2707](https://github.com/kedacore/keda/pull/2707))
zroubalik marked this conversation as resolved.
Show resolved Hide resolved

### Breaking Changes

Expand Down
34 changes: 32 additions & 2 deletions pkg/scalers/azure_pipelines_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type azurePipelinesMetadata struct {
organizationURL string
Eldarrin marked this conversation as resolved.
Show resolved Hide resolved
organizationName string
personalAccessToken string
parent string
scalarName string
poolID int
targetPipelinesQueueLength int
scalerIndex int
Expand Down Expand Up @@ -100,6 +102,12 @@ func parseAzurePipelinesMetadata(ctx context.Context, config *ScalerConfig, http
return nil, fmt.Errorf("no personalAccessToken given")
}

if val, ok := config.TriggerMetadata["parent"]; ok && val != "" {
meta.parent = config.TriggerMetadata["parent"]
} else {
meta.parent = ""
}

if val, ok := config.TriggerMetadata["poolName"]; ok && val != "" {
var err error
meta.poolID, err = getPoolIDFromName(ctx, val, &meta, httpClient)
Expand All @@ -119,6 +127,7 @@ func parseAzurePipelinesMetadata(ctx context.Context, config *ScalerConfig, http
}

meta.scalerIndex = config.ScalerIndex
meta.scalarName = config.Name
zroubalik marked this conversation as resolved.
Show resolved Hide resolved

return &meta, nil
}
Expand Down Expand Up @@ -230,13 +239,34 @@ func (s *azurePipelinesScaler) GetAzurePipelinesQueueLength(ctx context.Context)
for _, value := range jobs {
v := value.(map[string]interface{})
if v["result"] == nil {
count++
if s.metadata.parent == "" {
// keep the old template working
count++
} else if getCanAgentFulfilJob(v, s.metadata) {
count++
}
}
}

return count, err
}

// Determine if the Job and Agent have matching capabilities
func getCanAgentFulfilJob(v map[string]interface{}, metadata *azurePipelinesMetadata) bool {
matchedAgents, ok := v["matchedAgents"].([]interface{})
if !ok {
// ADO is already processing
return false
}

for _, m := range matchedAgents {
n := m.(map[string]interface{})
if metadata.parent == n["name"].(string) {
return true
}
}
return false
}

func (s *azurePipelinesScaler) GetMetricSpecForScaling(context.Context) []v2beta2.MetricSpec {
targetPipelinesQueueLengthQty := resource.NewQuantity(int64(s.metadata.targetPipelinesQueueLength), resource.DecimalSI)
externalMetric := &v2beta2.ExternalMetricSource{
Expand Down