Restore original order of agent startup functions

Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
Derek Nola 2024-02-21 10:22:03 -08:00
parent 1c1746114c
commit 91cc2feed2
2 changed files with 19 additions and 28 deletions

View File

@ -13,6 +13,7 @@ import (
systemd "github.com/coreos/go-systemd/daemon" systemd "github.com/coreos/go-systemd/daemon"
"github.com/k3s-io/k3s/pkg/agent/config" "github.com/k3s-io/k3s/pkg/agent/config"
"github.com/k3s-io/k3s/pkg/agent/containerd"
"github.com/k3s-io/k3s/pkg/agent/flannel" "github.com/k3s-io/k3s/pkg/agent/flannel"
"github.com/k3s-io/k3s/pkg/agent/netpol" "github.com/k3s-io/k3s/pkg/agent/netpol"
"github.com/k3s-io/k3s/pkg/agent/proxy" "github.com/k3s-io/k3s/pkg/agent/proxy"
@ -130,13 +131,18 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
} }
} }
notifySocket := os.Getenv("NOTIFY_SOCKET") if nodeConfig.Docker {
os.Unsetenv("NOTIFY_SOCKET") if err := executor.Docker(ctx, nodeConfig); err != nil {
if err := setupTunnelAndRunAgent(ctx, nodeConfig, cfg, proxy); err != nil {
return err return err
} }
} else if nodeConfig.ContainerRuntimeEndpoint == "" {
if err := containerd.SetupContainerdConfig(nodeConfig); err != nil {
return err
}
if err := executor.Containerd(ctx, nodeConfig); err != nil {
return err
}
}
// the agent runtime is ready to host workloads when containerd is up and the airgap // the agent runtime is ready to host workloads when containerd is up and the airgap
// images have finished loading, as that portion of startup may block for an arbitrary // images have finished loading, as that portion of startup may block for an arbitrary
// amount of time depending on how long it takes to import whatever the user has placed // amount of time depending on how long it takes to import whatever the user has placed
@ -145,6 +151,13 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
close(cfg.AgentReady) close(cfg.AgentReady)
} }
notifySocket := os.Getenv("NOTIFY_SOCKET")
os.Unsetenv("NOTIFY_SOCKET")
if err := setupTunnelAndRunAgent(ctx, nodeConfig, cfg, proxy); err != nil {
return err
}
if err := util.WaitForAPIServerReady(ctx, nodeConfig.AgentConfig.KubeConfigKubelet, util.DefaultAPIServerReadyTimeout); err != nil { if err := util.WaitForAPIServerReady(ctx, nodeConfig.AgentConfig.KubeConfigKubelet, util.DefaultAPIServerReadyTimeout); err != nil {
return errors.Wrap(err, "failed to wait for apiserver ready") return errors.Wrap(err, "failed to wait for apiserver ready")
} }

View File

@ -7,7 +7,6 @@ import (
"time" "time"
"github.com/k3s-io/k3s/pkg/agent/config" "github.com/k3s-io/k3s/pkg/agent/config"
"github.com/k3s-io/k3s/pkg/agent/containerd"
"github.com/k3s-io/k3s/pkg/agent/proxy" "github.com/k3s-io/k3s/pkg/agent/proxy"
daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config" daemonconfig "github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/k3s-io/k3s/pkg/daemons/executor" "github.com/k3s-io/k3s/pkg/daemons/executor"
@ -24,16 +23,6 @@ func Agent(ctx context.Context, nodeConfig *daemonconfig.Node, proxy proxy.Proxy
logs.InitLogs() logs.InitLogs()
defer logs.FlushLogs() defer logs.FlushLogs()
if nodeConfig.Docker {
if err := startDocker(ctx, nodeConfig); err != nil {
return err
}
} else if nodeConfig.ContainerRuntimeEndpoint == "" {
if err := startContainerd(ctx, nodeConfig); err != nil {
return err
}
}
if err := startKubelet(ctx, &nodeConfig.AgentConfig); err != nil { if err := startKubelet(ctx, &nodeConfig.AgentConfig); err != nil {
return err return err
} }
@ -65,17 +54,6 @@ func startKubelet(ctx context.Context, cfg *daemonconfig.Agent) error {
return executor.Kubelet(ctx, args) return executor.Kubelet(ctx, args)
} }
func startContainerd(ctx context.Context, cfg *daemonconfig.Node) error {
if err := containerd.SetupContainerdConfig(cfg); err != nil {
return err
}
return executor.Containerd(ctx, cfg)
}
func startDocker(ctx context.Context, cfg *daemonconfig.Node) error {
return executor.Docker(ctx, cfg)
}
// ImageCredProvAvailable checks to see if the kubelet image credential provider bin dir and config // ImageCredProvAvailable checks to see if the kubelet image credential provider bin dir and config
// files exist and are of the correct types. This is exported so that it may be used by downstream projects. // files exist and are of the correct types. This is exported so that it may be used by downstream projects.
func ImageCredProvAvailable(cfg *daemonconfig.Agent) bool { func ImageCredProvAvailable(cfg *daemonconfig.Agent) bool {