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

Metrics api unsafessl #3823

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -57,6 +57,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **GCP Storage Scaler:** Add prefix and delimiter support ([#3756](https://github.com/kedacore/keda/issues/3756))
- **Prometheus Scaler:** Introduce skipping of certificate check for unsigned certs ([#2310](https://github.com/kedacore/keda/issues/2310))
- **Event Hubs Scaler:** Support Azure Active Direcotry Pod & Workload Identity for Storage Blobs ([#3569](https://github.com/kedacore/keda/issues/3569))
- **Metrics API Scaler:** Add unsafeSsl paramater to skil certificate validation when connecting over HTTPS ([#3728](https://github.com/kedacore/keda/discussions/3728))
wymangr marked this conversation as resolved.
Show resolved Hide resolved

### Fixes

Expand Down
14 changes: 12 additions & 2 deletions pkg/scalers/metrics_api_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type metricsAPIScalerMetadata struct {
activationTargetValue float64
url string
valueLocation string
unsafeSsl bool

// apiKeyAuth
enableAPIKeyAuth bool
Expand Down Expand Up @@ -76,14 +77,13 @@ func NewMetricsAPIScaler(config *ScalerConfig) (Scaler, error) {
return nil, fmt.Errorf("error parsing metric API metadata: %s", err)
}

httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout, false)
httpClient := kedautil.CreateHTTPClient(config.GlobalHTTPTimeout, meta.unsafeSsl)

if meta.enableTLS || len(meta.ca) > 0 {
config, err := kedautil.NewTLSConfig(meta.cert, meta.key, meta.ca)
if err != nil {
return nil, err
}

httpClient.Transport = &http.Transport{TLSClientConfig: config}
}

Expand All @@ -98,6 +98,16 @@ func NewMetricsAPIScaler(config *ScalerConfig) (Scaler, error) {
func parseMetricsAPIMetadata(config *ScalerConfig) (*metricsAPIScalerMetadata, error) {
meta := metricsAPIScalerMetadata{}
meta.scalerIndex = config.ScalerIndex
var err error

if val, ok := config.TriggerMetadata["unsafeSsl"]; ok {
meta.unsafeSsl, err = strconv.ParseBool(val)
if err != nil {
return nil, fmt.Errorf("error parsing unsafeSsl: %s", err)
}
} else {
meta.unsafeSsl = false
}
wymangr marked this conversation as resolved.
Show resolved Hide resolved

if val, ok := config.TriggerMetadata["targetValue"]; ok {
targetValue, err := strconv.ParseFloat(val, 64)
Expand Down
4 changes: 4 additions & 0 deletions pkg/scalers/metrics_api_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ var testMetricsAPIAuthMetadata = []metricAPIAuthMetadataTestData{
{map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric", "targetValue": "42", "authMode": "bearer"}, map[string]string{"token": "bearerTokenValue"}, false},
// fail bearerAuth without token
{map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric", "targetValue": "42", "authMode": "bearer"}, map[string]string{}, true},
// success unsafeSsl true
{map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric", "targetValue": "42", "unsafeSsl": "true"}, map[string]string{}, false},
// success unsafeSsl false
{map[string]string{"url": "http://dummy:1230/api/v1/", "valueLocation": "metric", "targetValue": "42", "unsafeSsl": "false"}, map[string]string{}, false},
zroubalik marked this conversation as resolved.
Show resolved Hide resolved
}

func TestParseMetricsAPIMetadata(t *testing.T) {
Expand Down