helpers

package
v0.0.0-...-f6f9c28 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonEnvironmentNotInNamespace     = "EnvironmentNotInNamespace"
	ReasonMissingInfoInPipelineRunError = "MissingInfoInPipelineRunError"
	ReasonInvalidImageDigestError       = "InvalidImageDigest"
	ReasonMissingValidComponentError    = "MissingValidComponentError"
	ReasonUnknownError                  = "UnknownError"
)
View Source
const (

	//TestOutputName is the name of the standardized Test output Tekton task result
	TestOutputName = "TEST_OUTPUT"

	//LegacyTestOutputName is the previous name of the standardized AppStudio Test output Tekton task result
	LegacyTestOutputName = "HACBS_TEST_OUTPUT"

	// AppStudioTestOutputSuccess is the result that's set when the AppStudio test succeeds.
	AppStudioTestOutputSuccess = "SUCCESS"

	// AppStudioTestOutputFailure is the result that's set when the AppStudio test fails.
	AppStudioTestOutputFailure = "FAILURE"

	// AppStudioTestOutputWarning is the result that's set when the AppStudio test passes with a warning.
	AppStudioTestOutputWarning = "WARNING"

	// AppStudioTestOutputSkipped is the result that's set when the AppStudio test gets skipped.
	AppStudioTestOutputSkipped = "SKIPPED"

	// AppStudioTestOutputError is the result that's set when the AppStudio test produces an error.
	AppStudioTestOutputError = "ERROR"
)
View Source
const (

	// IntegrationTestScenarioValid is the condition for marking the AppStudio integration status of the Scenario.
	IntegrationTestScenarioValid = "IntegrationTestScenarioValid"

	// AppStudioIntegrationStatusInvalid is the reason that's set when the AppStudio integration gets into an invalid state.
	AppStudioIntegrationStatusInvalid = "Invalid"

	// AppStudioIntegrationStatusValid is the reason that's set when the AppStudio integration gets into an valid state.
	AppStudioIntegrationStatusValid = "Valid"
)
View Source
const ComponentFinalizer string = "test.appstudio.openshift.io/component"
View Source
const CreateSnapshotAnnotationName = "test.appstudio.openshift.io/create-snapshot-status"
View Source
const IntegrationPipelineRunFinalizer string = "test.appstudio.openshift.io/pipelinerun"

IntegrationPipelineRunFinalizer is the finalizer name to be added to the Integration PipelineRuns

View Source
const IntegrationTestScenarioFinalizer string = "test.appstudio.openshift.io/scenario"

Variables

This section is empty.

Functions

func AddFinalizerToComponent

func AddFinalizerToComponent(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, component *applicationapiv1alpha1.Component, finalizer string) error

AddFinalizerToComponent adds the finalizer to the component. If finalizer was not added successfully, a non-nil error is returned.

func AddFinalizerToPipelineRun

func AddFinalizerToPipelineRun(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, pipelineRun *tektonv1.PipelineRun, finalizer string) error

AddFinalizerToPipelineRun adds the finalizer to the PipelineRun. If finalizer was not added successfully, a non-nil error is returned.

func AddFinalizerToScenario

func AddFinalizerToScenario(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, scenario *v1beta2.IntegrationTestScenario, finalizer string) error

AddFinalizerToScenario adds the finalizer to the IntegrationTestScenario. If finalizer was not added successfully, a non-nil error is returned.

func GetIntegrationTestTaskResultsFromPipelineRunWithChildReferences

func GetIntegrationTestTaskResultsFromPipelineRunWithChildReferences(adapterClient client.Client, ctx context.Context, pipelineRun *tektonv1.PipelineRun) (map[string]*IntegrationTestTaskResult, error)

GetIntegrationTestTaskResultsFromPipelineRunWithChildReferences finds all TaskRuns from childReferences of the PipelineRun that also contain a TEST_OUTPUT result and returns the parsed data or validation error returns map taskName: result

func HandleLoaderError

func HandleLoaderError(logger IntegrationLogger, err error, resource, from string) (ctrl.Result, error)

func HasPipelineRunFinished

func HasPipelineRunFinished(object client.Object) bool

HasPipelineRunFinished returns a boolean indicating whether the PipelineRun finished or not. If the object passed to this function is not a PipelineRun, the function will return false.

func HasPipelineRunSucceeded

func HasPipelineRunSucceeded(object client.Object) bool

HasPipelineRunSucceeded returns a boolean indicating whether the PipelineRun succeeded or not. If the object passed to this function is not a PipelineRun, the function will return false.

func IsEnvironmentEphemeral

