Delete Coordinator core and apis

This commit is contained in:
katexochen 2022-06-21 17:59:12 +02:00 committed by Paul Meyer
parent e534c6a338
commit 32f1f5fd3e
93 changed files with 1824 additions and 16487 deletions

View file

@ -9,7 +9,7 @@ import (
"net"
"testing"
"github.com/edgelesssys/constellation/coordinator/pubapi/pubproto"
"github.com/edgelesssys/constellation/coordinator/initproto"
"github.com/edgelesssys/constellation/internal/atls"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -39,7 +39,7 @@ func TestATLSCredentials(t *testing.T) {
for i := 0; i < serverCount; i++ {
api := &fakeAPI{}
server := grpc.NewServer(grpc.Creds(serverCreds))
pubproto.RegisterAPIServer(server, api)
initproto.RegisterAPIServer(server, api)
listener := bufconn.Listen(1024)
listeners = append(listeners, listener)
@ -66,8 +66,8 @@ func TestATLSCredentials(t *testing.T) {
require.NoError(err)
defer conn.Close()
client := pubproto.NewAPIClient(conn)
_, err = client.GetState(context.Background(), &pubproto.GetStateRequest{})
client := initproto.NewAPIClient(conn)
_, err = client.Init(context.Background(), &initproto.InitRequest{})
}()
}
@ -112,9 +112,9 @@ type fakeDoc struct {
}
type fakeAPI struct {
pubproto.UnimplementedAPIServer
initproto.UnimplementedAPIServer
}
func (f *fakeAPI) GetState(ctx context.Context, in *pubproto.GetStateRequest) (*pubproto.GetStateResponse, error) {
return &pubproto.GetStateResponse{State: 1}, nil
func (f *fakeAPI) Init(ctx context.Context, in *initproto.InitRequest) (*initproto.InitResponse, error) {
return &initproto.InitResponse{}, nil
}

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