preset

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Settings{
	ConfigPath: "/etc/containerd/config.toml",
	Setup:      func(_ Env) error { return nil },
	Restarter:  containerd.NewDefaultRestarter(),
}
View Source
var K0s = Default.WithConfigPath("/etc/k0s/containerd.d/config.toml").
	WithRestarter(containerd.K0sRestarter{}).
	WithSetup(func(env Env) error {
		_, err := env.HostFs.Stat(env.ConfigPath)
		if err == nil {
			return nil
		}

		if errors.Is(err, os.ErrNotExist) {
			_, err := env.HostFs.Create(env.ConfigPath)
			if err != nil {
				return err
			}
			return nil
		}

		return err
	})
View Source
var K3s = RKE2.WithConfigPath("/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl").
	WithRestarter(containerd.K3sRestarter{})
View Source
var MicroK8s = Default.WithConfigPath("/var/snap/microk8s/current/args/containerd-template.toml").
	WithRestarter(containerd.MicroK8sRestarter{})
View Source
var RKE2 = Default.WithConfigPath("/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl").
	WithRestarter(containerd.RKE2Restarter{}).
	WithSetup(func(env Env) error {
		_, err := env.HostFs.Stat(env.ConfigPath)
		if err == nil {
			return nil
		}

		if errors.Is(err, os.ErrNotExist) {

			src, _ := strings.CutSuffix(env.ConfigPath, ".tmpl")
			in, err := env.HostFs.Open(src)
			if err != nil {
				return err
			}
			defer in.Close()
			out, err := env.HostFs.Create(env.ConfigPath)
			if err != nil {
				return err
			}
			defer func() {
				cerr := out.Close()
				if err == nil {
					err = cerr
				}
			}()
			if _, err = io.Copy(out, in); err != nil {
				return err
			}
			err = out.Sync()

			return nil
		}

		return err
	})

Functions

This section is empty.

Types

type Env

type Env struct {
	HostFs     afero.Fs
	ConfigPath string
}

type Settings

type Settings struct {
	ConfigPath string
	Setup      func(Env) error
	Restarter  containerd.Restarter
}

func (Settings) WithConfigPath

func (s Settings) WithConfigPath(path string) Settings

func (Settings) WithRestarter

func (s Settings) WithRestarter(restarter containerd.Restarter) Settings

func (Settings) WithSetup

func (s Settings) WithSetup(setup func(env Env) error) Settings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL