Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithManifest ¶ added in v0.29.0
func WithManifest(manifestPath string) testcontainers.CustomizeRequestOption
WithManifest loads the manifest into the cluster. K3s applies it automatically during the startup process
Types ¶
type K3sContainer ¶
type K3sContainer struct {
testcontainers.Container
}
K3sContainer represents the K3s container type used in the module
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error)
Run creates an instance of the K3s container type
Example ¶
// runK3sContainer {
ctx := context.Background()
k3sContainer, err := k3s.Run(ctx, "rancher/k3s:v1.27.1-k3s1")
defer func() {
if err := testcontainers.TerminateContainer(k3sContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := k3sContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
kubeConfigYaml, err := k3sContainer.GetKubeConfig(ctx)
if err != nil {
log.Printf("failed to get kubeconfig: %s", err)
return
}
restcfg, err := clientcmd.RESTConfigFromKubeConfig(kubeConfigYaml)
if err != nil {
log.Printf("failed to create rest config: %s", err)
return
}
k8s, err := kubernetes.NewForConfig(restcfg)
if err != nil {
log.Printf("failed to create k8s client: %s", err)
return
}
nodes, err := k8s.CoreV1().Nodes().List(ctx, v1.ListOptions{})
if err != nil {
log.Printf("failed to list nodes: %s", err)
return
}
fmt.Println(len(nodes.Items))
Output: true 1
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the K3s container type
func (*K3sContainer) GetKubeConfig ¶
func (c *K3sContainer) GetKubeConfig(ctx context.Context) ([]byte, error)
GetKubeConfig returns the modified kubeconfig with server url
func (*K3sContainer) LoadImages ¶ added in v0.25.0
func (c *K3sContainer) LoadImages(ctx context.Context, images ...string) error
func (*K3sContainer) LoadImagesWithOpts ¶ added in v0.39.0
func (c *K3sContainer) LoadImagesWithOpts(ctx context.Context, images []string, opts ...testcontainers.SaveImageOption) error
type KubeConfigValue ¶
type KubeConfigValue struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Clusters []KubeconfigNamedCluster `yaml:"clusters"`
Users []KubeconfigUser `yaml:"users"`
Contexts []KubeconfigNamedContext `yaml:"contexts"`
CurrentContext string `yaml:"current-context"`
Preferences struct{} `yaml:"preferences"`
}
KubeConfigValue is a struct used to create a kubectl configuration YAML file.
type KubeconfigAuthProvider ¶
type KubeconfigAuthProvider struct {
Name string `yaml:"name"`
Config map[string]string `yaml:"config"`
}
KubeconfigAuthProvider is a struct used to create a kubectl authentication provider
type KubeconfigCluster ¶
type KubeconfigCluster struct {
Server string `yaml:"server"`
CertificateAuthorityData string `yaml:"certificate-authority-data"`
CertificateAuthority string `yaml:"certificate-authority"`
}
KubeconfigCluster is a struct used to create a kubectl configuration YAML file
type KubeconfigContext ¶
type KubeconfigContext struct {
Cluster string `yaml:"cluster"`
Namespace string `yaml:"namespace,omitempty"`
User string `yaml:"user"`
}
KubeconfigContext is a struct used to create a kubectl configuration YAML file
type KubeconfigNamedCluster ¶
type KubeconfigNamedCluster struct {
Name string `yaml:"name"`
Cluster KubeconfigCluster `yaml:"cluster"`
}
KubeconfigNamedCluster is a struct used to create a kubectl configuration YAML file
type KubeconfigNamedContext ¶
type KubeconfigNamedContext struct {
Name string `yaml:"name"`
Context KubeconfigContext `yaml:"context"`
}
KubeconfigNamedContext is a struct used to create a kubectl configuration YAML file
type KubeconfigUser ¶
type KubeconfigUser struct {
Name string `yaml:"name"`
User KubeconfigUserKeyPair `yaml:"user"`
}
KubeconfigUser is a struct used to create a kubectl configuration YAML file
type KubeconfigUserKeyPair ¶
type KubeconfigUserKeyPair struct {
ClientCertificateData string `yaml:"client-certificate-data"`
ClientKeyData string `yaml:"client-key-data"`
AuthProvider KubeconfigAuthProvider `yaml:"auth-provider,omitempty"`
}
KubeconfigUserKeyPair is a struct used to create a kubectl configuration YAML file