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:
Sekerin Evgeniy 2019-10-24 02:26:55 +05:00 committed by Andrew Rynhard
parent 457c6416a6
commit c6e1e6f28f

View File

@ -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
}