penguin/monok8s

k8s image for Mono Gateway Dev Kit

clitools/pkg/bootstrap/registry.go

raw ยท 2362 bytes

package bootstrap

import (
	"fmt"

	"undecided.project/monok8s/pkg/node"
)

type Registry struct {
	steps map[string]node.Step
}

func NewRegistry(ctx *node.NodeContext) *Registry {
	netCfg := node.NetworkConfig{
		Hostname:         ctx.Config.Spec.Network.Hostname,
		MgmtIface:        ctx.Config.Spec.Network.ManagementIface,
		MgmtAddress:      ctx.Config.Spec.Network.ManagementCIDR,
		MgmtGateway:      ctx.Config.Spec.Network.ManagementGW,
		DNSNameservers:   ctx.Config.Spec.Network.DNSNameservers,
		DNSSearchDomains: ctx.Config.Spec.Network.DNSSearchDomains,
	}

	return &Registry{
		steps: map[string]node.Step{
			"ApplyLocalNodeMetadataIfPossible":       node.ApplyLocalNodeMetadataIfPossible,
			"CheckForVersionSkew":                    node.CheckForVersionSkew,
			"ClassifyBootstrapAction":                node.ClassifyBootstrapAction,
			"ConfigureDNS":                           node.ConfigureDNS(netCfg),
			"ConfigureDefaultCNI":                    node.ConfigureDefaultCNI,
			"ConfigureHostname":                      node.ConfigureHostname(netCfg),
			"ConfigureMgmtInterface":                 node.ConfigureMgmtInterface(netCfg),
			"DetectLocalClusterState":                node.DetectLocalClusterState,
			"EnsureIPForward":                        node.EnsureIPForward,
			"ReconcileControlPlane":                  node.ReconcileControlPlane,
			"ReconcileWorker":                        node.ReconcileWorker,
			"RunKubeadmInit":                         node.RunKubeadmInit,
			"RunKubeadmJoin":                         node.RunKubeadmJoin,
			"RunKubeadmUpgradeApply":                 node.RunKubeadmUpgradeApply,
			"RunKubeadmUpgradeNode":                  node.RunKubeadmUpgradeNode,
			"StartCRIO":                              node.StartCRIO,
			"ValidateNodeIPAndAPIServerReachability": node.ValidateNodeIPAndAPIServerReachability,
			"ValidateRequiredImagesPresent":          node.ValidateRequiredImagesPresent,
			"WaitForExistingClusterIfNeeded":         node.WaitForExistingClusterIfNeeded,
		},
	}
}

func (r *Registry) MustGet(name string) node.Step {
	step, ok := r.steps[name]
	if !ok {
		panic(fmt.Sprintf("unknown step %q", name))
	}
	return step
}

func (r *Registry) Get(name string) (node.Step, error) {
	step, ok := r.steps[name]
	if !ok {
		return nil, fmt.Errorf("unknown step %q", name)
	}
	return step, nil
}