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

Allow passing of metrics server secret to flagger #1672

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion cmd/flagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
kubeconfigQPS int
kubeconfigBurst int
metricsServer string
metricsServerSecretRef string
controlLoopInterval time.Duration
logLevel string
port string
Expand Down Expand Up @@ -94,6 +95,7 @@ func init() {
flag.IntVar(&kubeconfigBurst, "kubeconfig-burst", 250, "Set Burst for kubeconfig.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&metricsServer, "metrics-server", "http://prometheus:9090", "Prometheus URL.")
flag.StringVar(&metricsServerSecretRef, "metrics-server-secret-ref", "", "Prometheus Secret Reference.")
flag.DurationVar(&controlLoopInterval, "control-loop-interval", 10*time.Second, "Kubernetes API sync interval.")
flag.StringVar(&logLevel, "log-level", "debug", "Log level can be: debug, info, warning, error.")
flag.StringVar(&port, "port", "8080", "Port to listen on.")
Expand Down Expand Up @@ -196,7 +198,7 @@ func main() {
logger.Infof("Watching namespace %s", namespace)
}

observerFactory, err := observers.NewFactory(metricsServer)
observerFactory, err := observers.NewFactoryWithSecret(metricsServer, metricsServerSecretRef)
if err != nil {
logger.Fatalf("Error building prometheus client: %s", err.Error())
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/metrics/observers/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ import (

flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
"github.com/fluxcd/flagger/pkg/metrics/providers"
corev1 "k8s.io/api/core/v1"
)

type Factory struct {
Client providers.Interface
}

func NewFactory(metricsServer string) (*Factory, error) {
return NewFactoryWithSecret(metricsServer, "")
}

func NewFactoryWithSecret(metricsServer string, metricsServerSecretRef string) (*Factory, error) {
var secretRef *corev1.LocalObjectReference
if metricsServerSecretRef != "" {
secretRef = &corev1.LocalObjectReference{Name: metricsServerSecretRef}
}
client, err := providers.NewPrometheusProvider(flaggerv1.MetricTemplateProvider{
Type: "prometheus",
Address: metricsServer,
SecretRef: nil,
SecretRef: secretRef,
}, nil)
if err != nil {
return nil, err
Expand Down