-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refresh control plane endpoints on worker apids on schedule
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>
- Loading branch information
Showing
5 changed files
with
184 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.