dev

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 38 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	WaiterDefaultTimeout  = 60 * time.Second
	WaiterDefaultInterval = time.Second
)

Variables

View Source
var DefaultNewCtrlClientFunc = client.New

Functions

func BuildImage added in v0.6.0

func BuildImage(buildInfo *ImageBuildInfo, deps []interface{}) error

BuildImage is a generic image build function, requires the binaries to be built beforehand

func BuildPackage added in v0.6.0

func BuildPackage(buildInfo *PackageBuildInfo, deps []interface{}) error

BuildPackage builds a package image using the package operator CLI, requires `kubectl-package` command to be available on the system

func DefaultNewRestConfig added in v0.2.2

func DefaultNewRestConfig(kubeconfig string) (*rest.Config, error)

func LoadKubernetesObjectsFromBytes

func LoadKubernetesObjectsFromBytes(fileYaml []byte) ([]unstructured.Unstructured, error)

Loads kubernetes objects from given bytes. A single file may contain multiple objects separated by "---\n".

func LoadKubernetesObjectsFromFile

func LoadKubernetesObjectsFromFile(filePath string) ([]unstructured.Unstructured, error)

Loads kubernetes objects from the given file.

func LoadKubernetesObjectsFromFolder

func LoadKubernetesObjectsFromFolder(folderPath string) ([]unstructured.Unstructured, error)

Loads kubernets objects from all .yaml files in the given folder. Does not recurse into subfolders. Preserves lexical file order.

func PushImage added in v0.6.0

func PushImage(pushInfo *ImagePushInfo, buildImageDep mg.Fn) error

PushImage pushes only the given container image to the default registry.

Types

type Cluster

type Cluster struct {
	Scheme     *runtime.Scheme
	RestConfig *rest.Config
	CtrlClient client.Client
	Waiter     *Waiter
	Helm       *Helm
	// contains filtered or unexported fields
}

Container object to hold kubernetes client interfaces and configuration.

func NewCluster

func NewCluster(workDir string, opts ...ClusterOption) (*Cluster, error)

Creates a new Cluster object to interact with a Kubernetes cluster.

func (*Cluster) CreateAndWaitForReadiness

func (c *Cluster) CreateAndWaitForReadiness(
	ctx context.Context, object client.Object,
	opts ...WaitOption,
) error

Creates the given objects and waits for them to be considered ready.

func (*Cluster) CreateAndWaitFromFiles

func (c *Cluster) CreateAndWaitFromFiles(
	ctx context.Context, files []string,
	opts ...WaitOption,
) error

Load kube objects from a list of files, create these objects and wait for them to be ready.

func (*Cluster) CreateAndWaitFromFolders

func (c *Cluster) CreateAndWaitFromFolders(
	ctx context.Context, folders []string,
	opts ...WaitOption,
) error

Load kube objects from a list of folders, create these objects and wait for them to be ready.

func (*Cluster) CreateAndWaitFromHttp

func (c *Cluster) CreateAndWaitFromHttp(
	ctx context.Context, urls []string,
	opts ...WaitOption,
) error

Load kube objects from a list of http urls, create these objects and wait for them to be ready.

func (*Cluster) Kubeconfig

func (c *Cluster) Kubeconfig() string

Returns the path to the kubeconfig of the cluster.

type ClusterConfig

type ClusterConfig struct {
	SchemeBuilder runtime.SchemeBuilder
	NewWaiter     NewWaiterFunc
	WaitOptions   []WaitOption
	NewHelm       NewHelmFunc
	HelmOptions   []HelmOption
	NewRestConfig NewRestConfigFunc
	NewCtrlClient NewCtrlClientFunc

	WorkDir string
	// Path to the kubeconfig of the cluster
	Kubeconfig string
}

func (*ClusterConfig) Default

func (c *ClusterConfig) Default()

type ClusterHelmInstall

type ClusterHelmInstall struct {
	RepoName, RepoURL, PackageName, Namespace, ReleaseName string
	SetVars                                                []string
}

Adds the helm repository, updates repository cache and installs a helm package.

func (ClusterHelmInstall) Init

func (h ClusterHelmInstall) Init(
	ctx context.Context, cluster *Cluster) error

type ClusterInitializer

type ClusterInitializer interface {
	Init(ctx context.Context, cluster *Cluster) error
}

type ClusterLoadObjectFromClientObject added in v0.5.0

