utils

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 34 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GadgetEnvironmentContainerdSocketpath string = "INSPEKTOR_GADGET_CONTAINERD_SOCKETPATH"
	GadgetEnvironmentCRIOSocketpath       string = "INSPEKTOR_GADGET_CRIO_SOCKETPATH"
	GadgetEnvironmentDockerSocketpath     string = "INSPEKTOR_GADGET_DOCKER_SOCKETPATH"
	GadgetEnvironmentPodmanSocketpath     string = "INSPEKTOR_GADGET_PODMAN_SOCKETPATH"
)
View Source
const (
	GadgetOperation = "gadget.kinvolk.io/operation"
	// We name it "global" as if one trace is created on several nodes, then each
	// copy of the trace on each node will share the same id.
	GlobalTraceID = "global-trace-id"
	TraceTimeout  = 5 * time.Second
)

Variables

View Source
var KubectlGadgetVersion *semver.Version
View Source
var KubernetesConfigFlags = genericclioptions.NewConfigFlags(false)

Functions

func AddCommonFlags

func AddCommonFlags(command *cobra.Command, params *CommonFlags, gadgetNamespace string)

func CreateTrace

func CreateTrace(config *TraceConfig) (string, error)

CreateTrace initializes a trace object with its field according to the given parameter. The trace is then posted to the RESTClient which returns an error if something wrong occurred. A unique trace identifier is returned, this identifier will be used as other function parameter. A trace obtained with this function must be deleted calling DeleteTrace. Note that, if config.TraceInitialState is not empty, this function will succeed only if the trace was created and goes into the requested state.

func DeleteTrace

func DeleteTrace(gadgetNamespace string, traceID string) error

DeleteTrace deletes the traces for the given trace ID using RESTClient.

func DeleteTracesByGadgetName

func DeleteTracesByGadgetName(gadgetNamespace string, gadget string) error

DeleteTracesByGadgetName removes all traces with this gadget name

func ExecPod

func ExecPod(client *kubernetes.Clientset, node string, namespace string, podCmd string, cmdStdout io.Writer, cmdStderr io.Writer) error

func FlagInit

func FlagInit(rootCmd *cobra.Command)

func GetNamespace

func GetNamespace() (string, bool)

GetNamespace returns the namespace specified by '-n' or the default namespace configured in the kubeconfig file. It also returns a boolean that specifies if the namespace comes from the '-n' flag or not.

func GetRunningGadgetNamespaces added in v0.23.0

func GetRunningGadgetNamespaces() ([]string, error)

func GetTraceClient

func GetTraceClient() (*clientset.Clientset, error)

func GetTraceListFromOptions added in v0.11.0

func GetTraceListFromOptions(gadgetNamespace string, listTracesOptions metav1.ListOptions) (*gadgetv1alpha1.TraceList, error)

GetTraceListFromOptions returns a list of traces corresponding to the given options.

func ListTracesByGadgetName

func ListTracesByGadgetName(gadgetNamespace string, gadget string) ([]gadgetv1alpha1.Trace, error)

func PrintAllTraces

func PrintAllTraces(config *TraceConfig) error

PrintAllTraces prints all traces corresponding to the given config.CommonFlags.

func PrintTraceOutputFromStatus

func PrintTraceOutputFromStatus(
	gadgetNamespace string,
	traceID string,
	expectedState string,
	customResultsDisplay func(traceOutputMode string, results []string) error,
) error

PrintTraceOutputFromStatus is used to print trace output using function pointer provided by caller. It will parse trace.Spec.Output and print it calling the function pointer.

func PrintTraceOutputFromStream

func PrintTraceOutputFromStream(gadgetNamespace string, traceID string, expectedState string, params *CommonFlags,
	transformLine func(string) string,
) error

PrintTraceOutputFromStream is used to print trace output using generic printing function. This function is must be used by trace which has TraceOutputMode set to Stream.

func RunTraceAndPrintStatusOutput

func RunTraceAndPrintStatusOutput(
	config *TraceConfig,
	customResultsDisplay func(traceOutputMode string, results []string) error,
) error

RunTraceAndPrintStatusOutput creates a trace, prints its output and deletes it. It equals calling separately CreateTrace(), then PrintTraceOutputFromStatus() and DeleteTrace(). This function is thought to be used with "one-run" gadget, i.e. gadget which runs a trace when it is created.

func RunTraceAndPrintStream

func RunTraceAndPrintStream(config *TraceConfig, transformLine func(string) string) error

