stepfuncs

package
v0.0.0-...-2b985cc Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogsGeneratorDeployment = iota
	LogsGeneratorDaemonSet
)

Variables

This section is empty.

Functions

func ChangeMinMaxStatefulsetPods

func ChangeMinMaxStatefulsetPods(app string, newMin uint64, newMax uint64) features.Func

func GenerateLogs

func GenerateLogs(
	implType logsGeneratorImplType,
	logsCount uint,
	logsGeneratorName string,
	logsGeneratorNamespace string,
	logsGeneratorImage string,
) features.Func

Generate logsCount logs using the designated implementation type: either deployment or a daemonset.

func GenerateTraces

func GenerateTraces(
	tracesPerExporter uint,
	spansPerTrace uint,
	tracesGeneratorName string,
	tracesGeneratorNamespace string,
	tracesGeneratorImage string,
) features.Func

Generate logsCount logs using a deployment.

func HelmDeleteOpt

func HelmDeleteOpt(release string) features.Func

HelmDeleteOpt returns a features.Func that with run helm delete using the provided release name as argument.

NOTE: By default the default cluster namespace will be used. If you'd like to specify the namespace use SetKubectlNamespaceOpt.

func HelmDeleteTestOpt

func HelmDeleteTestOpt() features.Func

HelmDeleteTestOpt wraps HelmDeleteOpt by taking the release name saved in context by HelmInstallTestOpt/HelmInstallOpt.

func HelmDependencyUpdateOpt

func HelmDependencyUpdateOpt(path string) features.Func

HelmDependencyUpdateOpt returns a features.Func that will run helm dependency update using the provided path as an argument.

NOTE: This step will be skipped if the relevant environment variable (envNameHelmNoDependencyUpdate) will be set to a non empty value.

func HelmInstallOpt

func HelmInstallOpt(path string, releaseName string) features.Func

HelmInstallOpt returns a features.Func that with run helm install using the provided path and releaseName as arguments.

NOTE: By default the default cluster namespace will be used. If you'd like to specify the namespace use SetKubectlNamespaceOpt.

func HelmInstallTestOpt

func HelmInstallTestOpt(path string) features.Func

HelmInstallTestOpt wraps HelmInstallOpt with helm release name generation for tests.

func HelmVersionOpt

func HelmVersionOpt() features.Func

HelmVersion returns a features.Func that will run helm version

func IntoTestEnvFunc

func IntoTestEnvFunc(stepFn features.Func) internal.TestEnvFunc

func IntoTestEnvFuncs

func IntoTestEnvFuncs(stepFns ...features.Func) []internal.TestEnvFunc

func KubectlApplyFOpt

func KubectlApplyFOpt(yamlPath string, namespace string) features.Func

KubectlApplyFOpt returns a features.Func that will run "kubectl apply -f" in the provided namespace with the provided yaml file path as an argument.

func KubectlCreateNamespaceOpt

func KubectlCreateNamespaceOpt(namespace string) features.Func

KubectlCreateNamespaceOpt returns a features.Func that will create the requested namespace in the cluster and set it in kubectlOptions stored in the context.

func KubectlCreateNamespaceTestOpt

func KubectlCreateNamespaceTestOpt() features.Func

KubectlCreateNamespaceTestOpt wraps KubectlCreateNamespaceOpt by generating a namespace name for test.

func KubectlDeleteFOpt

func KubectlDeleteFOpt(yamlPath string, namespace string) features.Func

KubectlDeleteFOpt returns a features.Func that will run "kubectl delete -f" in the provided namespace with the provided yaml file path as an argument.

func KubectlDeleteNamespaceOpt

func KubectlDeleteNamespaceOpt(namespace string) features.Func

KubectlDeleteNamespaceOpt returns a features.Func that with delete the namespace that was saved in context using KubectlSetNamespaceOpt or KubectlSetTestNamespaceOpt.

func KubectlDeleteNamespaceTestOpt

func KubectlDeleteNamespaceTestOpt() features.Func

KubectlDeleteNamespaceTestOpt wraps KubectlDeleteNamespaceOpt by extracting the namespace saved in the context by KubectlCreateNamespaceTestOpt/KubectlCreateNamespaceOpt.

func PrintClusterStateOpt

func PrintClusterStateOpt(force ...bool) features.Func

PrintClusterStateOpt returns a features.Func that will log the output of kubectl get all if the test has failed of if the optional force flag has been set.

NOTE: By default the default cluster namespace will be used. If you'd like to specify the namespace use SetKubectlNamespaceOpt.

func SetHelmOptionsOpt

func SetHelmOptionsOpt(valuesFilePath string, extraInstallationArgs map[string][]string) features.Func

SetHelmOptionsOpt returns a features.Func that will get the kubectlOptions embedded in the context, use it to create helm options with values files set to the provided path.

NOTE: By default the default cluster namespace will be used. If you'd like to specify the namespace use SetKubectlNamespaceOpt.

func SetHelmOptionsTestOpt

func SetHelmOptionsTestOpt(extraInstallationArgs []string) features.Func

SetHelmOptionsTestOpt wraps SetHelmOptionsOpt by taking the values file from `values` directory and concatenating that with a name name generated from a test name.

The details of values file name generation can be found in `strings.ValueFileFromT()`.

func Wait

func Wait() features.Func

Wait is a step func that will wait for an hour or until a SIGKILL or SIGINT will be received. It can be used as a helper func in order to inspect cluster state at a particular step.

