Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultAuditConfig(ns string, workloads, nodes, admission bool) mondoov2.MondooAuditConfig
- func DefaultAuditConfigMinimal(ns string, workloads, nodes, admission, consoleIntegration bool) mondoov2.MondooAuditConfig
- func ExitStatus(err error) (int, bool)
- func FindRootFolder() (string, error)
- func GenerateTLSCerts(dnsNames []string) (*bytes.Buffer, *bytes.Buffer, *bytes.Buffer, error)
- func GetServiceAccount() (*upstream.ServiceAccountCredentials, error)
- func LabelSelectorListOptions(labelSelector string) (*client.ListOptions, error)
- func LabelsToLabelSelector(ls map[string]string) string
- func RandString(n int) string
- func ReadFile(filename string) string
- type CommandArgs
- type CommandExecutor
- func (c *CommandExecutor) ExecuteCommand(command string, arg ...string) error
- func (*CommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)
- func (*CommandExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error
- func (*CommandExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)
- func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string, arg ...string) (string, error)
- func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout(timeout time.Duration, command, outfileArg string, arg ...string) (string, error)
- func (*CommandExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)
- type CommandOut
- type K8sHelper
- func (k8sh *K8sHelper) CheckForDegradedCondition(auditConfig *api.MondooAuditConfig, ...) error
- func (k8sh *K8sHelper) CheckForPodInStatus(auditConfig *api.MondooAuditConfig, podName string) error
- func (k8sh *K8sHelper) CheckForReconciledOperatorVersion(auditConfig *api.MondooAuditConfig, version string) error
- func (k8sh *K8sHelper) DeleteResourceIfExists(r client.Object) error
- func (k8sh *K8sHelper) EnsureNoPodsPresent(listOpts *client.ListOptions) error
- func (k8sh *K8sHelper) ExecuteWithRetries(f func() (bool, error)) error
- func (k8sh *K8sHelper) GetDescribeFromNamespace(namespace, testName string)
- func (k8sh *K8sHelper) GetEventsFromNamespace(namespace, testName string)
- func (k8sh *K8sHelper) GetLogsFromNamespace(namespace, testName string)
- func (k8sh *K8sHelper) GetMondooAuditConfigConditionByType(auditConfig *api.MondooAuditConfig, ...) (api.MondooAuditConfigCondition, error)
- func (k8sh *K8sHelper) GetMondooAuditConfigFromCluster(auditConfigName, auditConfigNamespace string) (*api.MondooAuditConfig, error)
- func (k8sh *K8sHelper) IsPodReady(labelSelector, namespace string) bool
- func (k8sh *K8sHelper) Kubectl(args ...string) (string, error)
- func (k8sh *K8sHelper) KubectlWithStdin(stdin string, args ...string) (string, error)
- func (k8sh *K8sHelper) PrintPodDescribe(namespace string, args ...string)
- func (k8sh *K8sHelper) WaitForGoodCondition(auditConfig *api.MondooAuditConfig, ...) error
- func (k8sh *K8sHelper) WaitForResourceDeletion(r client.Object) error
- func (k8sh *K8sHelper) WaitUntilCronJobsSuccessful(labelSelector, namespace string) bool
Constants ¶
const ( MondooClientSecret = "mondoo-client" MondooTokenSecret = "mondoo-token" CnspecImageTagEnvVar = "CNSPEC_IMAGE_TAG" )
const ( RetryInterval = 2 RetryLoop = 75 )
const ServiceAccountEnv = "MONDOO_SERVICE_ACCOUNT_EDGE"
Variables ¶
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 FindRootFolder ¶
func GenerateTLSCerts ¶
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 RandString ¶ added in v0.4.0
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 ¶
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 ¶
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 ¶
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 (*K8sHelper) GetDescribeFromNamespace ¶ added in v1.0.1
func (*K8sHelper) GetEventsFromNamespace ¶
func (*K8sHelper) GetLogsFromNamespace ¶
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 ¶
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) KubectlWithStdin ¶
KubectlWithStdin is wrapper for executing kubectl commands in stdin
func (*K8sHelper) PrintPodDescribe ¶
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 ¶
WaitForResourceDeletion waits for a resource deletion
func (*K8sHelper) WaitUntilCronJobsSuccessful ¶ added in v0.4.0
WaitUntilCronJobsSuccessful waits for the CronJobs with the specified selector to have at least one successful run.