Skip to content

Commit

Permalink
azure-pipelines scaler allows configuration of requireAllDemands keda…
Browse files Browse the repository at this point in the history
…core#4138

Signed-off-by: Patrick Steinig <patrick.steinig@googlemail.com>
Signed-off-by: patst <patrick.steinig@googlemail.com>
  • Loading branch information
patst committed Feb 6, 2023
1 parent c0c9949 commit baf0bce
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Here is an overview of all new **experimental** features:

### Improvements

- **Azure Pipelines Scaler:** New configuration parameter `requireAllDemands` to scale only if jobs request all demands provided by the scaling definition ([#4138](https://github.com/kedacore/keda/issues/4138))
- **General**: Add a warning when KEDA run outside supported k8s versions ([#4130](https://github.com/kedacore/keda/issues/4130))
- **General**: Use (self-signed) certificates for all the communications (internals and externals) ([#3931](https://github.com/kedacore/keda/issues/3931))
- **Hashicorp Vault**: Add support to secrets backend version 1 ([#2645](https://github.com/kedacore/keda/issues/2645))
Expand Down
15 changes: 14 additions & 1 deletion pkg/scalers/azure_pipelines_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type azurePipelinesMetadata struct {
targetPipelinesQueueLength int64
activationTargetPipelinesQueueLength int64
scalerIndex int
requireAllDemands bool
}

// NewAzurePipelinesScaler creates a new AzurePipelinesScaler
Expand Down Expand Up @@ -217,6 +218,16 @@ func parseAzurePipelinesMetadata(ctx context.Context, config *ScalerConfig, http
meta.demands = ""
}

if val, ok := config.TriggerMetadata["requireAllDemands"]; ok && val != "" {
requireAllDemands, err := strconv.ParseBool(val)
if err != nil {
return nil, err
}
meta.requireAllDemands = requireAllDemands
} else {
meta.requireAllDemands = false
}

if val, ok := config.TriggerMetadata["poolName"]; ok && val != "" {
var err error
poolID, err := getPoolIDFromName(ctx, val, &meta, httpClient)
Expand Down Expand Up @@ -374,7 +385,9 @@ func getCanAgentDemandFulfilJob(jr JobRequest, metadata *azurePipelinesMetadata)
}
}
}

if metadata.requireAllDemands {
return countDemands == len(demandsAvail) && len(demandsAvail) == len(demandsReq)-1
}
return countDemands == len(demandsReq)-1
}

Expand Down
51 changes: 51 additions & 0 deletions pkg/scalers/azure_pipelines_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,57 @@ func TestAzurePipelinesNonMatchedDemandAgent(t *testing.T) {
}
}

func TestAzurePipelinesMatchedDemandAgentWithRequireAllDemands(t *testing.T) {
var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buildLoadJSON())
}))

meta := getDemandJobMetaData(apiStub.URL)
meta.requireAllDemands = true

mockAzurePipelinesScaler := azurePipelinesScaler{
metadata: meta,
httpClient: http.DefaultClient,
}

queuelen, err := mockAzurePipelinesScaler.GetAzurePipelinesQueueLength(context.TODO())

if err != nil {
t.Fail()
}

if queuelen < 1 {
t.Fail()
}
}

func TestAzurePipelinesNotMatchedPartialRequiredTriggerDemands(t *testing.T) {
var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buildLoadJSON())
}))

meta := getDemandJobMetaData(apiStub.URL)
meta.requireAllDemands = true
meta.demands = "kubectl,someOtherDemand" // the build demands only kubectl

mockAzurePipelinesScaler := azurePipelinesScaler{
metadata: meta,
httpClient: http.DefaultClient,
}

queuelen, err := mockAzurePipelinesScaler.GetAzurePipelinesQueueLength(context.TODO())

if err != nil {
t.Fail()
}

if queuelen > 0 {
t.Fail()
}
}

func buildLoadJSON() []byte {
output := testJobRequestResponse[0 : len(testJobRequestResponse)-2]
for i := 1; i < loadCount; i++ {
Expand Down

0 comments on commit baf0bce

Please sign in to comment.