gitops

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: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// BindingDeploymentStatusConditionType is the condition type to retrieve from the ComponentDeploymentConditions
	// in the SnapshotEnvironmentBinding's status to copy into the Release status
	BindingDeploymentStatusConditionType string = "AllComponentsDeployed"

	// BindingErrorOccurredStatusConditionType is the condition to check for failures within the
	// SnapshotEnvironmentBindingConditions status
	BindingErrorOccurredStatusConditionType string = "ErrorOccurred"
)
View Source
const (
	// PipelinesAsCodePrefix contains the prefix applied to labels and annotations copied from Pipelines as Code resources.
	PipelinesAsCodePrefix = "pac.test.appstudio.openshift.io"

	// SnapshotTypeLabel contains the type of the Snapshot.
	SnapshotTypeLabel = "test.appstudio.openshift.io/type"

	// SnapshotIntegrationTestRun contains name of test we want to trigger run
	SnapshotIntegrationTestRun = "test.appstudio.openshift.io/run"

	// AppstudioLabelPrefix contains application, component, build-pipelinerun etc.
	AppstudioLabelPrefix = "appstudio.openshift.io"

	// SnapshotLabel contains the name of the Snapshot within appstudio
	SnapshotLabel = "appstudio.openshift.io/snapshot"

	// SnapshotTestScenarioLabel contains the name of the Snapshot test scenario.
	SnapshotTestScenarioLabel = "test.appstudio.openshift.io/scenario"

	// SnapshotTestScenarioLabel contains json data with test results of the particular snapshot
	SnapshotTestsStatusAnnotation = "test.appstudio.openshift.io/status"

	// (Deprecated) SnapshotPRLastUpdate contains timestamp of last time PR was updated
	SnapshotPRLastUpdate = "test.appstudio.openshift.io/pr-last-update"

	// SnapshotStatusReportAnnotation contains metadata of tests related to status reporting to git provider
	SnapshotStatusReportAnnotation = "test.appstudio.openshift.io/git-reporter-status"

	// BuildPipelineRunPrefix contains the build pipeline run related labels and annotations
	BuildPipelineRunPrefix = "build.appstudio"

	// BuildPipelineRunFinishTimeLabel contains the build PipelineRun finish time of the Snapshot.
	BuildPipelineRunFinishTimeLabel = "test.appstudio.openshift.io/pipelinerunfinishtime"

	// BuildPipelineRunNameLabel contains the build PipelineRun name
	BuildPipelineRunNameLabel = AppstudioLabelPrefix + "/build-pipelinerun"

	// ApplicationNameLabel contains the name of the application
	ApplicationNameLabel = AppstudioLabelPrefix + "/application"

	// SnapshotComponentType is the type of Snapshot which was created for a single component build.
	SnapshotComponentType = "component"

	// SnapshotCompositeType is the type of Snapshot which was created for multiple components.
	SnapshotCompositeType = "composite"

	// PipelineAsCodeEventTypeLabel is the type of event which triggered the pipelinerun in build service
	PipelineAsCodeEventTypeLabel = PipelinesAsCodePrefix + "/event-type"

	// PipelineAsCodeGitProviderLabel is the git provider which triggered the pipelinerun in build service.
	PipelineAsCodeGitProviderLabel = PipelinesAsCodePrefix + "/git-provider"

	// PipelineAsCodeSHALabel is the commit which triggered the pipelinerun in build service.
	PipelineAsCodeSHALabel = PipelinesAsCodePrefix + "/sha"

	// PipelineAsCodeURLOrgLabel is the organization for the git repo which triggered the pipelinerun in build service.
	PipelineAsCodeURLOrgLabel = PipelinesAsCodePrefix + "/url-org"

	// PipelineAsCodeURLRepositoryLabel is the git repository which triggered the pipelinerun in build service.
	PipelineAsCodeURLRepositoryLabel = PipelinesAsCodePrefix + "/url-repository"

	// PipelineAsCodeRepoURLAnnotation is the URL to the git repository which triggered the pipelinerun in build service.
	PipelineAsCodeRepoURLAnnotation = PipelinesAsCodePrefix + "/repo-url"

	// PipelineAsCodeInstallationIDAnnotation is the GitHub App installation ID for the git repo which triggered the pipelinerun in build service.
	PipelineAsCodeInstallationIDAnnotation = PipelinesAsCodePrefix + "/installation-id"

	// PipelineAsCodePullRequestAnnotation is the git repository's pull request identifier
	PipelineAsCodePullRequestAnnotation = PipelinesAsCodePrefix + "/pull-request"

	// PipelineAsCodeSourceProjectIDAnnotation is the source project ID for gitlab
	PipelineAsCodeSourceProjectIDAnnotation = PipelinesAsCodePrefix + "/source-project-id"

	// PipelineAsCodeTargetProjectIDAnnotation is the target project ID for gitlab
	PipelineAsCodeTargetProjectIDAnnotation = PipelinesAsCodePrefix + "/target-project-id"

	// PipelineAsCodePushType is the type of push event which triggered the pipelinerun in build service
	PipelineAsCodePushType = "push"

	// PipelineAsCodeGLPushType is the type of gitlab push event which triggered the pipelinerun in build service
	PipelineAsCodeGLPushType = "Push"

	// PipelineAsCodePullRequestType is the type of pull_request event which triggered the pipelinerun in build service
	PipelineAsCodePullRequestType = "pull_request"

	// PipelineAsCodeMergeRequestType is the type of merge request event which triggered the pipelinerun in build service
	PipelineAsCodeMergeRequestType = "merge request"

	// PipelineAsCodeGitHubProviderType is the git provider type for a GitHub event which triggered the pipelinerun in build service.
	PipelineAsCodeGitHubProviderType = "github"

	// PipelineAsCodeGitHubProviderType is the git provider type for a GitHub event which triggered the pipelinerun in build service.
	PipelineAsCodeGitLabProviderType = "gitlab"

	//AppStudioTestSucceededCondition is the condition for marking if the AppStudio Tests succeeded for the Snapshot.
	AppStudioTestSucceededCondition = "AppStudioTestSucceeded"

	//LegacyTestSucceededCondition is the condition for marking if the AppStudio Tests succeeded for the Snapshot.
	LegacyTestSucceededCondition = "HACBSStudioTestSucceeded"

	// AppStudioIntegrationStatusCondition is the condition for marking the AppStudio integration status of the Snapshot.
	AppStudioIntegrationStatusCondition = "AppStudioIntegrationStatus"

	// LegacyIntegrationStatusCondition is the condition for marking the AppStudio integration status of the Snapshot.
	LegacyIntegrationStatusCondition = "HACBSIntegrationStatus"

	// SnapshotDeployedToRootEnvironmentsCondition is the condition for marking if Snapshot was deployed to root environments
	// within the user's workspace.
	SnapshotDeployedToRootEnvironmentsCondition = "DeployedToRootEnvironments"

	// SnapshotAutoReleasedCondition is the condition for marking if Snapshot was auto-released released with AppStudio.
	SnapshotAutoReleasedCondition = "AutoReleased"

	// SnapshotAddedToGlobalCandidateListCondition is the condition for marking if Snapshot's component was added to
	// the global candidate list.
	SnapshotAddedToGlobalCandidateListCondition = "AddedToGlobalCandidateList"

	// AppStudioTestSucceededConditionSatisfied is the reason that's set when the AppStudio tests succeed.
	AppStudioTestSucceededConditionSatisfied = "Passed"

	// AppStudioTestSucceededConditionFailed is the reason that's set when the AppStudio tests fail.
	AppStudioTestSucceededConditionFailed = "Failed"

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

	// AppStudioIntegrationStatusErrorOccured is the reason that's set when the AppStudio integration gets into an error state.
	AppStudioIntegrationStatusErrorOccured = "ErrorOccured"

	//AppStudioIntegrationStatusInProgress is the reason that's set when the AppStudio tests gets into an in progress state.
	AppStudioIntegrationStatusInProgress = "InProgress"

	//AppStudioIntegrationStatusFinished is the reason that's set when the AppStudio tests finish.
	AppStudioIntegrationStatusFinished = "Finished"

	// the statuses needed to report to GiHub when creating check run or commit status, see doc
	// https://docs.github.com/en/rest/guides/using-the-rest-api-to-interact-with-checks?apiVersion=2022-11-28
	// https://docs.github.com/en/free-pro-team@latest/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
	//IntegrationTestStatusPendingGithub is the status reported to github when integration test is in a queue
	IntegrationTestStatusPendingGithub = "pending"

	//IntegrationTestStatusSuccessGithub is the status reported to github when integration test succeed
	IntegrationTestStatusSuccessGithub = "success"

	//IntegrationTestStatusFailureGithub is the status reported to github when integration test fail
	IntegrationTestStatusFailureGithub = "failure"

	//IntegrationTestStatusErrorGithub is the status reported to github when integration test experience error
	IntegrationTestStatusErrorGithub = "error"

	//IntegrationTestStatusInProgressGithub is the status reported to github when integration test is in progress
	IntegrationTestStatusInProgressGithub = "in_progress"
)

