utils

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MPL-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MondooClientSecret   = "mondoo-client"
	MondooTokenSecret    = "mondoo-token"
	CnspecImageTagEnvVar = "CNSPEC_IMAGE_TAG"
)
View Source
const (
	RetryInterval = 2
	RetryLoop     = 75
)
View Source
const ServiceAccountEnv = "MONDOO_SERVICE_ACCOUNT_EDGE"

Variables

View Source
var (
	CreateArgs                        = []string{"create", "-f"}
	CreateFromStdinArgs               = append(CreateArgs, "-")
	ApplyArgs                         = []string{"apply", "-f"}
	ApplyFromStdinArgs                = append(ApplyArgs, "-")
	DeleteArgs                        = []string{"delete", "-f"}
	DeleteArgsIgnoreNotFound          = []string{"delete", "--ignore-not-found=true", "-f"}
	DeleteFromStdinArgs               = append(DeleteArgs, "-")
	DeleteIngoreNotFoundFromStdinArgs = append(DeleteArgsIgnoreNotFound, "-")
)

Functions

func DefaultAuditConfig

func DefaultAuditConfig(ns string, workloads, nodes, admission bool) mondoov2.MondooAuditConfig

DefaultAuditConfig returns a new Mondoo audit config with some default settings to make sure a tests passes (e.g. setting the correct secret name).

func DefaultAuditConfigMinimal added in v0.2.8

func DefaultAuditConfigMinimal(ns string, workloads, nodes, admission, consoleIntegration bool) mondoov2.MondooAuditConfig

DefaultAuditConfigMinimal returns a new Mondoo audit config with minimal default settings to make sure a test passes (e.g. setting the correct secret name). Values which have defaults are not set. This means that using this function in unit tests might result in strange behavior. For unit tests use DefaultAuditConfig instead.

func ExitStatus

func ExitStatus(err error) (int, bool)

func FindRootFolder

func FindRootFolder() (string, error)

func GenerateTLSCerts

func GenerateTLSCerts(dnsNames []string) (*bytes.Buffer, *bytes.Buffer, *bytes.Buffer, error)

GenerateTLSCerts will return create a CA and return the CA certificate, the Server certificate, and the Server private key for the provided list of dnsNames

func GetServiceAccount added in v1.9.3

func GetServiceAccount() (*upstream.ServiceAccountCredentials, error)

func LabelSelectorListOptions

func LabelSelectorListOptions(labelSelector string) (*client.ListOptions, error)

func LabelsToLabelSelector added in v0.4.0

func LabelsToLabelSelector(ls map[string]string) string

func RandString added in v0.4.0

func RandString(n int) string

func ReadFile

func ReadFile(filename string) string

Types

type CommandArgs

type CommandArgs struct {
	Command             string
	CmdArgs             []string
	PipeToStdIn         string
	EnvironmentVariable []string
}

CommandArgs is a warpper for cmd args

type CommandExecutor

type CommandExecutor struct{}

CommandExecutor is the type of the Executor

func (*CommandExecutor) ExecuteCommand

func (c *CommandExecutor) ExecuteCommand(command string, arg ...string) error

ExecuteCommand starts a process and wait for its completion

func (*CommandExecutor) ExecuteCommandWithCombinedOutput

func (*CommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)

ExecuteCommandWithCombinedOutput executes a command with combined output

func (*CommandExecutor) ExecuteCommandWithEnv

func (*CommandExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error

ExecuteCommandWithEnv starts a process with env variables and wait for its completion

func (*CommandExecutor) ExecuteCommandWithOutput

func (*CommandExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)

ExecuteCommandWithOutput executes a command with output

func (*CommandExecutor) ExecuteCommandWithOutputFile

func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string, arg ...string) (string, error)

ExecuteCommandWithOutputFile executes a command with output on a file #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close

func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout

func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout(timeout time.Duration,
	command, outfileArg string, arg ...string,
) (string, error)

ExecuteCommandWithOutputFileTimeout Same as ExecuteCommandWithOutputFile but with a timeout limit. #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close

func (*CommandExecutor) ExecuteCommandWithTimeout

func (*CommandExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)

ExecuteCommandWithTimeout starts a process and wait for its completion with timeout.

type CommandOut

type CommandOut struct {
	StdOut   string
	StdErr   string
	ExitCode int
	Err      error
}

CommandOut is a wrapper for cmd out returned after executing command args

func ExecuteCommand

func ExecuteCommand(cmdStruct CommandArgs) CommandOut

ExecuteCommand executes a os command with stdin and returns output

type K8sHelper

type K8sHelper struct {
	Clientset        client.Client
	RunningInCluster bool
	// contains filtered or unexported fields
}

func CreateK8sHelper

func CreateK8sHelper() (*K8sHelper, error)

