From ea66fe65b4c805d4b28a5d2e73cc33c4cd44f45a Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Fri, 8 Dec 2023 00:13:53 +0000 Subject: [PATCH] Propagate errors up from config.Get Fixes crash when killing agent while waiting for config from server Signed-off-by: Brad Davidson (cherry picked from commit 77846d63c199da46a5352715c8136b47ca043bd2) Signed-off-by: Brad Davidson --- pkg/agent/config/config.go | 6 +++--- pkg/agent/run.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index b4c38417d9..c37c25e49d 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -48,8 +48,8 @@ const ( // so this is somewhat computationally expensive on the server side, and is retried with jitter // to avoid having clients hammer on the server at fixed periods. // A call to this will bock until agent configuration is successfully returned by the -// server. -func Get(ctx context.Context, agent cmds.Agent, proxy proxy.Proxy) *config.Node { +// server, or the context is cancelled. +func Get(ctx context.Context, agent cmds.Agent, proxy proxy.Proxy) (*config.Node, error) { var agentConfig *config.Node var err error @@ -65,7 +65,7 @@ func Get(ctx context.Context, agent cmds.Agent, proxy proxy.Proxy) *config.Node cancel() } }, 5*time.Second, 1.0, true) - return agentConfig + return agentConfig, err } // KubeProxyDisabled returns a bool indicating whether or not kube-proxy has been disabled in the diff --git a/pkg/agent/run.go b/pkg/agent/run.go index 242d201899..a050cc3031 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -52,7 +52,10 @@ import ( ) func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { - nodeConfig := config.Get(ctx, cfg, proxy) + nodeConfig, err := config.Get(ctx, cfg, proxy) + if err != nil { + return errors.Wrap(err, "failed to retrieve agent configuration") + } dualCluster, err := utilsnet.IsDualStackCIDRs(nodeConfig.AgentConfig.ClusterCIDRs) if err != nil { @@ -234,7 +237,11 @@ func RunStandalone(ctx context.Context, cfg cmds.Agent) error { return err } - nodeConfig := config.Get(ctx, cfg, proxy) + nodeConfig, err := config.Get(ctx, cfg, proxy) + if err != nil { + return errors.Wrap(err, "failed to retrieve agent configuration") + } + if err := executor.Bootstrap(ctx, nodeConfig, cfg); err != nil { return err }