Variables

View Source
var (
	// SnapshotComponentLabel contains the name of the updated Snapshot component - it should match the pipeline label.
	SnapshotComponentLabel = tekton.ComponentNameLabel
)

Functions

func AddIntegrationTestRerunLabel

func AddIntegrationTestRerunLabel(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, integrationTestScenarioName string) error

AddIntegrationTestRerunLabel adding re-run label to snapshot

func CanSnapshotBePromoted

func CanSnapshotBePromoted(snapshot *applicationapiv1alpha1.Snapshot) (bool, []string)

CanSnapshotBePromoted checks if the Snapshot in question can be promoted for deployment and release.

func CompareSnapshots

func CompareSnapshots(expectedSnapshot *applicationapiv1alpha1.Snapshot, foundSnapshot *applicationapiv1alpha1.Snapshot) bool

CompareSnapshots compares two Snapshots and returns boolean true if their images match exactly.

func CopySnapshotLabelsAndAnnotation

func CopySnapshotLabelsAndAnnotation(application *applicationapiv1alpha1.Application, snapshot *applicationapiv1alpha1.Snapshot, componentName string, source *metav1.ObjectMeta, prefix string, isComposite bool)

CopySnapshotLabelsAndAnnotation coppies labels and annotations from build pipelineRun or tested snapshot into regular or composite snapshot

