Skip to content

Commit

Permalink
filter non-kube-apiserver advertisedAddresses (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
petersutter committed Mar 18, 2024
1 parent 2ea8952 commit 315af70
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions internal/client/garden/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,17 @@ var _ = Describe("Client", func() {
Status: gardencorev1beta1.ShootStatus{
AdvertisedAddresses: []gardencorev1beta1.ShootAdvertisedAddress{
{
Name: "shoot-address1",
Name: "external",
URL: "https://api." + domain,
},
{
Name: "shoot-address2",
Name: "internal",
URL: "https://api2." + domain,
},
{
Name: "service-account-issuer",
URL: "https://foo.bar/projects/prod1/shoots/test-shoot1/issuer",
},
},
},
}
Expand Down
16 changes: 15 additions & 1 deletion internal/client/garden/shoot_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ const (
ShootProjectSecretSuffixCACluster = "ca-cluster"
// DataKeyCertificateCA is the key in a secret or config map data holding the CA certificate.
DataKeyCertificateCA = "ca.crt"

// AdvertisedAddressExternal is a constant that represents the name of the external kube-apiserver address.
AdvertisedAddressExternal = "external"
// AdvertisedAddressInternal is a constant that represents the name of the internal kube-apiserver address.
AdvertisedAddressInternal = "internal"
// AdvertisedAddressUnmanaged is a constant that represents the name of the unmanaged kube-apiserver address.
AdvertisedAddressUnmanaged = "unmanaged"
)

// shootKubeconfigRequest is a struct which holds information about a Kubeconfig to be generated.
Expand All @@ -56,7 +63,7 @@ type shootKubeconfigRequest struct {

// cluster holds the data to describe and connect to a kubernetes cluster.
type cluster struct {
// name is the name of the shoot advertised address, usually "external", "internal" or "unmanaged"
// name is the name of the shoot advertised address. Either "external", "internal" or "unmanaged"
name string
// apiServerHost is the host of the kube-apiserver
apiServerHost string
Expand Down Expand Up @@ -258,6 +265,13 @@ func (g *clientImpl) GetShootClientConfig(ctx context.Context, namespace, name s
}

for _, address := range shoot.Status.AdvertisedAddresses {
isKubeApiserverAddress := address.Name == AdvertisedAddressExternal ||
address.Name == AdvertisedAddressInternal ||
address.Name == AdvertisedAddressUnmanaged
if !isKubeApiserverAddress {
continue
}

u, err := url.Parse(address.URL)
if err != nil {
return nil, fmt.Errorf("could not parse shoot server url: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var _ = Describe("SSH Command", func() {
Status: gardencorev1beta1.ShootStatus{
AdvertisedAddresses: []gardencorev1beta1.ShootAdvertisedAddress{
{
Name: "shoot-address1",
Name: "external",
URL: "https://api.bar.baz",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/sshpatch/sshpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ var _ = Describe("SSH Patch Command", func() {
Status: gardencorev1beta1.ShootStatus{
AdvertisedAddresses: []gardencorev1beta1.ShootAdvertisedAddress{
{
Name: "shoot-address1",
Name: "external",
URL: "https://api.bar.baz",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/target/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func createTestShoot(name string, namespace string, seedName *string) *gardencor
Status: gardencorev1beta1.ShootStatus{
AdvertisedAddresses: []gardencorev1beta1.ShootAdvertisedAddress{
{
Name: "shoot-address1",
Name: "external",
URL: "https://api.bar.baz",
},
},
Expand Down

0 comments on commit 315af70

Please sign in to comment.