Documentation ¶
Index ¶
- Constants
- Variables
- func BuildImage(buildInfo *ImageBuildInfo, deps []interface{}) error
- func BuildPackage(buildInfo *PackageBuildInfo, deps []interface{}) error
- func DefaultNewRestConfig(kubeconfig string) (*rest.Config, error)
- func LoadAndConvertIntoObject(scheme *runtime.Scheme, filePath string, out interface{}) error
- func LoadAndUnmarshalIntoObject(filePath string, out interface{}) error
- func LoadKubernetesObjectsFromBytes(fileYaml []byte) ([]unstructured.Unstructured, error)
- func LoadKubernetesObjectsFromFile(filePath string) ([]unstructured.Unstructured, error)
- func LoadKubernetesObjectsFromFolder(folderPath string) ([]unstructured.Unstructured, error)
- func PushImage(pushInfo *ImagePushInfo, buildImageDep mg.Fn) error
- type Cluster
- func (c *Cluster) CreateAndWaitForReadiness(ctx context.Context, object client.Object, opts ...WaitOption) error
- func (c *Cluster) CreateAndWaitFromFiles(ctx context.Context, files []string, opts ...WaitOption) error
- func (c *Cluster) CreateAndWaitFromFolders(ctx context.Context, folders []string, opts ...WaitOption) error
- func (c *Cluster) CreateAndWaitFromHttp(ctx context.Context, urls []string, opts ...WaitOption) error
- func (c *Cluster) Kubeconfig() string
- type ClusterConfig
- type ClusterHelmInstall
- type ClusterInitFn
- type ClusterInitializer
- type ClusterLoadObjectFromClientObject
- type ClusterLoadObjectsFromFiles
- type ClusterLoadObjectsFromFolders
- type ClusterLoadObjectsFromHttp
- type ClusterOption
- type ContainerRuntime
- type Environment
- type EnvironmentConfig
- type EnvironmentOption
- type Helm
- type HelmConfig
- type HelmOption
- type ImageBuildInfo
- type ImagePushInfo
- type NewClusterFunc
- type NewCtrlClientFunc
- type NewHelmFunc
- type NewRestConfigFunc
- type NewWaiterFunc
- type PackageBuildInfo
- type UnknownTypeError
- type WaitOption
- type Waiter
- func (w *Waiter) WaitForCondition(ctx context.Context, object client.Object, conditionType string, ...) error
- func (w *Waiter) WaitForObject(ctx context.Context, object client.Object, waitReason string, ...) error
- func (w *Waiter) WaitForReadiness(ctx context.Context, object client.Object, opts ...WaitOption) error
- func (w *Waiter) WaitToBeGone(ctx context.Context, object client.Object, ...) error
- type WaiterConfig
- type WithClusterInitializers
- type WithClusterOptions
- type WithContainerRuntime
- type WithHelmOptions
- type WithInterval
- type WithKindClusterConfig
- type WithKubeconfigPath
- type WithNewClusterFunc
- type WithNewCtrlClientFunc
- type WithNewHelmFunc
- type WithNewRestConfigFunc
- type WithNewWaiterFunc
- type WithSchemeBuilder
- type WithStderr
- type WithStdout
- type WithTimeout
- type WithWaitOptions
Examples ¶
Constants ¶
const ( WaiterDefaultTimeout = 60 * time.Second WaiterDefaultInterval = time.Second )
Variables ¶
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 LoadAndConvertIntoObject ¶ added in v0.6.5
LoadAndConvertIntoObject loads one Kubernetes object from a file into the out object. It uses the `Convert` method of `scheme` under the hood, so it does any conversion that method would do. LoadAndUnmarshalIntoObject provides similar functionality, without the conversion aspect. LoadAndUnmarshalIntoObject should only be used when there is no available scheme or when the user wants to explicitly block any conversions.
func LoadAndUnmarshalIntoObject ¶ added in v0.6.5
LoadAndUnmarshalIntoObject loads one Kubernetes object from a file into the out object. LoadAndUnmarshalIntoObject provides similar functionality, but uses `runtime.Scheme.Convert` under the hood. LoadAndUnmarshalIntoObject should only be used when there is no available scheme or when the user wants to explicitly block any conversions.
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.
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 ¶
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.
type ClusterInitFn ¶ added in v0.7.0
Run a function with access to the cluster object. Can be used to directly interact with the cluster.
type ClusterInitializer ¶
type ClusterLoadObjectFromClientObject ¶ added in v0.5.0
Creates the referenced Object and waits for it to be ready.
type ClusterLoadObjectsFromFiles ¶
type ClusterLoadObjectsFromFiles []string
Load objects from given file paths and applies them into the cluster.
type ClusterLoadObjectsFromFolders ¶
type ClusterLoadObjectsFromFolders []string
Load objects from given folder paths and applies them into the cluster.
type ClusterLoadObjectsFromHttp ¶
type ClusterLoadObjectsFromHttp []string
Load objects from the given http urls and applies them into the cluster.
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
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 ¶
Wrapper arround "helm repo add"
type HelmConfig ¶
func (*HelmConfig) Default ¶
func (c *HelmConfig) Default()
type HelmOption ¶
type HelmOption interface {
ApplyToHelmConfig(c *HelmConfig)
}
type ImageBuildInfo ¶ added in v0.6.0
type ImagePushInfo ¶ added in v0.6.0
type NewClusterFunc ¶
type NewClusterFunc func(kubeconfigPath string, opts ...ClusterOption) (*Cluster, error)
type NewCtrlClientFunc ¶ added in v0.2.2
type NewHelmFunc ¶
type NewHelmFunc func( workDir, kubeconfig string, opts ...HelmOption, ) *Helm
type NewRestConfigFunc ¶ added in v0.2.2
type NewWaiterFunc ¶
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 ¶
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 (*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.
type WaiterConfig ¶
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 ¶
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 ¶
func (WithStderr) ApplyToHelmConfig ¶
func (w WithStderr) ApplyToHelmConfig(c *HelmConfig)
type WithStdout ¶
func (WithStdout) ApplyToHelmConfig ¶
func (w WithStdout) ApplyToHelmConfig(c *HelmConfig)
type WithTimeout ¶
func (WithTimeout) ApplyToWaiterConfig ¶
func (t WithTimeout) ApplyToWaiterConfig(c *WaiterConfig)
type WithWaitOptions ¶
type WithWaitOptions []WaitOption
func (WithWaitOptions) ApplyToClusterConfig ¶
func (opts WithWaitOptions) ApplyToClusterConfig(c *ClusterConfig)