func DeploymentFailedForIntegrationBindingPredicate

func DeploymentFailedForIntegrationBindingPredicate() predicate.Predicate

DeploymentFailedForIntegrationBindingPredicate returns a predicate which filters out update events to a SnapshotEnvironmentBinding that have resulted in a deployment failure.

func DeploymentSucceededForIntegrationBindingPredicate

func DeploymentSucceededForIntegrationBindingPredicate() predicate.Predicate

DeploymentSucceededForIntegrationBindingPredicate returns a predicate which filters out update events to a SnapshotEnvironmentBinding whose component deployment status goes from unknown/false to true.

func FindMatchingSnapshot

func FindMatchingSnapshot(application *applicationapiv1alpha1.Application, allSnapshots *[]applicationapiv1alpha1.Snapshot, expectedSnapshot *applicationapiv1alpha1.Snapshot) *applicationapiv1alpha1.Snapshot

FindMatchingSnapshot tries to find the expected Snapshot with the same set of images.

func GetAppStudioTestsFinishedTime

func GetAppStudioTestsFinishedTime(snapshot *applicationapiv1alpha1.Snapshot) (metav1.Time, bool)

GetAppStudioTestsFinishedTime finds the timestamp of tests succeeded condition

func GetBindingConditionStatus

func GetBindingConditionStatus(snapshotEnvironmentBinding *applicationapiv1alpha1.SnapshotEnvironmentBinding) *metav1.Condition

func GetComponentSourceFromComponent

func GetComponentSourceFromComponent(component *applicationapiv1alpha1.Component) *applicationapiv1alpha1.ComponentSource

GetComponentSourceFromComponent gets the component source from the given Component as Revision and set Component.Status.LastBuiltCommit as Component.Source.GitSource.Revision if it is defined.

func GetIntegrationTestRunLabelValue

func GetIntegrationTestRunLabelValue(obj metav1.Object) (string, bool)

GetIntegrationTestRunLabelValue returns value of the label responsible for re-running tests

func GetLatestUpdateTime

func GetLatestUpdateTime(snapshot *applicationapiv1alpha1.Snapshot) (time.Time, error)

Deprecated

func GetTestSucceededCondition

func GetTestSucceededCondition(snapshot *applicationapiv1alpha1.Snapshot) (condition *metav1.Condition, ok bool)

GetTestSucceededCondition checks status of tests on the snapshot

func HasSnapshotRerunLabelChanged

func HasSnapshotRerunLabelChanged(objectOld, objectNew client.Object) bool

HasSnapshotRerunLabelChanged returns a boolean indicating whether the Snapshot label for re-running integration test has changed. If the objects passed to this function are not Snapshots, the function will return false.

func HasSnapshotTestAnnotationChanged

func HasSnapshotTestAnnotationChanged(objectOld, objectNew client.Object) bool

HasSnapshotTestAnnotationChanged returns a boolean indicating whether the Snapshot annotation has changed. If the objects passed to this function are not Snapshots, the function will return false.

func HasSnapshotTestingChangedToFinished

func HasSnapshotTestingChangedToFinished(objectOld, objectNew client.Object) bool

HasSnapshotTestingChangedToFinished returns a boolean indicating whether the Snapshot testing status has changed to finished. If the objects passed to this function are not Snapshots, the function will return false.

func HaveAppStudioTestsFinished

