Skip to content

Commit

Permalink
Move the containers cleanup step creation into its own func
Browse files Browse the repository at this point in the history
Makes the code a bit clearer.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Nov 19, 2024
1 parent 298f6cd commit f22d164
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pkg/cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,13 @@ func NewConfig(debug bool, k0sVars *config.CfgVars, criSocketFlag string) (*Conf
logrus.Errorf("failed to get cluster setup: %v", err)
}

runtimeEndpoint, err := worker.GetContainerRuntimeEndpoint(criSocketFlag, k0sVars.RunDir)
containers, err := newContainersStep(debug, k0sVars, criSocketFlag)
if err != nil {
return nil, err
}

containerRuntime := runtime.NewContainerRuntime(runtimeEndpoint)
var managedContainerd *containerd.Component
if criSocketFlag == "" {
logLevel := "error"
if debug {
logLevel = "debug"
}
managedContainerd = containerd.NewComponent(logLevel, k0sVars, &workerconfig.Profile{
PauseImage: &k0sv1beta1.ImageSpec{
Image: constant.KubePauseContainerImage,
Version: constant.KubePauseContainerImageVersion,
},
})
}

cleanupSteps := []Step{
&containers{
managedContainerd: managedContainerd,
containerRuntime: containerRuntime,
},
containers,
&users{
systemUsers: cfg.Spec.Install.SystemUsers,
},
Expand Down Expand Up @@ -101,6 +83,32 @@ func (c *Config) Cleanup() error {
return nil
}

func newContainersStep(debug bool, k0sVars *config.CfgVars, criSocketFlag string) (*containers, error) {
runtimeEndpoint, err := worker.GetContainerRuntimeEndpoint(criSocketFlag, k0sVars.RunDir)
if err != nil {
return nil, err
}

containers := containers{
containerRuntime: runtime.NewContainerRuntime(runtimeEndpoint),
}

if criSocketFlag == "" {
logLevel := "error"
if debug {
logLevel = "debug"
}
containers.managedContainerd = containerd.NewComponent(logLevel, k0sVars, &workerconfig.Profile{
PauseImage: &k0sv1beta1.ImageSpec{
Image: constant.KubePauseContainerImage,
Version: constant.KubePauseContainerImageVersion,
},
})
}

return &containers, nil
}

// Step interface is used to implement cleanup steps
type Step interface {
// Run impelements specific cleanup operations
Expand Down

0 comments on commit f22d164

Please sign in to comment.