type ClusterLoadObjectFromClientObject struct {
	client.Object
}

Creates the referenced Object and waits for it to be ready.

func (ClusterLoadObjectFromClientObject) Init added in v0.5.0

type ClusterLoadObjectsFromFiles

type ClusterLoadObjectsFromFiles []string

Load objects from given file paths and applies them into the cluster.

func (ClusterLoadObjectsFromFiles) Init

func (l ClusterLoadObjectsFromFiles) Init(
	ctx context.Context, cluster *Cluster) error

type ClusterLoadObjectsFromFolders

type ClusterLoadObjectsFromFolders []string

Load objects from given folder paths and applies them into the cluster.

func (ClusterLoadObjectsFromFolders) Init

type ClusterLoadObjectsFromHttp

type ClusterLoadObjectsFromHttp []string

Load objects from the given http urls and applies them into the cluster.

func (ClusterLoadObjectsFromHttp) Init

func (l ClusterLoadObjectsFromHttp) Init(
	ctx context.Context, cluster *Cluster) error

type ClusterOption

type ClusterOption interface {
	ApplyToClusterConfig(c *ClusterConfig)
}

type ContainerRuntime

type ContainerRuntime string
const (
	ContainerRuntimePodman ContainerRuntime = "podman"
	ContainerRuntimeDocker ContainerRuntime = "docker"
	ContainerRuntimeAuto   ContainerRuntime = "auto" // auto detect
)

func DetectContainerRuntime added in v0.3.0

func DetectContainerRuntime() (ContainerRuntime, error)

type Environment

type Environment struct {
	Name string
	// Working directory of the environment.
	// Temporary files/kubeconfig etc. will be stored here.
	WorkDir string
	Cluster *Cluster
	// contains filtered or unexported fields
}

Environment represents a development environment.

Example
log := logr.Discard()

env := NewEnvironment(
	"cheese", ".cache/dev-env/cheese",
	WithContainerRuntime(ContainerRuntimePodman),
	WithClusterInitializers{
		ClusterLoadObjectsFromFiles{
			"config/crd01.yaml",
			"config/crd02.yaml",
			"config/deploy.yaml",
		},
		ClusterLoadObjectsFromFolders{
			"config/logging-stack",
		},
		ClusterLoadObjectsFromHttp{
			// Install OLM.
			"https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v" + olmVersion + "/crds.yaml",
			"https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v" + olmVersion + "/olm.yaml",
		},
		ClusterHelmInstall{
			RepoName:    "prometheus-community",
			RepoURL:     "https://prometheus-community.github.io/helm-charts",
			PackageName: "kube-prometheus-stack",
			ReleaseName: "prometheus",
			Namespace:   "monitoring",
			SetVars: []string{
				"grafana.enabled=false",
				"kubeStateMetrics.enabled=false",
				"nodeExporter.enabled=false",
			},
		},
	},
)
ctx := logr.NewContext(context.Background(), log)
if err := env.Init(ctx); err != nil {
	// handle error
}
Output:

func NewEnvironment

func NewEnvironment(name, workDir string, opts ...EnvironmentOption) *Environment

Creates a new development environment.

func (*Environment) Destroy

func (env *Environment) Destroy(ctx context.Context) error

Destroy/Teardown the development environment.

func (*Environment) Init

func (env *Environment) Init(ctx context.Context) error

Initializes the environment and prepares it for use.

func (*Environment) LoadImageFromTar

func (env *Environment) LoadImageFromTar(filePath string) error

Load an image from a tar archive into the environment.

func (*Environment) RunKindCommand added in v0.4.0

func (env *Environment) RunKindCommand(ctx context.Context, stdout, stderr io.Writer, args ...string) error

type EnvironmentConfig

type EnvironmentConfig struct {
	// Cluster initializers prepare a cluster for use.
	ClusterInitializers []ClusterInitializer
	// Container runtime to use
	ContainerRuntime  ContainerRuntime
	NewCluster        NewClusterFunc
	ClusterOptions    []ClusterOption
	KindClusterConfig *kindv1alpha4.Cluster
}

func (*EnvironmentConfig) Default

func (c *EnvironmentConfig) Default()

Apply default configuration.

type EnvironmentOption

type EnvironmentOption interface {
	ApplyToEnvironmentConfig(c *EnvironmentConfig)
}

type Helm

type Helm struct {
	HelmConfig
}