func HaveAppStudioTestsFinished(snapshot *applicationapiv1alpha1.Snapshot) bool

HaveAppStudioTestsFinished checks if the AppStudio tests have finished by checking if the AppStudio Test Succeeded condition is set.

func HaveAppStudioTestsSucceeded

func HaveAppStudioTestsSucceeded(snapshot *applicationapiv1alpha1.Snapshot) bool

HaveAppStudioTestsSucceeded checks if the AppStudio tests have finished by checking if the AppStudio Test Succeeded condition is set.

func HaveBindingsFailed

func HaveBindingsFailed(snapshotEnvironmentBinding *applicationapiv1alpha1.SnapshotEnvironmentBinding) bool

func IntegrationSnapshotChangePredicate

func IntegrationSnapshotChangePredicate() predicate.Predicate

IntegrationSnapshotChangePredicate returns a predicate which filters out all objects except snapshot is deleted and requires HasSnapshotTestingChangedToFinished for update events.

func IntegrationSnapshotEnvironmentBindingPredicate

func IntegrationSnapshotEnvironmentBindingPredicate() predicate.Predicate

IntegrationSnapshotEnvironmentBindingPredicate returns a predicate which filters out update events to a SnapshotEnvironmentBinding associated with an IntegrationTestScenario.

func IsBindingDeployed

func IsBindingDeployed(snapshotEnvironmentBinding *applicationapiv1alpha1.SnapshotEnvironmentBinding) bool

func IsSnapshotCreatedByPACPushEvent

