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

Add insecureSkipVerify option for Prometheus and Graphite #935

Merged
merged 5 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,9 @@ spec:
region:
description: Region of the provider
type: string
insecureSkipVerify:
description: Disable SSL certificate validation for the provider address
type: boolean
query:
description: Query of this metric template
type: string
Expand Down
3 changes: 3 additions & 0 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,9 @@ spec:
region:
description: Region of the provider
type: string
insecureSkipVerify:
description: Disable SSL certificate validation for the provider address
type: boolean
query:
description: Query of this metric template
type: string
Expand Down
3 changes: 3 additions & 0 deletions kustomize/base/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,9 @@ spec:
region:
description: Region of the provider
type: string
insecureSkipVerify:
description: Disable SSL certificate validation for the provider address
type: boolean
query:
description: Query of this metric template
type: string
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/flagger/v1beta1/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type MetricTemplateProvider struct {
// Region of the provider
// +optional
Region string `json:"region,omitempty"`

// InsecureSkipVerify disables certificate verification for the provider
// +optional
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}

// MetricTemplateModel is the query template model
Expand Down
11 changes: 10 additions & 1 deletion pkg/metrics/providers/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package providers

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -104,6 +105,7 @@ type GraphiteProvider struct {
username string
password string
timeout time.Duration
client *http.Client
}

// NewGraphiteProvider takes a provider spec and credentials map,
Expand All @@ -119,6 +121,13 @@ func NewGraphiteProvider(provider flaggerv1.MetricTemplateProvider, credentials
graph := GraphiteProvider{
url: *graphiteURL,
timeout: 5 * time.Second,
client: http.DefaultClient,
}

if provider.InsecureSkipVerify {
t := http.DefaultTransport.(*http.Transport).Clone()
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
graph.client = &http.Client{Transport: t}
}

if provider.SecretRef == nil {
Expand Down Expand Up @@ -168,7 +177,7 @@ func (g *GraphiteProvider) RunQuery(query string) (float64, error) {
ctx, cancel := context.WithTimeout(req.Context(), g.timeout)
defer cancel()

r, err := http.DefaultClient.Do(req.WithContext(ctx))
r, err := g.client.Do(req.WithContext(ctx))
if err != nil {
return 0, fmt.Errorf("request failed: %w", err)
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/metrics/providers/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package providers

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -39,6 +40,7 @@ type PrometheusProvider struct {
url url.URL
username string
password string
client *http.Client
}

type prometheusResponse struct {
Expand All @@ -64,6 +66,13 @@ func NewPrometheusProvider(provider flaggerv1.MetricTemplateProvider, credential
prom := PrometheusProvider{
timeout: 5 * time.Second,
url: *promURL,
client: http.DefaultClient,
}

if provider.InsecureSkipVerify {
t := http.DefaultTransport.(*http.Transport).Clone()
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
prom.client = &http.Client{Transport: t}
}

if provider.SecretRef != nil {
Expand Down Expand Up @@ -106,7 +115,7 @@ func (p *PrometheusProvider) RunQuery(query string) (float64, error) {
ctx, cancel := context.WithTimeout(req.Context(), p.timeout)
defer cancel()

r, err := http.DefaultClient.Do(req.WithContext(ctx))
r, err := p.client.Do(req.WithContext(ctx))
if err != nil {
return 0, fmt.Errorf("request failed: %w", err)
}
Expand Down