func IsEnvironmentEphemeral(testEnvironment *applicationapiv1alpha1.Environment) bool

func IsEnvironmentNotInNamespaceError

func IsEnvironmentNotInNamespaceError(err error) bool

func IsInvalidImageDigestError

func IsInvalidImageDigestError(err error) bool

func IsMissingInfoInPipelineRunError

func IsMissingInfoInPipelineRunError(err error) bool

func IsMissingValidComponentError

func IsMissingValidComponentError(err error) bool

func IsObjectYoungerThanThreshold

func IsObjectYoungerThanThreshold(obj metav1.Object, threshold time.Duration) bool

func IsScenarioValid

func IsScenarioValid(scenario *v1beta2.IntegrationTestScenario) bool

IsScenarioValid sets the IntegrationTestScenarioValid integration status condition for the Scenario to valid.

func MissingInfoInPipelineRunError

func MissingInfoInPipelineRunError(pipelineRunName, paramName string) error

func NewEnvironmentNotInNamespaceError

func NewEnvironmentNotInNamespaceError(environment, namespace string) error

func NewInvalidImageDigestError

func NewInvalidImageDigestError(componentName, image_digest string) error

func NewMissingValidComponentError

func NewMissingValidComponentError(componentName string) error

func RemoveFinalizerFromAllIntegrationPipelineRunsOfSnapshot

func RemoveFinalizerFromAllIntegrationPipelineRunsOfSnapshot(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, snapshot applicationapiv1alpha1.Snapshot, finalizer string) error

RemoveFinalizerFromAllIntegrationPipelineRunsOfSnapshot fetches all the Integration PipelineRuns associated with the given Snapshot. After fetching them, it removes the finalizer from the PipelineRun, and returns error if any.

func RemoveFinalizerFromComponent

func RemoveFinalizerFromComponent(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, component *applicationapiv1alpha1.Component, finalizer string) error

RemoveFinalizerFromComponent removes the finalizer from the Component. If finalizer was not removed successfully, a non-nil error is returned.

func RemoveFinalizerFromPipelineRun

func RemoveFinalizerFromPipelineRun(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, pipelineRun *tektonv1.PipelineRun, finalizer string) error

RemoveFinalizerFromPipelineRun removes the finalizer from the PipelineRun. If finalizer was not removed successfully, a non-nil error is returned.

func RemoveFinalizerFromScenario

func RemoveFinalizerFromScenario(adapterClient client.Client, logger IntegrationLogger, ctx context.Context, scenario *v1beta2.IntegrationTestScenario, finalizer string) error

RemoveFinalizerFromScenario removes the finalizer from the IntegrationTestScenario. If finalizer was not removed successfully, a non-nil error is returned.

func SetScenarioIntegrationStatusAsInvalid

func SetScenarioIntegrationStatusAsInvalid(scenario *v1beta2.IntegrationTestScenario, message string)

SetScenarioIntegrationStatusAsInvalid sets the IntegrationTestScenarioValid status condition for the Scenario to invalid.

func SetScenarioIntegrationStatusAsValid

func SetScenarioIntegrationStatusAsValid(scenario *v1beta2.IntegrationTestScenario, message string)

SetScenarioIntegrationStatusAsValid sets the IntegrationTestScenarioValid integration status condition for the Scenario to valid.

Types

type AppStudioTestResult

type AppStudioTestResult struct {
	Result    string `json:"result"`
	Namespace string `json:"namespace"`
	Timestamp string `json:"timestamp"`
	Note      string `json:"note"`
	Successes int    `json:"successes"`
	Failures  int    `json:"failures"`
	Warnings  int    `json:"warnings"`
}

AppStudioTestResult matches AppStudio TaskRun result contract

type IntegrationError

type IntegrationError struct {
	Reason  string
	Message string
}

func (*IntegrationError) Error

func (ie *IntegrationError) Error() string

type IntegrationLogger

type IntegrationLogger struct {
	logr.Logger
}

func (*IntegrationLogger) LogAuditEvent

func (il *IntegrationLogger) LogAuditEvent(msg string, obj runtime.Object, action LogAction, keysAndValues ...interface{})

LogAuditEvent should be used for auditable events to log all required metadata msg is a user friendly log message obj is k8s runtime object audit action type and any extra keyAndValues being passed to logger

func (IntegrationLogger) WithApp

WithApp returns a new logger with application namespacedName key-value

type IntegrationPipelineRunOutcome

type IntegrationPipelineRunOutcome struct {
	// contains filtered or unexported fields
}

IntegrationPipelineRunOutcome is struct for pipeline outcome metadata

func GetIntegrationPipelineRunOutcome

