...

Package k8s

import "edge-infra.dev/test/framework/k8s"
Overview
Index
Subdirectories

Overview ▾

Package k8s provides test framework utilities for K8s-based unit and integration tests, supporting the ability to do both with the same test suite.

Variables

KonfigKonnector has configuration values needed for installing & configuring K8s config connector

var KonfigKonnector struct {
    APIKey         string `description:"path to key.json for service account that will be used with k8s cfg connector, required for non-GKE test runs"`
    ServiceAccount string `description:"service account name to use when configurng k8s cfg connector on GKE via workload identity"`
}

Runtime has configuration values related to the cluster runtime

var Runtime struct {
    GKE bool `default:"false" description:"whether or not the test is being ran against a GKE cluster"`
}

Timeouts has configuration values for K8s specific timeouts

var Timeouts struct {
    DefaultTimeout time.Duration `default:"30s" description:"default timeout for k8s operations"`
    Tick           time.Duration `default:"1s" description:"default tick interval for k8s operations to be retried"`
    InstallTimeout time.Duration `default:"60s" description:"default timeout for installing components"`
}

func ConfigMap

func ConfigMap(k client.ObjectKey, data map[string]string) *corev1.ConfigMap

ConfigMap is a helper for creating corev1.ConfigMap resources

func CreateTestPod

func CreateTestPod(name string, namespace string, args []string, image string, registry ...string) *corev1.Pod

Create pod object that runs the specified args in the test cluster. Registry parameter defaults to "localhost:21700" if nothing is input, otherwise it uses the first input value.

func FieldManagerOwner

func FieldManagerOwner(f *framework.Framework) sap.Owner

FieldManagerOwner creates a consistent ownership key for resource fields that are created/updated by test framework code. The unique name for the test run is used in conjunction with a framework constant to provide scope.

func InstallOpts

func InstallOpts() []install.Option

InstallOpts returns consistent server-side apply options based on the configured framework timeouts. These options should be used for all of the apply operations

func Namespace

func Namespace(name string) *corev1.Namespace

func NeedsKonfigKonnector

func NeedsKonfigKonnector(f *framework.Framework)

NeedsKonfigKonnector is a function that can be hooked in as a framework.Step so that test suites which require K8s cfg connector for integration tests are automatically skipped if the pre-reqs aren't provided. Only skips if the test is an integration test.

func ProcessManifest

func ProcessManifest(manifest *unstructured.Unstructured, namespace string) (err error)

update manifest to set unique namespace and update associated role bindings

func Secret

func Secret(k client.ObjectKey, data map[string]string) *corev1.Secret

type K8s

K8s implements framework.SubFramework and provides lifecycle utilities for integration tests that run on K8s clusters.

type K8s struct {
    Namespace string
    Client    client.Client
    // contains filtered or unexported fields
}

func New

func New(cfg *rest.Config, opts ...Option) *K8s

New creates a K8s framework

func (*K8s) FindPodLogs

func (k *K8s) FindPodLogs(ctx context.Context, podname string, namespace string) (io.ReadCloser, error)

Return a stream of the Pod logs for a given pod in a namespace

func (*K8s) RESTConfig

func (k *K8s) RESTConfig() *rest.Config

func (*K8s) SetupWithFramework

func (k *K8s) SetupWithFramework(f *framework.Framework)

SetupWithFramework registers the called instance of K8s with the provided Framework, setting up lifecycle hooks and framework metadata.

type Option

Option is used to expose public optional K8s configurations. It should generally only be used to change non-public members of the K8s struct

type Option func(*K8s)

func SkipNamespaceCreation

func SkipNamespaceCreation() Option

SkipNamespaceCreation will make the framework skip creation of a namespace for each test case. Useful for tests that don't operate against any Namespaced resources.

func WithCertManager

func WithCertManager() Option

WithCertManager ensures that cert-manager is installed for the test run.

func WithCtrlManager

func WithCtrlManager(mgr manager.Manager) Option

WithCtrlManager sets up the framework for testing a controller-runtime Manager

func WithKonfigKonnector

func WithKonfigKonnector() Option

WithKonfigKonnector controls whether or not K8s config connector is installed and configured for the test run.

Subdirectories

Name Synopsis
..
envtest Package envtest helps to set up various pieces of sigs.k8s.io/controller-runtime/pkg/envtest framework to simplify writing K8s controller tests