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>
  • Loading branch information
patst committed Jan 30, 2023
1 parent 751c631 commit cc9c1df
Show file tree
Hide file tree
Showing 3 changed files with 56 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
5 changes: 4 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 @@ -374,7 +375,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 cc9c1df

Please sign in to comment.