Skip to content

Commit 01db26c

Browse files
Copilotillume
andcommitted
Add custom API server endpoint configuration
- Added APIServerEndpoint field to backend config - Added --api-server-endpoint CLI flag and environment variable support - Updated GetInClusterContext to accept and use custom endpoint - Added Helm chart value config.apiServerEndpoint - Updated deployment template to pass value as argument Co-authored-by: illume <9541+illume@users.noreply.github.com>
1 parent a805367 commit 01db26c

File tree

7 files changed

+21
-2
lines changed

7 files changed

+21
-2
lines changed

backend/cmd/headlamp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ func createHeadlampHandler(config *HeadlampConfig) http.Handler {
434434
config.OidcClientID, config.OidcClientSecret,
435435
strings.Join(config.OidcScopes, ","),
436436
config.OidcSkipTLSVerify,
437-
config.OidcCACert)
437+
config.OidcCACert,
438+
config.APIServerEndpoint)
438439
if err != nil {
439440
logger.Log(logger.LevelError, nil, err, "Failed to get in-cluster context")
440441
}

backend/cmd/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func buildHeadlampCFG(conf *config.Config, kubeConfigStore kubeconfig.ContextSto
8282
return &headlampconfig.HeadlampCFG{
8383
UseInCluster: conf.InCluster,
8484
InClusterContextName: conf.InClusterContextName,
85+
APIServerEndpoint: conf.APIServerEndpoint,
8586
KubeConfigPath: conf.KubeConfigPath,
8687
SkippedKubeContexts: conf.SkippedKubeContexts,
8788
ListenAddr: conf.ListenAddr,

backend/pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Config struct {
3535
Version bool `koanf:"version"`
3636
InCluster bool `koanf:"in-cluster"`
3737
InClusterContextName string `koanf:"in-cluster-context-name"`
38+
APIServerEndpoint string `koanf:"api-server-endpoint"`
3839
DevMode bool `koanf:"dev"`
3940
InsecureSsl bool `koanf:"insecure-ssl"`
4041
LogLevel string `koanf:"log-level"`
@@ -415,6 +416,7 @@ func addGeneralFlags(f *flag.FlagSet) {
415416
f.Bool("version", false, "Print version information and exit")
416417
f.Bool("in-cluster", false, "Set when running from a k8s cluster")
417418
f.String("in-cluster-context-name", "main", "Name to use for the in-cluster Kubernetes context")
419+
f.String("api-server-endpoint", "", "Custom Kubernetes API server endpoint (overrides default in-cluster endpoint)")
418420
f.Bool("dev", false, "Allow connections from other origins")
419421
f.Bool("cache-enabled", false, "K8s cache in backend")
420422
f.Bool("no-browser", false, "Disable automatically opening the browser when using embedded frontend")

backend/pkg/headlampconfig/headlampConfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type HeadlampConfig struct {
4141
type HeadlampCFG struct {
4242
UseInCluster bool
4343
InClusterContextName string
44+
APIServerEndpoint string
4445
ListenAddr string
4546
CacheEnabled bool
4647
DevMode bool

backend/pkg/kubeconfig/kubeconfig.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,14 +1009,21 @@ func GetInClusterContext(
10091009
oidcScopes string,
10101010
oidcSkipTLSVerify bool,
10111011
oidcCACert string,
1012+
customAPIServerEndpoint string,
10121013
) (*Context, error) {
10131014
clusterConfig, err := rest.InClusterConfig()
10141015
if err != nil {
10151016
return nil, err
10161017
}
10171018

1019+
// Use custom API server endpoint if provided, otherwise use default from in-cluster config
1020+
apiServerHost := clusterConfig.Host
1021+
if customAPIServerEndpoint != "" {
1022+
apiServerHost = customAPIServerEndpoint
1023+
}
1024+
10181025
cluster := &api.Cluster{
1019-
Server: clusterConfig.Host,
1026+
Server: apiServerHost,
10201027
CertificateAuthority: clusterConfig.CAFile,
10211028
CertificateAuthorityData: clusterConfig.CAData,
10221029
}

charts/headlamp/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ spec:
235235
{{- if .Values.config.inClusterContextName }}
236236
- "-in-cluster-context-name={{ .Values.config.inClusterContextName }}"
237237
{{- end }}
238+
{{- if .Values.config.apiServerEndpoint }}
239+
- "-api-server-endpoint={{ .Values.config.apiServerEndpoint }}"
240+
{{- end }}
238241
{{- end }}
239242
{{- with .Values.config.enableHelm }}
240243
- "-enable-helm"

charts/headlamp/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ extraContainers: []
3434
config:
3535
inCluster: true
3636
inClusterContextName: "main"
37+
# -- Custom Kubernetes API server endpoint (overrides the default in-cluster endpoint).
38+
# Useful when requests need to pass through a proxy (e.g., kube-oidc-proxy).
39+
# Example: "https://kube-oidc-proxy.example.com:443"
40+
apiServerEndpoint: ""
3741
# -- base url path at which headlamp should run
3842
baseURL: ""
3943
oidc:

0 commit comments

Comments
 (0)