Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RELEASE-1109): allow tenant and managed pipelines to run #549

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions api/v1alpha1/release_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package v1alpha1
import "github.com/konflux-ci/operator-toolkit/conditions"

const (
// managedProcessedConditionType is the type used to track the status of a Release Managed Pipeline processing
managedProcessedConditionType conditions.ConditionType = "ManagedPipelineProcessed"
davidmogar marked this conversation as resolved.
Show resolved Hide resolved

// postActionsExecutedConditionType is the type used to track the status of Release post-actions
postActionsExecutedConditionType conditions.ConditionType = "PostActionsExecuted"

// processedConditionType is the type used to track the status of a Release processing
processedConditionType conditions.ConditionType = "Processed"
// tenantProcessedConditionType is the type used to track the status of a Release Tenant Pipeline processing
tenantProcessedConditionType conditions.ConditionType = "TenantPipelineProcessed"

// releasedConditionType is the type used to track the status of a Release
releasedConditionType conditions.ConditionType = "Released"
Expand All @@ -20,9 +23,12 @@ const (
// FailedReason is the reason set when a failure occurs
FailedReason conditions.ConditionReason = "Failed"

// ProgressingReason is the reason set when an action is progressing
// ProgressingReason is the reason set when a phase is progressing
ProgressingReason conditions.ConditionReason = "Progressing"

// SucceededReason is the reason set when an action succeeds
// SkippedReason is the reason set when a phase is skipped
davidmogar marked this conversation as resolved.
Show resolved Hide resolved
SkippedReason conditions.ConditionReason = "Skipped"

// SucceededReason is the reason set when a phase succeeds
SucceededReason conditions.ConditionReason = "Succeeded"
)
195 changes: 142 additions & 53 deletions api/v1alpha1/release_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/konflux-ci/operator-toolkit/conditions"

"github.com/konflux-ci/release-service/metadata"
"github.com/konflux-ci/release-service/metrics"
"k8s.io/apimachinery/pkg/runtime"

Expand Down Expand Up @@ -66,13 +67,17 @@ type ReleaseStatus struct {
// +optional
Conditions []metav1.Condition `json:"conditions"`

// ManagedProcessing contains information about the release managed processing
// +optional
ManagedProcessing PipelineInfo `json:"managedProcessing,omitempty"`
davidmogar marked this conversation as resolved.
Show resolved Hide resolved

// PostActionsExecution contains information about the post-actions execution
// +optional
PostActionsExecution PostActionsExecutionInfo `json:"postActionsExecution,omitempty"`
PostActionsExecution PipelineInfo `json:"postActionsExecution,omitempty"`

// Processing contains information about the release processing
// TenantProcessing contains information about the release tenant processing
// +optional
Processing ProcessingInfo `json:"processing,omitempty"`
TenantProcessing PipelineInfo `json:"tenantProcessing,omitempty"`

// Validation contains information about the release validation
// +optional
Expand Down Expand Up @@ -111,19 +116,8 @@ type AttributionInfo struct {
StandingAuthorization bool `json:"standingAuthorization,omitempty"`
}

// PostActionsExecutionInfo defines the observed state of the post-actions execution.
type PostActionsExecutionInfo struct {
// CompletionTime is the time when the Release post-actions execution was completed
// +optional
CompletionTime *metav1.Time `json:"completionTime,omitempty"`

// StartTime is the time when the Release post-actions execution started
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`
}

// ProcessingInfo defines the observed state of the release processing.
type ProcessingInfo struct {
// PipelineInfo defines the observed state of a release pipeline processing.
type PipelineInfo struct {
// CompletionTime is the time when the Release processing was completed
// +optional
CompletionTime *metav1.Time `json:"completionTime,omitempty"`
Expand Down Expand Up @@ -177,9 +171,14 @@ func (r *Release) HasEveryPostActionExecutionFinished() bool {
return r.hasPhaseFinished(postActionsExecutedConditionType)
}

// HasProcessingFinished checks whether the Release processing has finished, regardless of the result.
func (r *Release) HasProcessingFinished() bool {
return r.hasPhaseFinished(processedConditionType)
// HasManagedPipelineProcessingFinished checks whether the Release Managed Pipeline processing has finished, regardless of the result.
func (r *Release) HasManagedPipelineProcessingFinished() bool {
return r.hasPhaseFinished(managedProcessedConditionType)
}

// HasTenantPipelineProcessingFinished checks whether the Release Tenant Pipeline processing has finished, regardless of the result.
func (r *Release) HasTenantPipelineProcessingFinished() bool {
return r.hasPhaseFinished(tenantProcessedConditionType)
}

// HasReleaseFinished checks whether the Release has finished, regardless of the result.
Expand Down Expand Up @@ -207,14 +206,24 @@ func (r *Release) IsEachPostActionExecuting() bool {
return r.isPhaseProgressing(postActionsExecutedConditionType)
}

// IsProcessed checks whether the Release was successfully processed.
func (r *Release) IsProcessed() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, processedConditionType.String())
// IsManagedPipelineProcessed checks whether the Release Managed Pipeline was successfully processed.
func (r *Release) IsManagedPipelineProcessed() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, managedProcessedConditionType.String())
}

// IsTenantPipelineProcessed checks whether the Release Tenant Pipeline was successfully processed.
func (r *Release) IsTenantPipelineProcessed() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, tenantProcessedConditionType.String())
}

// IsManagedPipelineProcessing checks whether the Release Managed Pipeline processing is in progress.
func (r *Release) IsManagedPipelineProcessing() bool {
return r.isPhaseProgressing(managedProcessedConditionType)
}

// IsProcessing checks whether the Release processing is in progress.
func (r *Release) IsProcessing() bool {
return r.isPhaseProgressing(processedConditionType)
// IsTenantPipelineProcessing checks whether the Release Tenant Pipeline processing is in progress.
func (r *Release) IsTenantPipelineProcessing() bool {
return r.isPhaseProgressing(tenantProcessedConditionType)
}

// IsReleased checks whether the Release has finished successfully.
Expand All @@ -232,60 +241,138 @@ func (r *Release) IsValid() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, validatedConditionType.String())
}

// MarkProcessed marks the Release as processed.
func (r *Release) MarkProcessed() {
if !r.IsProcessing() || r.HasProcessingFinished() {
// MarkManagedPipelineProcessed marks the Release Managed Pipeline as processed.
func (r *Release) MarkManagedPipelineProcessed() {
if !r.IsManagedPipelineProcessing() || r.HasManagedPipelineProcessingFinished() {
return
}

r.Status.Processing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, processedConditionType, metav1.ConditionTrue, SucceededReason)
r.Status.ManagedProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionTrue, SucceededReason)

go metrics.RegisterCompletedReleaseProcessing(
r.Status.Processing.StartTime,
r.Status.Processing.CompletionTime,
go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.ManagedProcessing.StartTime,
r.Status.ManagedProcessing.CompletionTime,
SucceededReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

// MarkProcessing marks the Release as processing.
func (r *Release) MarkProcessing(message string) {
if r.HasProcessingFinished() {
// MarkTenantPipelineProcessed marks the Release Tenant Pipeline as processed.
func (r *Release) MarkTenantPipelineProcessed() {
if !r.IsTenantPipelineProcessing() || r.HasTenantPipelineProcessingFinished() {
return
}

if !r.IsProcessing() {
r.Status.Processing.StartTime = &metav1.Time{Time: time.Now()}
r.Status.TenantProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionTrue, SucceededReason)

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.TenantProcessing.StartTime,
r.Status.TenantProcessing.CompletionTime,
SucceededReason.String(),
r.Status.Target,
metadata.TenantPipelineType,
)
}

// MarkManagedPipelineProcessing marks the Release Managed Pipeline as processing.
func (r *Release) MarkManagedPipelineProcessing() {
if r.HasManagedPipelineProcessingFinished() {
return
}

conditions.SetConditionWithMessage(&r.Status.Conditions, processedConditionType, metav1.ConditionFalse, ProgressingReason, message)
if !r.IsManagedPipelineProcessing() {
r.Status.ManagedProcessing.StartTime = &metav1.Time{Time: time.Now()}
}

conditions.SetCondition(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionFalse, ProgressingReason)

go metrics.RegisterNewReleaseProcessing(
r.Status.Processing.StartTime,
go metrics.RegisterNewReleasePipelineProcessing(
r.Status.ManagedProcessing.StartTime,
r.Status.StartTime,
ProgressingReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

// MarkProcessingFailed marks the Release processing as failed.
func (r *Release) MarkProcessingFailed(message string) {
if !r.IsProcessing() || r.HasProcessingFinished() {
// MarkTenantPipelineProcessing marks the Release Tenant Pipeline as processing.
func (r *Release) MarkTenantPipelineProcessing() {
if r.HasTenantPipelineProcessingFinished() {
return
}

r.Status.Processing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetConditionWithMessage(&r.Status.Conditions, processedConditionType, metav1.ConditionFalse, FailedReason, message)
if !r.IsTenantPipelineProcessing() {
r.Status.TenantProcessing.StartTime = &metav1.Time{Time: time.Now()}
}

conditions.SetCondition(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionFalse, ProgressingReason)

go metrics.RegisterCompletedReleaseProcessing(
r.Status.Processing.StartTime,
r.Status.Processing.CompletionTime,
go metrics.RegisterNewReleasePipelineProcessing(
r.Status.TenantProcessing.StartTime,
r.Status.StartTime,
ProgressingReason.String(),
r.Status.Target,
metadata.TenantPipelineType,
)
}

// MarkManagedPipelineProcessingFailed marks the Release Managed Pipeline processing as failed.
func (r *Release) MarkManagedPipelineProcessingFailed(message string) {
if !r.IsManagedPipelineProcessing() || r.HasManagedPipelineProcessingFinished() {
return
}

r.Status.ManagedProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetConditionWithMessage(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionFalse, FailedReason, message)

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.ManagedProcessing.StartTime,
r.Status.ManagedProcessing.CompletionTime,
FailedReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

// MarkTenantPipelineProcessingFailed marks the Release Tenant Pipeline processing as failed.
func (r *Release) MarkTenantPipelineProcessingFailed(message string) {
if !r.IsTenantPipelineProcessing() || r.HasTenantPipelineProcessingFinished() {
return
}

r.Status.TenantProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetConditionWithMessage(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionFalse, FailedReason, message)

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.TenantProcessing.StartTime,
r.Status.TenantProcessing.CompletionTime,
FailedReason.String(),
r.Status.Target,
metadata.TenantPipelineType,
)
}

// MarkManagedPipelineProcessingSkipped marks the Release Managed Pipeline processing as skipped.
func (r *Release) MarkManagedPipelineProcessingSkipped() {
if r.HasManagedPipelineProcessingFinished() {
return
}

conditions.SetCondition(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionTrue, SkippedReason)
}

// MarkTenantPipelineProcessingSkipped marks the Release Tenant Pipeline processing as skipped.
func (r *Release) MarkTenantPipelineProcessingSkipped() {
if r.HasTenantPipelineProcessingFinished() {
return
}

conditions.SetCondition(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionTrue, SkippedReason)
}

// MarkPostActionsExecuted marks the Release post-actions as executed.
func (r *Release) MarkPostActionsExecuted() {
if !r.IsEachPostActionExecuting() || r.HasEveryPostActionExecutionFinished() {
Expand Down Expand Up @@ -327,8 +414,8 @@ func (r *Release) MarkPostActionsExecutionFailed(message string) {
conditions.SetConditionWithMessage(&r.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionFalse, FailedReason, message)

go metrics.RegisterCompletedReleasePostActionsExecuted(
r.Status.Processing.StartTime,
r.Status.Processing.CompletionTime,
r.Status.PostActionsExecution.StartTime,
r.Status.PostActionsExecution.CompletionTime,
FailedReason.String(),
)
}
Expand All @@ -345,10 +432,11 @@ func (r *Release) MarkReleased() {
go metrics.RegisterCompletedRelease(
r.Status.StartTime,
r.Status.CompletionTime,
r.getPhaseReason(managedProcessedConditionType),
r.getPhaseReason(postActionsExecutedConditionType),
r.getPhaseReason(processedConditionType),
SucceededReason.String(),
r.Status.Target,
r.getPhaseReason(tenantProcessedConditionType),
r.getPhaseReason(validatedConditionType),
)
}
Expand Down Expand Up @@ -381,7 +469,8 @@ func (r *Release) MarkReleaseFailed(message string) {
r.Status.StartTime,
r.Status.CompletionTime,
r.getPhaseReason(postActionsExecutedConditionType),
r.getPhaseReason(processedConditionType),
r.getPhaseReason(tenantProcessedConditionType),
r.getPhaseReason(managedProcessedConditionType),
FailedReason.String(),
r.Status.Target,
r.getPhaseReason(validatedConditionType),
Expand Down
Loading
Loading