integration

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CleanupInspektorGadget = &Command{
	Name:    "CleanupInspektorGadget",
	Cmd:     "$KUBECTL_GADGET undeploy",
	Cleanup: true,
}

CleanupInspektorGadget cleans up inspector gadget in Kubernetes

View Source
var CleanupSPO = []*Command{
	{
		Name: "RemoveSecurityProfilesOperator",
		Cmd: `
		kubectl delete seccompprofile --all --all-namespaces
		kubectl delete -f https://raw.githubusercontent.com/kubernetes-sigs/security-profiles-operator/v0.6.0/deploy/operator.yaml --ignore-not-found
		kubectl delete -f https://github.com/jetstack/cert-manager/releases/download/v1.10.0/cert-manager.yaml --ignore-not-found
		`,
		Cleanup: true,
	},
	{
		Name: "PatchSecurityProfilesOperatorProfiles",
		Cmd: `
		while true; do
		  # Ensure we have profiles to clean, otherwise just exit.
		  NAMESPACES=$(kubectl get seccompprofile --all-namespaces --no-headers --ignore-not-found -o custom-columns=":metadata.namespace" | uniq)
		  if [ -z $NAMESPACES ]; then
		    break
		  fi

		  # Patch profiles in each namespace, ignore any errors since it can already be deleted.
		  for NAMESPACE in $NAMESPACES; do
		    PROFILES=$(kubectl get seccompprofile --namespace $NAMESPACE -o name)
		    for PROFILE in $PROFILES; do
		      kubectl patch $PROFILE -n $NAMESPACE -p '{"metadata":{"finalizers":null}}' --type=merge || true
		    done
		  done

		  # Give some time before starting next cycle.
		  sleep 1
		done
		`,
		Cleanup: true,
	},
}

CleanupSPO cleans up security profile operator in Kubernetes

View Source
var DefaultTestComponent = InspektorGadgetTestComponent

DefaultTestComponent indicates component under testing allowing component specific logic e.g. indicating whether we have to enrich error message with InspektorGadget logs

Functions

func BuildBaseEvent

func BuildBaseEvent(namespace string) eventtypes.Event

func BuildCommonData

func BuildCommonData(namespace string) eventtypes.CommonData

func CheckNamespace added in v0.11.0

func CheckNamespace(ns string) bool

func ExpectAllInArrayToMatch

func ExpectAllInArrayToMatch[T any](output string, normalize func(*T), expectedEntry *T) error

ExpectAllInArrayToMatch verifies that the expectedEntry is matched by all the entries in the output (JSON array of JSON objects).

func ExpectAllInMultipleArrayToMatch added in v0.13.0

func ExpectAllInMultipleArrayToMatch[T any](output string, normalize func(*T), expectedEntry *T) error

ExpectAllInMultipleArrayToMatch verifies that the expectedEntry is matched by all the entries in the output (multiple JSON array of JSON objects separated by newlines).

func ExpectAllToMatch

func ExpectAllToMatch[T any](output string, normalize func(*T), expectedEntry *T) error

ExpectAllToMatch verifies that the expectedEntry is matched by all the entries in the output (Lines of independent JSON objects).

func ExpectEntriesInArrayToMatch

func ExpectEntriesInArrayToMatch[T any](output string, normalize func(*T), expectedEntries ...*T) error

ExpectEntriesInArrayToMatch verifies that all the entries in expectedEntries are matched by at least one entry in the output (JSON array of JSON objects).

func ExpectEntriesInMultipleArrayToMatch added in v0.13.0

func ExpectEntriesInMultipleArrayToMatch[T any](output string, normalize func(*T), expectedEntries ...*T) error

ExpectEntriesInMultipleArrayToMatch verifies that all the entries in expectedEntries are matched by at least one entry in the output (multiple JSON array of JSON objects separated by newlines).

func ExpectEntriesToMatch

func ExpectEntriesToMatch[T any](output string, normalize func(*T), expectedEntries ...*T) error