func NewHelm

func NewHelm(workDir, kubeconfig string, opts ...HelmOption) *Helm

func (*Helm) HelmInstall

func (h *Helm) HelmInstall(
	ctx context.Context, cluster *Cluster,
	repoName, packageName, releaseName, namespace string,
	setVars []string,
) error

Wrapper arround "helm install"

func (*Helm) HelmRepoAdd

func (h *Helm) HelmRepoAdd(
	ctx context.Context, repoName, repoURL string,
) error

Wrapper arround "helm repo add"

func (*Helm) HelmRepoUpdate

func (h *Helm) HelmRepoUpdate(ctx context.Context) error

Wrapper arround "helm repo update"

type HelmConfig

type HelmConfig struct {
	WorkDir        string
	Kubeconfig     string
	Stdout, Stderr io.Writer
}

func (*HelmConfig) Default

func (c *HelmConfig) Default()

type HelmOption

type HelmOption interface {
	ApplyToHelmConfig(c *HelmConfig)
}

type ImageBuildInfo added in v0.6.0

type ImageBuildInfo struct {
	ImageTag      string
	CacheDir      string
	ContainerFile string
	ContextDir    string
	Runtime       string
}

type ImagePushInfo added in v0.6.0

type ImagePushInfo struct {
	ImageTag   string
	CacheDir   string
	Runtime    string
	DigestFile string
}

type NewClusterFunc

type NewClusterFunc func(kubeconfigPath string, opts ...ClusterOption) (*Cluster, error)

type NewCtrlClientFunc added in v0.2.2

type NewCtrlClientFunc func(c *rest.Config, opts client.Options) (client.Client, error)

type NewHelmFunc

type NewHelmFunc func(
	workDir, kubeconfig string,
	opts ...HelmOption,
) *Helm

type NewRestConfigFunc added in v0.2.2

type NewRestConfigFunc func(kubeconfig string) (*rest.Config, error)

type NewWaiterFunc

type NewWaiterFunc func(
	client client.Client, scheme *runtime.Scheme,
	defaultOpts ...WaitOption,
) *Waiter

type PackageBuildInfo added in v0.6.0

type PackageBuildInfo struct {
	ImageTag string
	CacheDir string
	// source directory
	SourcePath string
	// destination: .tar file path
	OutputPath string
	Runtime    string
	// will default to "kubectl-package"
	ExecutablePath string
	// if set to `true`, built package won't be loaded into the runtime
	NoRunTimeLoad bool
	// package will be pushed directly using the PKO CLI and not the runtime
	Push bool
}

type UnknownTypeError

type UnknownTypeError struct {
	GK schema.GroupKind
}

UnknownTypeError is returned when the given GroupKind is not registered.

func (*UnknownTypeError) Error

func (e *UnknownTypeError) Error() string

type WaitOption

type WaitOption interface {
	ApplyToWaiterConfig(c *WaiterConfig)
}

type Waiter

type Waiter struct {
	// contains filtered or unexported fields
}

Waiter implements functions to block till kube objects are in a certain state.

func NewWaiter

func NewWaiter(
	client client.Client, scheme *runtime.Scheme,
	defaultOpts ...WaitOption,
) *Waiter

Creates a new Waiter instance.

func (*Waiter) WaitForCondition

func (w *Waiter) WaitForCondition(
	ctx context.Context, object client.Object,
	conditionType string, conditionStatus metav1.ConditionStatus,
	opts ...WaitOption,
) error

Waits for an object to report the given condition with given status. Takes observedGeneration into account when present on the object. observedGeneration may be reported on the condition or under .status.observedGeneration.

func (*Waiter) WaitForObject

func (w *Waiter) WaitForObject(
	ctx context.Context, object client.Object, waitReason string,
	checkFn func(obj client.Object) (done bool, err error),
	opts ...WaitOption,
) error

Wait for an object to match a check function.

func (*Waiter) WaitForReadiness

func (w *Waiter) WaitForReadiness(
	ctx context.Context, object client.Object, opts ...WaitOption,
) error

Waits for an object to be considered available.

func (*Waiter) WaitToBeGone added in v0.4.0

func (w *Waiter) WaitToBeGone(
	ctx context.Context, object client.Object,
	checkFn func(obj client.Object) (done bool, err error),
	opts ...WaitOption,
) error

Wait for an object to not exist anymore.

type WaiterConfig

