Skip to content

Commit 032985a

Browse files
committed
feat: Configure Prometheus endpoint via Helm chart (#4562)
Add PrometheusEndpoint to backend config and API - Update frontend to use configured endpoint for Prometheus plugin - Add config.prometheus.endpoint to Helm chart values - Use safe quoting for Helm value injection - Add backend validation for Prometheus URL Signed-off-by: zyzzmohit <mohitray949@gmail.com>
1 parent 51c2b8b commit 032985a

33 files changed

+123
-45
lines changed

backend/cmd/headlamp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const (
9797
type clientConfig struct {
9898
Clusters []Cluster `json:"clusters"`
9999
IsDynamicClusterEnabled bool `json:"isDynamicClusterEnabled"`
100+
PrometheusEndpoint string `json:"prometheusEndpoint"`
100101
}
101102

102103
type OauthConfig struct {
@@ -1750,7 +1751,7 @@ func parseClusterFromKubeConfig(kubeConfigs []string) ([]Cluster, []error) {
17501751
func (c *HeadlampConfig) getConfig(w http.ResponseWriter, r *http.Request) {
17511752
w.Header().Set("Content-Type", "application/json")
17521753

1753-
clientConfig := clientConfig{c.getClusters(), c.EnableDynamicClusters}
1754+
clientConfig := clientConfig{c.getClusters(), c.EnableDynamicClusters, c.PrometheusEndpoint}
17541755

17551756
if err := json.NewEncoder(w).Encode(&clientConfig); err != nil {
17561757
logger.Log(logger.LevelError, nil, err, "encoding config")

backend/cmd/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func buildHeadlampCFG(conf *config.Config, kubeConfigStore kubeconfig.ContextSto
101101
TLSCertPath: conf.TLSCertPath,
102102
TLSKeyPath: conf.TLSKeyPath,
103103
SessionTTL: conf.SessionTTL,
104+
PrometheusEndpoint: *conf.PrometheusEndpoint,
104105
}
105106
}
106107

backend/cmd/stateless.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (c *HeadlampConfig) parseKubeConfig(w http.ResponseWriter, r *http.Request)
178178
return
179179
}
180180

181-
clientConfig := clientConfig{contexts, c.EnableDynamicClusters}
181+
clientConfig := clientConfig{contexts, c.EnableDynamicClusters, c.PrometheusEndpoint}
182182

183183
if err := json.NewEncoder(w).Encode(&clientConfig); err != nil {
184184
logger.Log(logger.LevelError, nil, err, "encoding config")

backend/pkg/config/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type Config struct {
8585
// TLS config
8686
TLSCertPath string `koanf:"tls-cert-path"`
8787
TLSKeyPath string `koanf:"tls-key-path"`
88+
PrometheusEndpoint *string `koanf:"prometheus-endpoint"`
8889
}
8990

9091
func (c *Config) Validate() error {
@@ -138,12 +139,17 @@ func (c *Config) Validate() error {
138139
return errors.New("at least one tracing exporter (jaeger, otlp, or stdout) must be configured")
139140
}
140141

141-
if (c.UseOTLPHTTP != nil && *c.UseOTLPHTTP) &&
142142
(c.OTLPEndpoint == nil || *c.OTLPEndpoint == "") {
143143
return errors.New("otlp-endpoint must be configured when use-otlp-http is enabled")
144144
}
145145
}
146146

147+
if c.PrometheusEndpoint != nil && *c.PrometheusEndpoint != "" {
148+
if !strings.HasPrefix(*c.PrometheusEndpoint, "http://") && !strings.HasPrefix(*c.PrometheusEndpoint, "https://") {
149+
return errors.New("prometheus-endpoint must start with http:// or https://")
150+
}
151+
}
152+
147153
return nil
148154
}
149155

@@ -448,6 +454,7 @@ func addGeneralFlags(f *flag.FlagSet) {
448454
f.Uint("port", defaultPort, "Port to listen from")
449455
f.String("proxy-urls", "", "Allow proxy requests to specified URLs")
450456
f.Bool("enable-helm", false, "Enable Helm operations")
457+
f.String("prometheus-endpoint", "", "Prometheus endpoint for the cluster")
451458
}
452459

453460
func addOIDCFlags(f *flag.FlagSet) {

backend/pkg/headlampconfig/headlampConfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ type HeadlampCFG struct {
6363
TLSCertPath string
6464
TLSKeyPath string
6565
SessionTTL int
66+
PrometheusEndpoint string
6667
}

charts/headlamp/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ spec:
319319
{{- with .Values.config.baseURL }}
320320
- "-base-url={{ . }}"
321321
{{- end }}
322+
{{- with .Values.config.prometheus.endpoint }}
323+
- "-prometheus-endpoint={{ . | quote }}"
324+
{{- end }}
322325
{{- with .Values.config.tlsCertPath }}
323326
- "-tls-cert-path={{ . }}"
324327
{{- end }}

charts/headlamp/tests/expected_templates/azure-oidc-with-validators.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ spec:
115115
- "-in-cluster"
116116
- "-in-cluster-context-name=main"
117117
- "-plugins-dir=/headlamp/plugins"
118-
- "-session-ttl=86400"
119118
# Check if externalSecret is disabled
120119
# Check if clientID is non empty either from env or oidc.config
121120
- "-oidc-client-id=$(OIDC_CLIENT_ID)"

charts/headlamp/tests/expected_templates/default.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ spec:
112112
- "-in-cluster"
113113
- "-in-cluster-context-name=main"
114114
- "-plugins-dir=/headlamp/plugins"
115-
- "-session-ttl=86400"
116115
# Check if externalSecret is disabled
117116
ports:
118117
- name: http

charts/headlamp/tests/expected_templates/extra-args.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ spec:
112112
- "-in-cluster"
113113
- "-in-cluster-context-name=main"
114114
- "-plugins-dir=/headlamp/plugins"
115-
- "-session-ttl=86400"
116115
# Check if externalSecret is disabled
117116
- -insecure-ssl
118117
ports:

charts/headlamp/tests/expected_templates/extra-manifests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ spec:
129129
- "-in-cluster"
130130
- "-in-cluster-context-name=main"
131131
- "-plugins-dir=/headlamp/plugins"
132-
- "-session-ttl=86400"
133132
# Check if externalSecret is disabled
134133
ports:
135134
- name: http

0 commit comments

Comments
 (0)