Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn-hurley committed Apr 23, 2024
1 parent 085ead0 commit 3890234
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions provider/grpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log"
"os/exec"
"time"

"github.com/go-logr/logr"
reflectClient "github.com/jhump/protoreflect/grpcreflect"
Expand Down Expand Up @@ -41,12 +42,9 @@ func NewGRPCClient(config provider.Config, log logr.Logger) (provider.InternalPr
}
refCltCtx, cancel := context.WithCancel(context.Background())
refClt := reflectClient.NewClientAuto(refCltCtx, conn)
defer cancel()

// TODO: reasonable retry here
services, err := refClt.ListServices()
if err != nil {
return nil, err
}
services, err := checkServicesRunning(refClt, log)
foundCodeSnip := false
foundDepResolve := false
for _, s := range services {
Expand All @@ -58,8 +56,6 @@ func NewGRPCClient(config provider.Config, log logr.Logger) (provider.InternalPr
foundDepResolve = true
}
}
// Close the reflection service connection
cancel()
// Always need these
provierClient := pb.NewProviderServiceClient(conn)
gp := grpcProvider{
Expand Down Expand Up @@ -132,6 +128,25 @@ func NewGRPCClient(config provider.Config, log logr.Logger) (provider.InternalPr
// }
}

func checkServicesRunning(refClt *reflectClient.Client, log logr.Logger) ([]string, error) {
for {
select {
default:
services, err := refClt.ListServices()
if err == nil && len(services) != 0 {
log.Info("no services found")
return services, nil
}
if err != nil {
log.Info("error for list services: ", "error", err)
}
time.Sleep(3 * time.Second)
case <-time.After(time.Second * 30):
return nil, fmt.Errorf("no services found")
}
}
}

func (g *grpcProvider) ProviderInit(ctx context.Context) error {
for _, c := range g.config.InitConfig {
s, err := g.Init(ctx, g.log, c)
Expand Down

0 comments on commit 3890234

Please sign in to comment.