func GetIntegrationPipelineRunOutcome(adapterClient client.Client, ctx context.Context, pipelineRun *tektonv1.PipelineRun) (*IntegrationPipelineRunOutcome, error)

GetIntegrationPipelineRunOutcome returns the IntegrationPipelineRunOutcome which can be used for further inspection of the results and general outcome This function must be called on the finished pipeline

func (*IntegrationPipelineRunOutcome) GetValidationErrorsList

func (ipro *IntegrationPipelineRunOutcome) GetValidationErrorsList() []string

GetValidationErrorsList returns validation error messages for each invalid task result in a list.

func (*IntegrationPipelineRunOutcome) HasPipelineRunPassedTesting

func (ipro *IntegrationPipelineRunOutcome) HasPipelineRunPassedTesting() bool

HasPipelineRunPassedTesting returns general outcome If any of the tasks with the TEST_OUTPUT result don't have the `result` field set to SUCCESS or SKIPPED, it returns false.

func (*IntegrationPipelineRunOutcome) HasPipelineRunSucceeded

func (ipro *IntegrationPipelineRunOutcome) HasPipelineRunSucceeded() bool

HasPipelineRunSucceeded returns true when pipeline in outcome succeeded

func (*IntegrationPipelineRunOutcome) HasPipelineRunValidTestOutputs

func (ipro *IntegrationPipelineRunOutcome) HasPipelineRunValidTestOutputs() bool

HasPipelineRunValidTestOutputs returns false when we failed to parse results of TEST_OUTPUT in tasks

func (*IntegrationPipelineRunOutcome) LogResults

func (ipro *IntegrationPipelineRunOutcome) LogResults(logger logr.Logger)

LogResults writes tasks names with results into given logger, each task on separate line

type IntegrationTestTaskResult

type IntegrationTestTaskResult struct {
	TestOutput      *AppStudioTestResult
	ValidationError error
}

IntegrationTestTaskResult provides results from integration test task including metadata about validity of results

type LogAction

type LogAction int
const (
	LogActionView   LogAction = iota + 1 // VIEW
	LogActionAdd                         // ADD
	LogActionUpdate                      // UPDATE
	LogActionDelete                      // DELETE
)

func (LogAction) String

func (i LogAction) String() string

type SortTaskRunsByStartTime

type SortTaskRunsByStartTime []*TaskRun

SortTaskRunsByStartTime can sort TaskRuns by their start time. It implements sort.Interface.

func (SortTaskRunsByStartTime) Len

func (s SortTaskRunsByStartTime) Len() int

Len returns the length of the slice being sorted.

func (SortTaskRunsByStartTime) Less

func (s SortTaskRunsByStartTime) Less(i int, j int) bool

Less determines if TaskRun in position i started before TaskRun in position j.

func (SortTaskRunsByStartTime) Swap

func (s SortTaskRunsByStartTime) Swap(i int, j int)

Swap switches the position of two elements in the slice.

type TaskRun

type TaskRun struct {
	// contains filtered or unexported fields
}

TaskRun is an integration specific wrapper around the status of a Tekton TaskRun.

func GetAllChildTaskRunsForPipelineRun

func GetAllChildTaskRunsForPipelineRun(adapterClient client.Client, ctx context.Context, pipelineRun *tektonv1.PipelineRun) ([]*TaskRun, error)

GetAllChildTaskRunsForPipelineRun finds all Child TaskRuns for a given PipelineRun and returns integration TaskRun wrappers for them sorted by start time.

func NewTaskRunFromTektonTaskRun

func NewTaskRunFromTektonTaskRun(pipelineTaskName string, status *tektonv1.TaskRunStatus) *TaskRun

NewTaskRunFromTektonTaskRun creates and returns am integration TaskRun from the TaskRunStatus.

func (*TaskRun) GetDuration

func (t *TaskRun) GetDuration() time.Duration

GetDuration returns the time it took to execute the Task. If the start or end times are unknown, a duration of 0 is returned.

func (*TaskRun) GetPipelineTaskName

func (t *TaskRun) GetPipelineTaskName() string

GetPipelineTaskName returns the name of the PipelineTask.

func (*TaskRun) GetStartTime

func (t *TaskRun) GetStartTime() time.Time

GetStartTime returns the start time of the TaskRun. If the start time is unknown, the zero start time is returned.

func (*TaskRun) GetTestResult

func (t *TaskRun) GetTestResult() (*IntegrationTestTaskResult, error)

GetTestResult returns a IntegrationTestTaskResult if the TaskRun produced the result. It will return nil otherwise.

Jump to

Keyboard shortcuts

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