func (s containersState) CreateAndStart(containerName string) error {
	if _, exists := s[containerName]; !exists {
		return fmt.Errorf("can't create non-existing container")
	}
	if err := s[containerName].Create(); err != nil {
		return fmt.Errorf("creating new container: %w", err)
	}
	if err := s[containerName].Start(); err != nil {
		return fmt.Errorf("starting container: %w", err)
	}
	return nil
}
CreateAndStart is a helper, which creates and spawns given container.
package container
import (
	"fmt"
	"github.com/flexkube/libflexkube/pkg/container/runtime/docker"
	"github.com/flexkube/libflexkube/pkg/container/types"
)
const (
	StatusMissing = "gone"
)
type ContainersStateInterface interface {
	CheckState() error
	RemoveContainer(containerName string) error
	CreateAndStart(containerName string) error
	Export() ContainersState
}
type ContainersState map[string]*HostConfiguredContainer
type containersState map[string]*hostConfiguredContainer
func (s ContainersState) New() (ContainersStateInterface, error) {
	if s == nil {
		s = ContainersState{}
	}
	state := containersState{}
	for name, container := range s {
		m, err := container.New()
		if err != nil {
			return nil, fmt.Errorf("creating new container object: %w", err)
		}
		hcc, ok := m.(*hostConfiguredContainer)
		if !ok {
			return nil, fmt.Errorf("converting container to internal version")
		}
		state[name] = hcc
	}
	return state, nil
}
func (s containersState) CheckState() error {
	for i, hcc := range s {
		if err := hcc.Status(); err != nil {
			hcc.container.SetStatus(types.ContainerStatus{
				Status: err.Error(),
			})
			continue
		}
		if !hcc.container.Status().Exists() {
			hcc.container.SetStatus(types.ContainerStatus{
				Status: StatusMissing,
			})
		}
		if err := hcc.ConfigurationStatus(); err != nil {
			return fmt.Errorf("checking container %q configuration status: %w", i, err)
		}
	}
	return nil
}
func (s containersState) RemoveContainer(containerName string) error {
	if _, exists := s[containerName]; !exists {
		return fmt.Errorf("can't remove non-existing container")
	}
	status := s[containerName].container.Status()
	if status.Exists() && (status.Running() || status.Restarting()) {
		if err := s[containerName].Stop(); err != nil {
			return fmt.Errorf("stopping container before removing: %w", err)
		}
	}
	if status.Exists() {
		if err := s[containerName].Delete(); err != nil {
			return fmt.Errorf("removing container: %w", err)
		}
	}
	delete(s, containerName)
	return nil
}