Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter Non-Kube-Apiserver AdvertisedAddresses #412

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading