Skip to content

Commit

Permalink
Clean up kube-proxy 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 14, 2024
1 parent 109f70b commit a1fbc66
Showing 1 changed file with 7 additions and 21 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 @@ -660,21 +661,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

0 comments on commit a1fbc66

Please sign in to comment.