Skip to content

Commit

Permalink
When apiserver-proxy mutating webhook starts too late, firewalls don'…
Browse files Browse the repository at this point in the history
…t work (#326)
  • Loading branch information
majst01 authored Jul 4, 2023
1 parent d5306b1 commit 52bbb13
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/controller/controlplane/valuesprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"net/netip"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -1260,16 +1262,37 @@ func (vp *valuesProvider) getFirewallControllerManagerChartValues(ctx context.Co
Namespace: "garden",
},
}
isConfigMapConfigured := false
err := vp.Client().Get(ctx, client.ObjectKeyFromObject(cm), cm)
if err == nil {
url, ok := cm.Data["url"]
if ok {
seedApiURL = url
isConfigMapConfigured = true
}
}
if err != nil && !apierrors.IsNotFound(err) {
return nil, err
}

// We generally expect to get a DNS name for the seed api url.
// This is alway true for gardener managed clusters, because the mutating webhook
// of the api-server-proxy sets the KUBERNETES_SERVICE_HOST env variable.
// But for Managed Seeds where the control plane resides at GKE, this is always a IP
// in this case we set the seedAPI URL in a configmap.
if !isConfigMapConfigured {
u, err := url.Parse(seedApiURL)
if err != nil {
return nil, err
}

_, err = netip.ParseAddr(u.Hostname())
if err == nil {
// If hostname is a parsable ipaddress we error out because we need a dnsname.
panic(fmt.Sprintf("seedApiUrl:%q is not a dns entry, exiting", seedApiURL))
}
}

serverSecret, found := secretsReader.Get(metal.FirewallControllerManagerDeploymentName)
if !found {
return nil, fmt.Errorf("secret %q not found", metal.FirewallControllerManagerDeploymentName)
Expand Down

0 comments on commit 52bbb13

Please sign in to comment.