Documentation
¶
Index ¶
- Constants
- func LoadKubernetesObjectsFromBytes(fileYaml []byte) ([]unstructured.Unstructured, error)
- func LoadKubernetesObjectsFromFile(filePath string) ([]unstructured.Unstructured, error)
- func LoadKubernetesObjectsFromFolder(folderPath string) ([]unstructured.Unstructured, 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
- type ClusterConfig
- type ClusterHelmInstall
- type ClusterInitializer
- type ClusterLoadObjectsFromFiles
- type ClusterLoadObjectsFromFolders
- type ClusterLoadObjectsFromHttp
- type ClusterOption
- type ContainerRuntime
- type Environment
- type EnvironmentConfig
- type EnvironmentOption
- type Helm
- type HelmConfig
- type HelmOption
- type NewClusterFunc
- type NewHelmFunc
- type NewWaiterFunc
- 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
- type WaiterConfig
- type WithClusterInitializers
- type WithClusterOptions
- type WithContainerRuntime
- type WithHelmOptions
- type WithInterval
- type WithLogger
- type WithNewClusterFunc
- type WithNewHelmFunc
- type WithNewWaiterFunc
- type WithSchemeBuilder
- type WithStderr
- type WithStdout
- type WithTimeout
- type WithWaitOptions
Examples ¶
Constants ¶
const ( WaiterDefaultTimeout = 60 * time.Second WaiterDefaultInterval = time.Second )
Variables ¶
This section is empty.
Functions ¶
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
WorkDir string
// Path to the kubeconfig of the cluster
Kubeconfig string
// 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.
type ClusterConfig ¶
type ClusterConfig struct {
Logger logr.Logger
SchemeBuilder runtime.SchemeBuilder
NewWaiter NewWaiterFunc
WaitOptions []WaitOption
NewHelm NewHelmFunc
HelmOptions []HelmOption
}
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 ClusterInitializer ¶
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 ( Podman ContainerRuntime = "podman" Docker ContainerRuntime = "docker" )
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 ¶
package main
import "github.com/go-logr/logr"
const (
olmVersion = "0.19.1"
)
func main() {
log := logr.Discard()
_ = NewEnvironment(
"cheese", ".cache/dev-env/cheese",
WithLogger(log),
WithContainerRuntime(Podman),
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",
},
},
},
)
}
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( ctx context.Context, filePath string) error
Load an image from a tar archive into the environment.
type EnvironmentConfig ¶
type EnvironmentConfig struct {
// Cluster initializers prepare a cluster for use.
ClusterInitializers []ClusterInitializer
// Container runtime to use
ContainerRuntime string
Logger logr.Logger
NewCluster NewClusterFunc
ClusterOptions []ClusterOption
}
func (*EnvironmentConfig) Default ¶
func (c *EnvironmentConfig) Default()
Apply default configuration.
type EnvironmentOption ¶
type EnvironmentOption interface {
ApplyToEnvironmentConfig(c *EnvironmentConfig)
}
type Helm ¶
type Helm struct {
// contains filtered or unexported fields
}
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 NewClusterFunc ¶
type NewClusterFunc func(kubeconfigPath string, opts ...ClusterOption) (*Cluster, error)
type NewHelmFunc ¶
type NewHelmFunc func( workDir, kubeconfig string, opts ...HelmOption, ) *Helm
type NewWaiterFunc ¶
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 WithLogger ¶
func (WithLogger) ApplyToClusterConfig ¶
func (l WithLogger) ApplyToClusterConfig(c *ClusterConfig)
func (WithLogger) ApplyToEnvironmentConfig ¶
func (l WithLogger) ApplyToEnvironmentConfig(c *EnvironmentConfig)
func (WithLogger) ApplyToWaiterConfig ¶
func (l WithLogger) ApplyToWaiterConfig(c *WaiterConfig)
type WithNewClusterFunc ¶
type WithNewClusterFunc NewClusterFunc
func (WithNewClusterFunc) ApplyToEnvironmentConfig ¶
func (f WithNewClusterFunc) ApplyToEnvironmentConfig(c *EnvironmentConfig)
type WithNewHelmFunc ¶
type WithNewHelmFunc NewHelmFunc
func (WithNewHelmFunc) ApplyToClusterConfig ¶
func (f WithNewHelmFunc) 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)