Skip to content

Commit

Permalink
https://github.com/kedacore/keda/issues/5419
Browse files Browse the repository at this point in the history
Signed-off-by: Siva Guruvareddiar <sivagurunath@gmail.com>
  • Loading branch information
sguruvar committed Jan 20, 2024
1 parent 31d2afa commit f20f5a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pkg/scalers/aws/aws_sigv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
func parseAwsAMPMetadata(config *scalersconfig.ScalerConfig) (*awsConfigMetadata, error) {
meta := awsConfigMetadata{}

if val, ok := config.TriggerMetadata["awsRegion"]; ok && val != "" {
meta.awsRegion = val
} else {
return nil, ErrAwsAMPNoAwsRegion
}

auth, err := GetAwsAuthorization(config.TriggerUniqueKey, config.PodIdentity, config.TriggerMetadata, config.AuthParams, config.ResolvedEnv)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ data:
triggerAuthenticationTemplate = `apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-aws-credentials
name: keda-trigger-auth-aws-credentials-acc
namespace: {{.TestNamespace}}
spec:
secretTargetRef:
Expand Down Expand Up @@ -99,9 +99,11 @@ metadata:
app: {{.DeploymentName}}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{.DeploymentName}}
maxReplicaCount: 2
minReplicaCount: 0
maxReplicaCount: 30
minReplicaCount: 1
cooldownPeriod: 1
advanced:
horizontalPodAutoscalerConfig:
Expand All @@ -111,9 +113,10 @@ spec:
triggers:
- type: prometheus
authenticationRef:
name: keda-trigger-auth-aws-credentials
name: keda-trigger-auth-aws-credentials-acc
metadata:
awsRegion: {{.AwsRegion}}
metricName: s0-prometheus
serverAddress: "https://aps-workspaces.{{.AwsRegion}}.amazonaws.com/workspaces/{{.WorkspaceID}}"
query: "vector(100)"
threshold: "50.0"
Expand Down Expand Up @@ -146,10 +149,9 @@ func TestScaler(t *testing.T) {

data, templates := getTemplateData()
CreateKubernetesResources(t, kc, testNamespace, data, templates)
t.Log(secretTemplate)
t.Log("--- assert ---")
expectedReplicaCountNumber := 2 // as mentioned above, as the AMP returns 100 and the threshold set to 50, the expected replica count is 100 / 50 = 2
assert.Truef(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, 0, 60, 1),
assert.Truef(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, expectedReplicaCountNumber, 60, 1),
"replica count should be %d after a minute", expectedReplicaCountNumber)

t.Log("--- cleaning up ---")
Expand All @@ -173,8 +175,9 @@ func getTemplateData() (templateData, []Template) {
ScaledObjectName: scaledObjectName,
WorkspaceID: workspaceID,
}, []Template{
{Name: "deploymentTemplate", Config: deploymentTemplate},
{Name: "secretTemplate", Config: secretTemplate},
{Name: "triggerAuthenticationTemplate", Config: triggerAuthenticationTemplate},
{Name: "deploymentTemplate", Config: deploymentTemplate},
{Name: "scaledObjectTemplate", Config: scaledObjectTemplate},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestScaler(t *testing.T) {

t.Log("--- assert ---")
expectedReplicaCountNumber := 2 // as mentioned above, as the AMP returns 100 and the threshold set to 50, the expected replica count is 100 / 50 = 2
assert.Truef(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, 0, 60, 1),
assert.Truef(t, WaitForDeploymentReplicaReadyCount(t, kc, deploymentName, testNamespace, expectedReplicaCountNumber, 60, 1),
"replica count should be %d after a minute", expectedReplicaCountNumber)

t.Log("--- cleaning up ---")
Expand Down

0 comments on commit f20f5a0

Please sign in to comment.