RunTraceAndPrintStream creates a trace, prints its output and deletes it. It equals calling separately CreateTrace(), then PrintTraceOutputFromStream() and DeleteTrace(). This function is thought to be used with "one-run" gadget, i.e. gadget which runs a trace when it is created.

func RunTraceStreamCallback

func RunTraceStreamCallback(gadgetNamespace string, config *TraceConfig, callback func(line string, node string)) error

RunTraceStreamCallback creates a stream trace and calls callback each time one of the tracers produces a new line on any of the nodes.

func SetTraceOperation

func SetTraceOperation(gadgetNamespace string, traceID string, operation string) error

SetTraceOperation sets the operation of an existing trace. If trace does not exist an error is returned.

func SigHandler added in v0.11.0

func SigHandler(gadgetNamespace string, traceID *string, printTerminationMessage bool)

SigHandler installs a handler for all signals which cause termination as their default behavior. On reception of this signal, the given trace will be deleted. This function fixes trace not being deleted when calling: kubectl gadget process-collector -A | head -n0

Types

type CommonFlags

type CommonFlags struct {
	// OutputConfig describes the way output should be printed
	commonutils.OutputConfig

	// LabelsRaw allows to filter containers with a label selector in the
	// following format: key1=value1,key2=value2.
	// It's the raw representation as passed by the user.
	LabelsRaw string

	// Labels is a parsed representation of LabelsRaw
	Labels map[string]string

	// Node allows to filter containers by node name
	Node string

	// Namespace allows to filter by Kubernetes namespace. Ignored if
	// AllNamespaces is true
	Namespace string

	// NamespaceOverridden will be true only if the CommonFlags.Namespace
	// field contains the value passed by the user using the '-n' flag
	// and not the default value configured in the kubeconfig file.
	NamespaceOverridden bool

	// AllNamespaces disables the container filtering by namespace
	AllNamespaces bool

	// Podname allows to filter containers by the pod name
	Podname string

	// Containername allows to filter containers by name
	Containername string

	// Number of seconds that the gadget will run for
	Timeout int
}

CommonFlags contains CLI flags common to several gadgets

type PostProcess

type PostProcess struct {
	OutStreams []*postProcessSingle
	ErrStreams []*postProcessSingle
	// contains filtered or unexported fields
}

func NewPostProcess

func NewPostProcess(config *PostProcessConfig) *PostProcess

type PostProcessConfig

type PostProcessConfig struct {
	// Number of flow this should process.
	Flows int

	// Function to be called each time there is new data from the node.
	Callback func(line string, node string)

	// Function to be called to transform the output before printing.
	// It's only called if Callback is nil.
	Transform func(line string) string

	// Streams to print the standard and error outputs.
	OutStream io.Writer
	ErrStream io.Writer

	// Only print the first line once.
	SkipFirstLine bool

	// Verbose mode
	Verbose bool
}

type TraceConfig

type TraceConfig struct {
	// GadgetName is gadget name, e.g. socket-collector.
	GadgetName string

	// GadgetNamespace is the namespace where Inspektor Gadget is deployed
	GadgetNamespace string

	// Operation is the gadget operation to apply to this trace, e.g. start to
	// start the tracing.
	Operation gadgetv1alpha1.Operation

	// TraceOutputMode is the trace output mode, the correct values are:
	// * "Status": The trace prints information when its status changes.
	// * "Stream": The trace prints information as events arrive.
	// * "File": The trace prints information into a file.
	// * "ExternalResource": The trace prints information an external resource,
	// e.g. a seccomp profile.
	TraceOutputMode gadgetv1alpha1.TraceOutputMode

	// TraceOutputState is the state in which the trace can output information.
	// For example, trace for *-collector gadget contains output while in
	// Completed state.
	// But other gadgets, like dns, can contain output only in Started state.
	TraceOutputState gadgetv1alpha1.TraceState

	// TraceOutput is either the name of the file when TraceOutputMode is File or
	// the name of the external resource when TraceOutputMode is ExternalResource.
	// Otherwise, its value is ignored.
	TraceOutput string

	// TraceInitialState is the state in which the trace should be after its
	// creation.
	// This field is only used by "multi-rounds gadgets" like biolatency.
	TraceInitialState gadgetv1alpha1.TraceState

	// CommonFlags is used to hold parameters given on the command line interface.
	CommonFlags *CommonFlags

	// Parameters is used to pass specific gadget configurations.
	Parameters map[string]string

	// AdditionalLabels is used to pass specific labels to traces.
	AdditionalLabels map[string]string
}

TraceConfig is used to contain information used to manage a trace.

Jump to

Keyboard shortcuts

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