ExpectEntriesToMatch verifies that all the entries in expectedEntries are matched by at least one entry in the output (Lines of independent JSON objects).

func GenerateTestNamespaceName

func GenerateTestNamespaceName(namespace string) string

GenerateTestNamespaceName returns a string which can be used as unique namespace. The returned value is: namespace_parameter-random_integer.

func GetPodNode added in v0.15.0

func GetPodNode(ns string, podname string) (string, error)

func GetTestPodIP

func GetTestPodIP(ns string, podname string) (string, error)

func NewDockerOptions added in v0.12.0

func NewDockerOptions(opts ...dockerOption) []dockerOption

func PrintLogsFn added in v0.14.0

func PrintLogsFn(namespaces ...string) func(t *testing.T)

PrintLogsFn returns a function that print logs in case the test fails.

func RunTestSteps added in v0.12.0

func RunTestSteps[S TestStep](steps []S, t *testing.T, options ...Option)

RunTestSteps is used to run a list of test steps with stopping/clean up logic. executeBeforeCleanup is executed before calling the cleanup functions, it can be use for instance to print extra logs when the test fails.

func WithCbBeforeCleanup added in v0.14.0

func WithCbBeforeCleanup(f func(t *testing.T)) func(opts *runTestStepsOpts)

func WithDockerImage added in v0.12.0

func WithDockerImage(image string) dockerOption

func WithDockerSeccompProfile added in v0.12.0

func WithDockerSeccompProfile(profile string) dockerOption

Types

type Command

type Command struct {
	// Name of the command to be run, used to give information.
	Name string

	// Cmd is a string of the command which will be run.
	Cmd string

	// ExpectedString contains the exact expected output of the command.
	ExpectedString string

	// ExpectedRegexp contains a regex used to match against the command output.
	ExpectedRegexp string

	// ExpectedOutputFn is a function used to verify the output.
	ExpectedOutputFn func(output string) error

	// Cleanup indicates this command is used to clean resource and should not be
	// skipped even if previous commands failed.
	Cleanup bool

	// StartAndStop indicates this command should first be started then stopped.
	// It corresponds to gadget like execsnoop which wait user to type Ctrl^C.
	StartAndStop bool
	// contains filtered or unexported fields
}

func BusyboxPodCommand

func BusyboxPodCommand(namespace, cmd string) *Command

BusyboxPodCommand returns a Command that creates a pod and runs "cmd" in it.

func BusyboxPodRepeatCommand

func BusyboxPodRepeatCommand(namespace, cmd string) *Command

BusyboxPodRepeatCommand returns a Command that creates a pod and runs "cmd" each 0.1 seconds inside the pod.

func CreateTestNamespaceCommand

func CreateTestNamespaceCommand(namespace string) *Command

CreateTestNamespaceCommand returns a Command which creates a namespace whom name is given as parameter.

func DeleteRemainingNamespacesCommand

func DeleteRemainingNamespacesCommand() *Command

DeleteRemainingNamespacesCommand returns a Command which deletes a namespace whom name is given as parameter.

func DeleteTestNamespaceCommand

func DeleteTestNamespaceCommand(namespace string) *Command

DeleteTestNamespaceCommand returns a Command which deletes a namespace whom name is given as parameter.

func DeployInspektorGadget

func DeployInspektorGadget(image, imagePullPolicy string) *Command

DeployInspektorGadget deploys inspector gadget in Kubernetes

func DeploySPO

func DeploySPO(limitReplicas, patchWebhookConfig, bestEffortResourceMgmt bool) *Command

func PodCommand

func PodCommand(podname, image, namespace, command, commandArgs string) *Command

PodCommand returns a Command that starts a pid with a specified image, command and args

func SleepForSecondsCommand added in v0.11.0

func SleepForSecondsCommand(seconds int) *Command

SleepForSecondsCommand returns a Command which sleeps for given seconds

