mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-06 05:39:08 -04:00
Delete Coordinator core and apis
This commit is contained in:
parent
e534c6a338
commit
32f1f5fd3e
93 changed files with 1824 additions and 16487 deletions
63
internal/grpc/retry/retry.go
Normal file
63
internal/grpc/retry/retry.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package retry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/utils/clock"
|
||||
)
|
||||
|
||||
type IntervalRetryer struct {
|
||||
interval time.Duration
|
||||
doer Doer
|
||||
clock clock.WithTicker
|
||||
}
|
||||
|
||||
func NewIntervalRetryer(doer Doer, interval time.Duration) *IntervalRetryer {
|
||||
return &IntervalRetryer{
|
||||
interval: interval,
|
||||
doer: doer,
|
||||
clock: clock.RealClock{},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IntervalRetryer) Do(ctx context.Context) error {
|
||||
ticker := r.clock.NewTicker(r.interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
err := r.doer.Do(ctx)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !r.serviceIsUnavailable(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done(): // TODO(katexochen): is this necessary?
|
||||
return ctx.Err()
|
||||
case <-ticker.C():
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IntervalRetryer) serviceIsUnavailable(err error) bool {
|
||||
statusErr, ok := status.FromError(err)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if statusErr.Code() != codes.Unavailable {
|
||||
return false
|
||||
}
|
||||
// ideally we would check the error type directly, but grpc only provides a string
|
||||
return strings.HasPrefix(statusErr.Message(), `connection error: desc = "transport: authentication handshake failed`)
|
||||
}
|
||||
|
||||
type Doer interface {
|
||||
Do(ctx context.Context) error
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue