Skip to content

Commit

Permalink
Remove kube-proxy static pod manifest during agent bootstrap
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Mar 22, 2024
1 parent 9c10458 commit 6566d01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
28 changes: 7 additions & 21 deletions pkg/podexecutor/staticpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ type StaticPodConfig struct {
PSAConfigFile string
KubeletPath string
RuntimeEndpoint string
KubeProxyChan chan struct{}
CISMode bool
DisableETCD bool
IsServer bool
Expand Down Expand Up @@ -161,6 +160,13 @@ func (s *StaticPodConfig) Bootstrap(_ context.Context, nodeConfig *daemonconfig.
if s.IsServer {
return bootstrap.UpdateManifests(s.Resolver, nodeConfig, cfg)
}

// Remove the kube-proxy static pod manifest before starting the agent.
// If kube-proxy should run, the manifest will be recreated after the apiserver is up.
if err := staticpod.Remove(s.ManifestsDir, "kube-proxy"); err != nil {
logrus.Error(err)
}

return nil
}

Expand Down Expand Up @@ -197,16 +203,11 @@ func (s *StaticPodConfig) Kubelet(ctx context.Context, args []string) error {
})
}()

go s.cleanupKubeProxy()

return nil
}

// KubeProxy starts Kube Proxy as a static pod.
func (s *StaticPodConfig) KubeProxy(_ context.Context, args []string) error {
// close the channel so that the cleanup goroutine does not remove the pod manifest
close(s.KubeProxyChan)

image, err := s.Resolver.GetReference(images.KubeProxy)
if err != nil {
return err
Expand Down Expand Up @@ -664,21 +665,6 @@ func (s *StaticPodConfig) stopEtcd() error {
return nil
}

// cleanupKubeProxy waits to see if kube-proxy is run. If kube-proxy does not run and
// close the channel within one minute of this goroutine being started by the kubelet
// runner, then the kube-proxy static pod manifest is removed from disk. The kubelet will
// clean up the static pod soon after.
func (s *StaticPodConfig) cleanupKubeProxy() {
select {
case <-s.KubeProxyChan:
return
case <-time.After(time.Minute * 1):
if err := staticpod.Remove(s.ManifestsDir, "kube-proxy"); err != nil {
logrus.Error(err)
}
}
}

// chownr recursively changes the ownership of the given
// path to the given user ID and group ID.
func chownr(path string, uid, gid int) error {
Expand Down
1 change: 0 additions & 1 deletion pkg/rke2/rke2_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func initExecutor(clx *cli.Context, cfg Config, isServer bool) (*podexecutor.Sta
PSAConfigFile: podSecurityConfigFile,
KubeletPath: cfg.KubeletPath,
RuntimeEndpoint: containerRuntimeEndpoint,
KubeProxyChan: make(chan struct{}),
DisableETCD: clx.Bool("disable-etcd"),
IsServer: isServer,
ControlPlaneResources: *controlPlaneResources,
Expand Down

0 comments on commit 6566d01

Please sign in to comment.