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

Fix/trigger update on apiserver address change #45

Merged
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
23 changes: 20 additions & 3 deletions pkg/controller/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func (w *watch) Start(ctx context.Context) error {
}

var last time.Time
var shootInfo *corev1.ConfigMap
var apiServer *config.Endpoint
for {
select {
case <-ctx.Done():
Expand All @@ -188,7 +190,7 @@ func (w *watch) Start(ctx context.Context) error {
last = now
}

if !controller.HasUpdates() {
if !controller.HasUpdates() && !w.apiServerAddressChanged(shootInfo, apiServer) {
w.lastLoop.Store(last.UnixMilli())
continue
}
Expand All @@ -213,9 +215,8 @@ func (w *watch) Start(ctx context.Context) error {
IP: svc.Spec.ClusterIP,
Port: int(svc.Spec.Ports[0].Port),
}
var apiServer *config.Endpoint
configmaps := w.clientSet.CoreV1().ConfigMaps(common.NamespaceKubeSystem)
shootInfo, err := configmaps.Get(ctx, common.NameGardenerShootInfo, metav1.GetOptions{})
shootInfo, err = configmaps.Get(ctx, common.NameGardenerShootInfo, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
w.log.Errorf("loading configmap %s/%s failed: %s", common.NamespaceKubeSystem, common.NameGardenerShootInfo, err)
Expand All @@ -242,6 +243,10 @@ func (w *watch) Start(ctx context.Context) error {
continue
}
cfg, err = deploy.BuildClusterConfig(nodes, pods, internalApiServer, apiServer)
if err != nil {
w.log.Errorf("building cluster config failed: %w", err)
continue
}
cfgBytes, err := yaml.Marshal(cfg)
if err != nil {
w.log.Errorf("marshal configmap %s/%s failed: %s", common.NamespaceKubeSystem, common.NameClusterConfigMap, err)
Expand All @@ -262,3 +267,15 @@ func (w *watch) Start(ctx context.Context) error {
}
}
}

func (w *watch) apiServerAddressChanged(shootInfo *corev1.ConfigMap, apiServer *config.Endpoint) bool {
if shootInfo == nil {
return true
}
newApiServer, err := deploy.GetAPIServerEndpointFromShootInfo(shootInfo)
if err != nil {
w.log.Errorf("failed to determine apiserver endpoint from shoot info: %w", err)
return true
}
return *newApiServer != *apiServer
}