Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ValyaB committed Sep 27, 2024
1 parent bf24e48 commit f1cc03f
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 155 deletions.
51 changes: 3 additions & 48 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import (
"runtime"
"time"

"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"cloud-proxy/internal/cloud/gcp"
"cloud-proxy/internal/cloud/gcp/gcpauth"
"cloud-proxy/internal/config"
"cloud-proxy/internal/healthz"
"cloud-proxy/internal/proxy"
"github.com/sirupsen/logrus"
)

var (
Expand All @@ -38,48 +33,8 @@ func main() {
logger.WithError(err).Panicf("Failed to create GCP credentials source")
}

dialOpts := make([]grpc.DialOption, 0)
if cfg.CastAI.DisableGRPCTLS {
// ONLY For testing purposes.
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(nil)))
}

connectParams := grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: 2 * time.Second,
Jitter: 0.1,
MaxDelay: 5 * time.Second,
Multiplier: 1.2,
},
MinConnectTimeout: 10 * time.Second,
}
dialOpts = append(dialOpts, grpc.WithConnectParams(connectParams), grpc.WithIdleTimeout(cfg.KeepAliveTimeout))

logger.Infof(
"Creating grpc channel against (%s) with connection config (%+v) and TLS enabled=%v",
cfg.CastAI.GrpcURL,
connectParams,
!cfg.CastAI.DisableGRPCTLS,
)
conn, err := grpc.NewClient(cfg.CastAI.GrpcURL, dialOpts...)
if err != nil {
logger.Panicf("Failed to connect to server: %v", err)
panic(err)
}

defer func(conn *grpc.ClientConn) {
logger.Info("Closing grpc connection")
err := conn.Close()
if err != nil {
logger.Panicf("Failed to close gRPC connection: %v", err)
panic(err)
}
}(conn)

client := proxy.New(conn, gcp.New(tokenSource), logger,
cfg.GetPodName(), cfg.ClusterID, GetVersion(), cfg.CastAI.APIKey, cfg.KeepAlive, cfg.KeepAliveTimeout)
client := proxy.New(gcp.New(tokenSource), logger,
GetVersion(), &cfg)

go startHealthServer(logger, cfg.HealthAddress)

Expand Down
Loading

0 comments on commit f1cc03f

Please sign in to comment.