func IsSnapshotCreatedByPACPushEvent(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotCreatedByPACPushEvent checks if a snapshot has label PipelineAsCodeEventTypeLabel and with push value it the label doesn't exist for some manual snapshot

func IsSnapshotCreatedBySamePACEvent

func IsSnapshotCreatedBySamePACEvent(snapshot1, snapshot2 *applicationapiv1alpha1.Snapshot) bool

IsSnapshotCreatedBySamePACEvent checks if the two snapshot are created by the same PAC event or they don't have event type

func IsSnapshotError

func IsSnapshotError(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotError if the AppStudio Integration Status condition is in ErrorOcurred status.

func IsSnapshotIntegrationStatusMarkedAsFinished

func IsSnapshotIntegrationStatusMarkedAsFinished(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotIntegrationStatusMarkedAsFinished returns true if snapshot is marked as finished

func IsSnapshotMarkedAsAddedToGlobalCandidateList

func IsSnapshotMarkedAsAddedToGlobalCandidateList(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotMarkedAsAddedToGlobalCandidateList returns true if snapshot's component is marked as added to global candidate list

func IsSnapshotMarkedAsAutoReleased

func IsSnapshotMarkedAsAutoReleased(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotMarkedAsAutoReleased returns true if snapshot is marked as deployed to root environments

func IsSnapshotMarkedAsFailed

func IsSnapshotMarkedAsFailed(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotMarkedAsFailed returns true if snapshot is marked as failed

func IsSnapshotMarkedAsInvalid

func IsSnapshotMarkedAsInvalid(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotMarkedAsInvalid returns true if snapshot is marked as failed

func IsSnapshotMarkedAsPassed

func IsSnapshotMarkedAsPassed(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotMarkedAsPassed returns true if snapshot is marked as passed

func IsSnapshotNotStarted

func IsSnapshotNotStarted(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotNotStarted checks if the AppStudio Integration Status condition is not in progress status.

func IsSnapshotStatusConditionSet

func IsSnapshotStatusConditionSet(snapshot *applicationapiv1alpha1.Snapshot, conditionType string, conditionStatus metav1.ConditionStatus, reason string) bool

IsSnapshotStatusConditionSet checks if the condition with the conditionType in the status of Snapshot has been marked as the conditionStatus and reason.

func IsSnapshotValid

func IsSnapshotValid(snapshot *applicationapiv1alpha1.Snapshot) bool

IsSnapshotValid checks if the AppStudio Integration Status condition is not invalid.

func MarkSnapshotAsAddedToGlobalCandidateList

func MarkSnapshotAsAddedToGlobalCandidateList(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotAsAddedToGlobalCandidateList updates the SnapshotAddedToGlobalCandidateListCondition for the Snapshot to true with reason 'Added'. If the patch command fails, an error will be returned.

func MarkSnapshotAsAutoReleased

func MarkSnapshotAsAutoReleased(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotAsAutoReleased updates the SnapshotAutoReleasedCondition for the Snapshot to 'AutoReleased'. If the patch command fails, an error will be returned.

func MarkSnapshotAsFailed

func MarkSnapshotAsFailed(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotAsFailed updates the AppStudio Test succeeded condition for the Snapshot to failed. If the patch command fails, an error will be returned.

func MarkSnapshotAsInvalid

func MarkSnapshotAsInvalid(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotAsInvalid updates the AppStudio integration status condition for the Snapshot to invalid. If the patch command fails, an error will be returned.

func MarkSnapshotAsPassed

func MarkSnapshotAsPassed(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotAsPassed updates the AppStudio Test succeeded condition for the Snapshot to passed. If the patch command fails, an error will be returned.

func MarkSnapshotIntegrationStatusAsFinished

func MarkSnapshotIntegrationStatusAsFinished(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotIntegrationStatusAsFinished sets the AppStudio integration status condition for the Snapshot to Finished.

func MarkSnapshotIntegrationStatusAsInProgress

func MarkSnapshotIntegrationStatusAsInProgress(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

MarkSnapshotIntegrationStatusAsInProgress sets the AppStudio integration status condition for the Snapshot to In Progress.

func NewBindingComponents

NewBindingComponents gets all components from the Snapshot and formats them to be used in the SnapshotEnvironmentBinding as BindingComponents.

func NewSnapshot

NewSnapshot creates a new snapshot based on the supplied application and components

func NewSnapshotIntegrationTestStatusesFromSnapshot

func NewSnapshotIntegrationTestStatusesFromSnapshot(s *applicationapiv1alpha1.Snapshot) (*intgteststat.SnapshotIntegrationTestStatuses, error)

NewSnapshotIntegrationTestStatusesFromSnapshot creates new SnapshotTestStatus struct from snapshot annotation

func PrepareSnapshot

func PrepareSnapshot(adapterClient client.Client, ctx context.Context, application *applicationapiv1alpha1.Application, applicationComponents *[]applicationapiv1alpha1.Component, component *applicationapiv1alpha1.Component, newContainerImage string, newComponentSource *applicationapiv1alpha1.ComponentSource) (*applicationapiv1alpha1.Snapshot, error)

PrepareSnapshot prepares the Snapshot for a given application, components and the updated component (if any). In case the Snapshot can't be created, an error will be returned.

func PrepareToRegisterIntegrationPipelineRunStarted

func PrepareToRegisterIntegrationPipelineRunStarted(snapshot *applicationapiv1alpha1.Snapshot)

PrepareToRegisterIntegrationPipelineRunStarted is to do preparation before calling RegisterPipelineRunStarted Don't use this function for PLR re-runs

func RemoveIntegrationTestRerunLabel

func RemoveIntegrationTestRerunLabel(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot) error

RemoveIntegrationTestRerunLabel removes re-run label from snapshot

func ResetSnapshotStatusConditions

func ResetSnapshotStatusConditions(adapterClient client.Client, ctx context.Context, snapshot *applicationapiv1alpha1.Snapshot, message string) error

func SetSnapshotIntegrationStatusAsError

func SetSnapshotIntegrationStatusAsError(snapshot *applicationapiv1alpha1.Snapshot, message string)

SetSnapshotIntegrationStatusAsError sets the AppStudio integration status condition for the Snapshot to error.

func SetSnapshotIntegrationStatusAsInvalid

func SetSnapshotIntegrationStatusAsInvalid(snapshot *applicationapiv1alpha1.Snapshot, message string)

SetSnapshotIntegrationStatusAsInvalid sets the AppStudio integration status condition for the Snapshot to invalid.

func SnapshotIntegrationTestRerunTriggerPredicate

func SnapshotIntegrationTestRerunTriggerPredicate() predicate.Predicate

SnapshotIntegrationTestRerunTriggerPredicate returns a predicate which filters out all objects except when label for rerunning an integration test is added.

func SnapshotTestAnnotationChangePredicate

func SnapshotTestAnnotationChangePredicate() predicate.Predicate

SnapshotTestAnnotationChangePredicate returns a predicate which filters out all objects except when Snapshot annotation "test.appstudio.openshift.io/status" is changed for update events.

func ValidateImageDigest

func ValidateImageDigest(imageUrl string) error

ValidateImageDigest checks if image url contains valid digest, return error if check fails

func WriteIntegrationTestStatusesIntoSnapshot

func WriteIntegrationTestStatusesIntoSnapshot(s *applicationapiv1alpha1.Snapshot, sts *intgteststat.SnapshotIntegrationTestStatuses, c client.Client, ctx context.Context) error

WriteIntegrationTestStatusesIntoSnapshot writes data to snapshot by updating CR Data are written only when new changes are detected

Types

This section is empty.

Jump to

Keyboard shortcuts

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