mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-12 16:11:10 +02:00
feat: Add retry on get kubeconfig
This implement retry when get kubeconfig Signed-off-by: Sekerin Evgeniy <sekerin.e.a@gmail.com>
This commit is contained in:
parent
457c6416a6
commit
c6e1e6f28f
@ -15,6 +15,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
criconstants "github.com/containerd/cri/pkg/constants"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
@ -29,6 +30,7 @@ import (
|
||||
"github.com/talos-systems/talos/pkg/chunker"
|
||||
filechunker "github.com/talos-systems/talos/pkg/chunker/file"
|
||||
"github.com/talos-systems/talos/pkg/constants"
|
||||
"github.com/talos-systems/talos/pkg/retry"
|
||||
)
|
||||
|
||||
// Registrator is the concrete type that implements the factory.Registrator and
|
||||
@ -42,7 +44,21 @@ func (r *Registrator) Register(s *grpc.Server) {
|
||||
|
||||
// Kubeconfig implements the osapi.OSDServer interface.
|
||||
func (r *Registrator) Kubeconfig(ctx context.Context, in *empty.Empty) (data *osapi.DataReply, err error) {
|
||||
fileBytes, err := ioutil.ReadFile(constants.AdminKubeconfig)
|
||||
var fileBytes []byte
|
||||
|
||||
err = retry.Constant(5*time.Minute, retry.WithUnits(5*time.Second)).Retry(func() error {
|
||||
fileBytes, err = ioutil.ReadFile(constants.AdminKubeconfig)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return retry.ExpectedError(err)
|
||||
}
|
||||
|
||||
return retry.UnexpectedError(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user