CreateK8sHelper creates a instance of k8sHelper

func (*K8sHelper) CheckForDegradedCondition added in v0.4.1

func (k8sh *K8sHelper) CheckForDegradedCondition(auditConfig *api.MondooAuditConfig, conditionType api.MondooAuditConfigConditionType, conditionStatus v1.ConditionStatus) error

CheckForDegradedCondition Check whether specified Condition is in degraded state in a MondooAuditConfig with retries.

func (*K8sHelper) CheckForPodInStatus added in v0.4.1

func (k8sh *K8sHelper) CheckForPodInStatus(auditConfig *api.MondooAuditConfig, podName string) error

CheckForPodInStatus Check whether a give PodName is an element of the PodList saved in the Status part of MondooAuditConfig

func (*K8sHelper) CheckForReconciledOperatorVersion added in v0.4.1

func (k8sh *K8sHelper) CheckForReconciledOperatorVersion(auditConfig *api.MondooAuditConfig, version string) error

CheckForReconciledOperatorVersion Check whether the MondooAuditConfig Status contains the current operator Version after Reconcile.

func (*K8sHelper) DeleteResourceIfExists

func (k8sh *K8sHelper) DeleteResourceIfExists(r client.Object) error

DeleteResourceIfExists Deletes the requested resource if it exists. If the resource does not exist, the function does nothing (return no error).

func (*K8sHelper) EnsureNoPodsPresent added in v0.6.0

func (k8sh *K8sHelper) EnsureNoPodsPresent(listOpts *client.ListOptions) error

IsPodInExpectedState waits for a pod to be in a Ready state If the pod is in expected state within the time retry limit true is returned, if not false

func (*K8sHelper) ExecuteWithRetries added in v0.2.8

func (k8sh *K8sHelper) ExecuteWithRetries(f func() (bool, error)) error

func (*K8sHelper) GetDescribeFromNamespace added in v1.0.1

func (k8sh *K8sHelper) GetDescribeFromNamespace(namespace, testName string)

func (*K8sHelper) GetEventsFromNamespace

func (k8sh *K8sHelper) GetEventsFromNamespace(namespace, testName string)

func (*K8sHelper) GetLogsFromNamespace

func (k8sh *K8sHelper) GetLogsFromNamespace(namespace, testName string)

GetLogsFromNamespace collects logs for all containers in all pods in the namespace

func (*K8sHelper) GetMondooAuditConfigConditionByType added in v0.4.1

func (k8sh *K8sHelper) GetMondooAuditConfigConditionByType(auditConfig *api.MondooAuditConfig, conditionType api.MondooAuditConfigConditionType) (api.MondooAuditConfigCondition, error)

GetMondooAuditConfigConditionByType Fetches Condition from MondooAuditConfig Status for the specified Type.

func (*K8sHelper) GetMondooAuditConfigFromCluster added in v0.4.1

func (k8sh *K8sHelper) GetMondooAuditConfigFromCluster(auditConfigName, auditConfigNamespace string) (*api.MondooAuditConfig, error)

GetMondooAuditConfigFromCluster Fetches current MondooAuditConfig from Cluster

func (*K8sHelper) IsPodReady

func (k8sh *K8sHelper) IsPodReady(labelSelector, namespace string) bool

IsPodReady waits for a pod to be in a Ready state If the pod is in ready state within the time retry limit true is returned, if not false

func (*K8sHelper) Kubectl

func (k8sh *K8sHelper) Kubectl(args ...string) (string, error)

Kubectl is wrapper for executing kubectl commands

func (*K8sHelper) KubectlWithStdin

func (k8sh *K8sHelper) KubectlWithStdin(stdin string, args ...string) (string, error)

KubectlWithStdin is wrapper for executing kubectl commands in stdin

func (*K8sHelper) PrintPodDescribe

func (k8sh *K8sHelper) PrintPodDescribe(namespace string, args ...string)

func (*K8sHelper) WaitForGoodCondition added in v0.6.0

func (k8sh *K8sHelper) WaitForGoodCondition(auditConfig *api.MondooAuditConfig, conditionType api.MondooAuditConfigConditionType) error

CheckForDegradedCondition Check whether specified Condition is in degraded state in a MondooAuditConfig with retries.

func (*K8sHelper) WaitForResourceDeletion

func (k8sh *K8sHelper) WaitForResourceDeletion(r client.Object) error

WaitForResourceDeletion waits for a resource deletion

func (*K8sHelper) WaitUntilCronJobsSuccessful added in v0.4.0

func (k8sh *K8sHelper) WaitUntilCronJobsSuccessful(labelSelector, namespace string) bool

WaitUntilCronJobsSuccessful waits for the CronJobs with the specified selector to have at least one successful run.

Jump to

Keyboard shortcuts

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