Skip to content

Commit

Permalink
Fix API Server url for Managed EKS
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinBisson committed Sep 20, 2023
1 parent 75f55c2 commit 70a84ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion files/templates/scrapeconfigs/_apiserver.yaml
Original file line number Diff line number Diff line change
@@ -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 ]]
Expand Down
11 changes: 8 additions & 3 deletions service/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math"
"strings"

"github.com/giantswarm/k8sclient/v7/pkg/k8sclient"
"github.com/giantswarm/microerror"
Expand Down Expand Up @@ -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 ""
Expand Down

0 comments on commit 70a84ad

Please sign in to comment.