From 70a84ad80225a6e5f76dd93ae6e15fed604881f7 Mon Sep 17 00:00:00 2001 From: QuentinBisson Date: Wed, 20 Sep 2023 14:42:10 +0200 Subject: [PATCH] Fix API Server url for Managed EKS --- CHANGELOG.md | 4 ++++ files/templates/scrapeconfigs/_apiserver.yaml | 2 +- service/key/key.go | 11 ++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 570ee5fc2..c178f6780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix api server url in case the CAPI provider sets https prefix in the CAPI CR status. + ## [4.48.0] - 2023-09-19 ### Changed diff --git a/files/templates/scrapeconfigs/_apiserver.yaml b/files/templates/scrapeconfigs/_apiserver.yaml index fadc8a5c4..9e453a568 100644 --- a/files/templates/scrapeconfigs/_apiserver.yaml +++ b/files/templates/scrapeconfigs/_apiserver.yaml @@ -1,6 +1,6 @@ [[- define "_apiserver" -]] [[- if ne .ClusterType "management_cluster" ]] - api_server: https://[[ .APIServerURL ]] + api_server: [[ .APIServerURL ]] [[- if eq .AuthenticationType "token" ]] bearer_token_file: /etc/prometheus/secrets/[[ .SecretName ]]/token [[- end ]] diff --git a/service/key/key.go b/service/key/key.go index 743cbed29..69acf6f1f 100644 --- a/service/key/key.go +++ b/service/key/key.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math" + "strings" "github.com/giantswarm/k8sclient/v7/pkg/k8sclient" "github.com/giantswarm/microerror" @@ -270,11 +271,15 @@ func AlertmanagerKey() string { func APIUrl(obj interface{}) string { switch v := obj.(type) { case *v1.Service: - return "kubernetes.default:443" + return "https://kubernetes.default:443" case *capi.Cluster: - return fmt.Sprintf("%s:%d", v.Spec.ControlPlaneEndpoint.Host, v.Spec.ControlPlaneEndpoint.Port) + controlPlaneEndpointHost := v.Spec.ControlPlaneEndpoint.Host + if !strings.HasPrefix(controlPlaneEndpointHost, "https://") { + controlPlaneEndpointHost = "https://" + controlPlaneEndpointHost + } + return fmt.Sprintf("%s:%d", controlPlaneEndpointHost, v.Spec.ControlPlaneEndpoint.Port) case metav1.Object: - return fmt.Sprintf("master.%s:443", v.GetName()) + return fmt.Sprintf("https://master.%s:443", v.GetName()) } return ""