type WaiterConfig struct {
	Timeout  time.Duration
	Interval time.Duration
}

func (*WaiterConfig) Default

func (c *WaiterConfig) Default()

Sets defaults on the waiter config.

type WithClusterInitializers

type WithClusterInitializers []ClusterInitializer

func (WithClusterInitializers) ApplyToEnvironmentConfig

func (i WithClusterInitializers) ApplyToEnvironmentConfig(c *EnvironmentConfig)

type WithClusterOptions

type WithClusterOptions []ClusterOption

func (WithClusterOptions) ApplyToEnvironmentConfig

func (opts WithClusterOptions) ApplyToEnvironmentConfig(c *EnvironmentConfig)

type WithContainerRuntime

type WithContainerRuntime ContainerRuntime

func (WithContainerRuntime) ApplyToEnvironmentConfig

func (cr WithContainerRuntime) ApplyToEnvironmentConfig(c *EnvironmentConfig)

type WithHelmOptions

type WithHelmOptions []HelmOption

func (WithHelmOptions) ApplyToClusterConfig

func (opts WithHelmOptions) ApplyToClusterConfig(c *ClusterConfig)

type WithInterval

type WithInterval time.Duration

func (WithInterval) ApplyToWaiterConfig

func (i WithInterval) ApplyToWaiterConfig(c *WaiterConfig)

type WithKindClusterConfig added in v0.5.0

type WithKindClusterConfig kindv1alpha4.Cluster

func (WithKindClusterConfig) ApplyToEnvironmentConfig added in v0.5.0

func (opts WithKindClusterConfig) ApplyToEnvironmentConfig(c *EnvironmentConfig)

type WithKubeconfigPath added in v0.2.0

type WithKubeconfigPath string

func (WithKubeconfigPath) ApplyToClusterConfig added in v0.2.0

func (kubeconfig WithKubeconfigPath) ApplyToClusterConfig(c *ClusterConfig)

type WithNewClusterFunc

type WithNewClusterFunc NewClusterFunc

func (WithNewClusterFunc) ApplyToEnvironmentConfig

func (f WithNewClusterFunc) ApplyToEnvironmentConfig(c *EnvironmentConfig)

type WithNewCtrlClientFunc added in v0.2.2

type WithNewCtrlClientFunc NewCtrlClientFunc

func (WithNewCtrlClientFunc) ApplyToClusterConfig added in v0.2.2

func (f WithNewCtrlClientFunc) ApplyToClusterConfig(c *ClusterConfig)

type WithNewHelmFunc

type WithNewHelmFunc NewHelmFunc

func (WithNewHelmFunc) ApplyToClusterConfig

func (f WithNewHelmFunc) ApplyToClusterConfig(c *ClusterConfig)

type WithNewRestConfigFunc added in v0.2.2

type WithNewRestConfigFunc NewRestConfigFunc

func (WithNewRestConfigFunc) ApplyToClusterConfig added in v0.2.2

func (f WithNewRestConfigFunc) ApplyToClusterConfig(c *ClusterConfig)

type WithNewWaiterFunc

type WithNewWaiterFunc NewWaiterFunc

func (WithNewWaiterFunc) ApplyToClusterConfig

func (f WithNewWaiterFunc) ApplyToClusterConfig(c *ClusterConfig)

type WithSchemeBuilder

type WithSchemeBuilder runtime.SchemeBuilder

func (WithSchemeBuilder) ApplyToClusterConfig

func (sb WithSchemeBuilder) ApplyToClusterConfig(c *ClusterConfig)

type WithStderr

type WithStderr struct{ io.Writer }

func (WithStderr) ApplyToHelmConfig

func (w WithStderr) ApplyToHelmConfig(c *HelmConfig)

type WithStdout

type WithStdout struct{ io.Writer }

func (WithStdout) ApplyToHelmConfig

func (w WithStdout) ApplyToHelmConfig(c *HelmConfig)

type WithTimeout

type WithTimeout time.Duration

func (WithTimeout) ApplyToWaiterConfig

func (t WithTimeout) ApplyToWaiterConfig(c *WaiterConfig)

type WithWaitOptions

type WithWaitOptions []WaitOption

func (WithWaitOptions) ApplyToClusterConfig

func (opts WithWaitOptions) ApplyToClusterConfig(c *ClusterConfig)

Jump to

Keyboard shortcuts

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