func WaitUntilPodReadyCommand

func WaitUntilPodReadyCommand(namespace string, podname string) *Command

WaitUntilPodReadyCommand returns a Command which waits until pod with the specified name in the given as parameter namespace is ready.

func WaitUntilTestPodReadyCommand

func WaitUntilTestPodReadyCommand(namespace string) *Command

WaitUntilTestPodReadyCommand returns a Command which waits until test-pod in the given as parameter namespace is ready.

func (*Command) IsCleanup added in v0.12.0

func (c *Command) IsCleanup() bool

func (*Command) IsStartAndStop added in v0.12.0

func (c *Command) IsStartAndStop() bool

func (*Command) KillWithoutTest

func (c *Command) KillWithoutTest() error

KillWithoutTest kills a Command started with StartWithoutTest() or RunWithoutTest() and we do not need to verify its output. This is thought to be used in TestMain().

func (*Command) Run

func (c *Command) Run(t *testing.T)

Run runs the Command on the given as parameter test.

func (*Command) RunWithoutTest

func (c *Command) RunWithoutTest() error

RunWithoutTest runs the Command, this is thought to be used in TestMain().

func (*Command) Running added in v0.12.0

func (c *Command) Running() bool

func (*Command) Start

func (c *Command) Start(t *testing.T)

Start starts the Command on the given as parameter test, you need to wait it using Stop().

func (*Command) StartWithoutTest

func (c *Command) StartWithoutTest() error

StartWithoutTest starts the Command, this is thought to be used in TestMain().

func (*Command) Stop

func (c *Command) Stop(t *testing.T)

Stop stops a Command previously started with Start(). To do so, it Kill() the process corresponding to this Cmd and then wait for its termination. Cmd output is then checked with regard to ExpectedString and ExpectedRegexp

func (*Command) WaitWithoutTest

func (c *Command) WaitWithoutTest() error

WaitWithoutTest waits for a Command that was started with StartWithoutTest(), this is thought to be used in TestMain().

type DockerContainer added in v0.12.0

type DockerContainer struct {
	Name         string
	Cmd          string
	Options      []dockerOption
	Cleanup      bool
	StartAndStop bool
	// contains filtered or unexported fields
}

DockerContainer implements TestStep for docker containers

func (*DockerContainer) IsCleanup added in v0.12.0

func (d *DockerContainer) IsCleanup() bool

func (*DockerContainer) IsStartAndStop added in v0.12.0

func (d *DockerContainer) IsStartAndStop() bool

func (*DockerContainer) Run added in v0.12.0

func (d *DockerContainer) Run(t *testing.T)

func (*DockerContainer) Running added in v0.12.0

func (d *DockerContainer) Running() bool

func (*DockerContainer) Start added in v0.12.0

func (d *DockerContainer) Start(t *testing.T)

func (*DockerContainer) Stop added in v0.12.0

func (d *DockerContainer) Stop(t *testing.T)

type Option added in v0.14.0

type Option func(*runTestStepsOpts)

type TestComponent added in v0.12.0

type TestComponent int
const (
	InspektorGadgetTestComponent TestComponent = iota
	IgTestComponent
)

type TestStep added in v0.12.0

type TestStep interface {
	// Run runs the step and wait its completion.
	Run(t *testing.T)

	// Start starts the step and immediately returns, it does wait until
	// its completion, use Stop() for that.
	Start(t *testing.T)

	// Stop stops the step and waits its completion.
	Stop(t *testing.T)

	// IsCleanup returns true if the step is used to clean resource and
	// should not be skipped even if previous commands failed.
	IsCleanup() bool

	// IsStartAndStop returns true if the step should first be started then
	// stopped after some time.
	IsStartAndStop() bool

	// Running returns true if the step has been started.
	Running() bool
}

TestStep allows combining different steps (e.g command, container creation) to allow simplified/consistent flow for tests via RunTestSteps

Jump to

Keyboard shortcuts

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