Propagate errors up from config.Get

Fixes crash when killing agent while waiting for config from server

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
Brad Davidson 2023-12-08 00:13:53 +00:00 committed by Brad Davidson
parent 16d29398ad
commit 77846d63c1
2 changed files with 12 additions and 5 deletions

View File

@ -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

View File

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