func WaitForPvcCount

func WaitForPvcCount(appName string, count int, waitDuration time.Duration, tickDuration time.Duration) features.Func

func WaitUntilDaemonSetIsReady

func WaitUntilDaemonSetIsReady(
	waitDuration time.Duration,
	tickDuration time.Duration,
	opts ...Option,
) features.Func

WaitUntilDaemonSetIsReady waits for a specified duration and checks with the specified tick interval whether the daemonset (as described by the provided options) is ready.

Readiness for a daemonset is defined as having Status.NumberUnavailable == 0.

func WaitUntilDeploymentIsReady

func WaitUntilDeploymentIsReady(
	waitDuration time.Duration,
	tickDuration time.Duration,
	opts ...Option,
) features.Func

WaitUntilDeploymentIsReady waits for a specified duration and checks with the specified tick interval whether the deployment (as described by the provided options) is ready.

Readiness for a deployment is defined as having Status.NumberUnavailable == 0.

func WaitUntilExpectedLogsPresent

func WaitUntilExpectedLogsPresent(
	expectedLogsCount uint,
	expectedLogsMetadata map[string]string,
	receiverMockNamespace string,
	receiverMockServiceName string,
	receiverMockServicePort int,
	waitDuration time.Duration,
	tickDuration time.Duration,
) features.Func

WaitUntilExpectedMetricsPresent returns a features.Func that can be used in `Assess` calls. It will wait until the provided number of logs with the provided labels are returned by receiver-mock's HTTP API on the provided Service and port, until it succeeds or waitDuration passes.

func WaitUntilExpectedMetricsPresent

func WaitUntilExpectedMetricsPresent(
	expectedMetrics []string,
	receiverMockNamespace string,
	receiverMockServiceName string,
	receiverMockServicePort int,
	waitDuration time.Duration,
	tickDuration time.Duration,
) features.Func

WaitUntilExpectedMetricsPresent returns a features.Func that can be used in `Assess` calls. It will wait until all the provided metrics are returned by receiver-mock's HTTP API on the provided Service and port, until it succeeds or waitDuration passes.

func WaitUntilExpectedSpansPresent

func WaitUntilExpectedSpansPresent(
	expectedSpansCount uint,
	expectedSpansMetadata map[string]string,
	receiverMockNamespace string,
	receiverMockServiceName string,
	receiverMockServicePort int,
	waitDuration time.Duration,
	tickDuration time.Duration,
) features.Func

func WaitUntilExpectedTracesPresent

func WaitUntilExpectedTracesPresent(
	expectedTracesCount uint,
	expectedSpansPerTraceCount uint,
	expectedTracesMetadata map[string]string,
	receiverMockNamespace string,
	receiverMockServiceName string,
	receiverMockServicePort int,
	waitDuration time.Duration,
	tickDuration time.Duration,
) features.Func

func WaitUntilPodsAvailable

func WaitUntilPodsAvailable(listOptions metav1.ListOptions, count int, wait time.Duration, tick time.Duration) features.Func

WaitUntilPodsAvailable returns a features.Func that can be used in `Assess` calls. It will wait until the selected pods are available, using the provided total `wait` and `tick` times as well as the provided list options and the desired count.

func WaitUntilStatefulSetIsReady

func WaitUntilStatefulSetIsReady(
	waitDuration time.Duration,
	tickDuration time.Duration,
	opts ...Option,
) features.Func

WaitUntilStatefulSetIsReady waits for a specified duration and check with the specified tick interval whether the stateful set (as described by the provided options) is ready.

Readiness for a stateful set in here is defined as having N ready replicas where N is also equal to the spec replicas set on the stateful set.

Types

type Formatter

type Formatter func(ctx context.Context) string

func ReleaseFormatter

func ReleaseFormatter(format string) Formatter

type LabelFormatterKV

type LabelFormatterKV struct {
	K string
	V Formatter
}

type Option

type Option interface {
	Apply(ctx context.Context, obj k8s.Object)
	GetListOption(ctx context.Context) resources.ListOption
}

Option is an interface that is used to pass in types that fulfill it to e.g. assess functions in internal/stepfuncs/assess_funcs.go so that their custom modification logic can be applied on k8s.Object.

Example:

func WaitUntilStatefulSetIsReady(

opts ...Option,

) features.Func {
  return func(ctx context.Context, t *testing.T, envConf *envconf.Config) context.Context {
    sts := appsv1.StatefulSet{
      ObjectMeta: v1.ObjectMeta{
        Namespace: ctxopts.Namespace(ctx),
      },
    }
    for _, opt := range opts {
      opt.Apply(ctx, &sts)
      ...
    }
  ...
}

func WithLabelsF

func WithLabelsF(kvs ...LabelFormatterKV) Option

WithLabelsF creates an Option which can be used to set key value pairs with custom value formatting.

Example: stepfuncs.WaitUntilStatefulSetIsReady(

...
stepfuncs.WithLabelsF(
  stepfuncs.LabelFormatterKV{
    K: "app",
    V: stepfuncs.ReleaseFormatter("%s-sumologic-fluentd-events"),
  },
),

),

The above snippet will use the helm release name (passed around in tests context) and place it in the `%s` format string when a test will be executed.

func WithName

func WithName(name string) Option

WithName creates a nameOption with provided name.

func WithNameF

func WithNameF(formatter Formatter) Option

WithNameF creates a nameFOption using the provided formatter.

Jump to

Keyboard shortcuts

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