Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
fix: reconnect on reconcile to handle failures with envoy
Browse files Browse the repository at this point in the history
In early cluster stage, envoy doesn't yet work as expected and needs a new gRPC
connection once it does. This causes a problem with this controller as it caches
the (falsy) connection once a first one is established. To fix this, we create a
new connection every time the reconcile loop is run.
  • Loading branch information
nfnt committed Jan 2, 2023
1 parent 45e533d commit 73a21c4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions components/fl-operator/controllers/floperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type FlOperatorReconciler struct {
client.Client
Scheme *runtime.Scheme
EnvoyproxyConfigFile string
OrchestratorClient *orchestratorClient.Client
}

const (
Expand Down Expand Up @@ -107,26 +106,28 @@ func (r *FlOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

// Create gRPC client for connection to FL-Orchestrator
if r.OrchestratorClient == nil {
log.Info("Creating OrchestratorClient")
log.Info("Creating OrchestratorClient")

timeout := time.Second * 30 // TODO move this into the spec?
serverAddress := fmt.Sprintf("%s.%s:9080", serviceNameEnvoyProxy, req.Namespace)
dialOptions := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
conn, err := grpc.Dial(serverAddress, dialOptions...)
if err != nil {
log.Error(err, "Could not create gRPC connection")
return ctrl.Result{}, err
}

cl := orchestratorClient.NewClient(conn, timeout)
r.OrchestratorClient = &cl
timeout := time.Second * 30 // TODO move this into the spec?
serverAddress := fmt.Sprintf("%s.%s:9080", serviceNameEnvoyProxy, req.Namespace)
dialOptions := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
conn, err := grpc.Dial(serverAddress, dialOptions...)
if err != nil {
log.Error(err, "Could not create gRPC connection")
return ctrl.Result{}, err
}

// We can run into situations where we have a gRPC connection, but aren't
// yet able to use it because the envoy proxy isn't fully set up yet.
// As a result, we create a new connection on every call to 'Reconcile'.
// Some connections might fail but these failures won't affect later calls
// to 'Reconcile' as we're not caching failed connections.
cl := orchestratorClient.NewClient(conn, timeout)

// Fetch tasks from FL-Orchestrator
response, err := r.OrchestratorClient.GetTasks(ctx)
response, err := cl.GetTasks(ctx)
if err != nil {
log.Error(err, "Could not fetch tasks")
return ctrl.Result{
Expand Down

0 comments on commit 73a21c4

Please sign in to comment.