mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-20 05:11:15 +02:00
This moves endpoint refresh from the context of the service `apid` in `machined` into `apid` service itself for the workers. `apid` does initial poll for the endpoints when it boots, but also periodically polls for new endpoints to make sure it has accurate list of `trustd` endpoints to talk to, this handles cases when control plane endpoints change (e.g. rolling replace of control plane nodes with new IPs). Related to #3069 Fixes #3068 Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package provider
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/talos-systems/go-retry/retry"
|
|
|
|
"github.com/talos-systems/talos/pkg/kubernetes"
|
|
)
|
|
|
|
// Endpoints interfaces describes a control plane endpoints provider.
|
|
type Endpoints interface {
|
|
GetEndpoints() (endpoints []string, err error)
|
|
}
|
|
|
|
// StaticEndpoints provides static list of endpoints.
|
|
type StaticEndpoints struct {
|
|
Endpoints []string
|
|
}
|
|
|
|
// GetEndpoints implements Endpoints inteface.
|
|
func (e *StaticEndpoints) GetEndpoints() (endpoints []string, err error) {
|
|
return e.Endpoints, nil
|
|
}
|
|
|
|
// KubernetesEndpoints provides dynamic list of control plane endpoints via Kubernetes Endpoints resource.
|
|
type KubernetesEndpoints struct{}
|
|
|
|
// GetEndpoints implements Endpoints inteface.
|
|
func (e *KubernetesEndpoints) GetEndpoints() (endpoints []string, err error) {
|
|
err = retry.Constant(8*time.Minute, retry.WithUnits(3*time.Second), retry.WithJitter(time.Second), retry.WithErrorLogging(true)).Retry(func() error {
|
|
ctx, ctxCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer ctxCancel()
|
|
|
|
var client *kubernetes.Client
|
|
|
|
client, err = kubernetes.NewClientFromKubeletKubeconfig()
|
|
if err != nil {
|
|
return retry.ExpectedError(fmt.Errorf("failed to create client: %w", err))
|
|
}
|
|
|
|
endpoints, err = client.MasterIPs(ctx)
|
|
if err != nil {
|
|
return retry.ExpectedError(err)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
return endpoints, err
|
|
}
|