Skip to content

Commit

Permalink
feat(RELEASE-914): add collectors phase
Browse files Browse the repository at this point in the history
This change enables the execution of the collectors pipeline.

Signed-off-by: David Moreno García <[email protected]>
  • Loading branch information
davidmogar committed Oct 23, 2024
1 parent a103042 commit db69aa6
Show file tree
Hide file tree
Showing 19 changed files with 2,041 additions and 147 deletions.
18 changes: 16 additions & 2 deletions api/v1alpha1/collectors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package v1alpha1

// Collector represents a reference to a Collector to be executed as part of the release workflow.
// Collectors holds the list of collectors to be executed as part of the release workflow along with the
// ServiceAccount to be used in the PipelineRun.
// +kubebuilder:object:generate=true
type Collector struct {
type Collectors struct {
// Items is the list of Collectors to be executed as part of the release workflow
// +required
Items []CollectorItem `json:"items"`

// ServiceAccountName is the ServiceAccount to use during the execution of the Collectors Pipeline
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}

// CollectorItem represents all the information about an specific collector which will be executed in the
// CollectorsPipeline.
type CollectorItem struct {
// Name of the collector
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
// +required
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/release_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ const (
// finalProcessedConditionType is the type used to track the status of a Release Final Pipeline processing
finalProcessedConditionType conditions.ConditionType = "FinalPipelineProcessed"

// managedCollectorsProcessedConditionType is the type used to track the status of a Release Managed Collectors Pipeline processing
managedCollectorsProcessedConditionType conditions.ConditionType = "ManagedCollectorsPipelineProcessed"

// managedProcessedConditionType is the type used to track the status of a Release Managed Pipeline processing
managedProcessedConditionType conditions.ConditionType = "ManagedPipelineProcessed"

// tenantCollectorsProcessedConditionType is the type used to track the status of a Release Tenant Collectors Pipeline processing
tenantCollectorsProcessedConditionType conditions.ConditionType = "TenantCollectorsPipelineProcessed"

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

Expand Down
188 changes: 182 additions & 6 deletions api/v1alpha1/release_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type ReleaseStatus struct {
// +optional
Conditions []metav1.Condition `json:"conditions"`

// CollectorsProcessing contains information about the release collectors processing
// +optional
CollectorsProcessing CollectorsInfo `json:"collectorsProcessing,omitempty"`

// FinalProcessing contains information about the release final processing
// +optional
FinalProcessing PipelineInfo `json:"finalProcessing,omitempty"`
Expand Down Expand Up @@ -121,6 +125,12 @@ type AttributionInfo struct {
StandingAuthorization bool `json:"standingAuthorization,omitempty"`
}

type CollectorsInfo struct {
ManagedCollectorsProcessing PipelineInfo `json:"managedCollectorsProcessing,omitempty"`

TenantCollectorsProcessing PipelineInfo `json:"tenantCollectorsProcessing,omitempty"`
}

// PipelineInfo defines the observed state of a release pipeline processing.
type PipelineInfo struct {
// CompletionTime is the time when the Release processing was completed
Expand Down Expand Up @@ -175,11 +185,21 @@ func (r *Release) HasFinalPipelineProcessingFinished() bool {
return r.hasPhaseFinished(finalProcessedConditionType)
}

// HasManagedCollectorsPipelineProcessingFinished checks whether the Release Managed Collectors Pipeline processing has finished, regardless of the result.
func (r *Release) HasManagedCollectorsPipelineProcessingFinished() bool {
return r.hasPhaseFinished(managedCollectorsProcessedConditionType)
}

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

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

// HasTenantPipelineProcessingFinished checks whether the Release Tenant Pipeline processing has finished, regardless of the result.
func (r *Release) HasTenantPipelineProcessingFinished() bool {
return r.hasPhaseFinished(tenantProcessedConditionType)
Expand All @@ -205,11 +225,21 @@ func (r *Release) IsFinalPipelineProcessed() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, finalProcessedConditionType.String())
}

// IsManagedCollectorsPipelineProcessed checks whether the Release Managed Collectors Pipeline was successfully processed.
func (r *Release) IsManagedCollectorsPipelineProcessed() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, managedCollectorsProcessedConditionType.String())
}

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

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

// IsTenantPipelineProcessed checks whether the Release Tenant Pipeline was successfully processed.
func (r *Release) IsTenantPipelineProcessed() bool {
return meta.IsStatusConditionTrue(r.Status.Conditions, tenantProcessedConditionType.String())
Expand All @@ -220,11 +250,21 @@ func (r *Release) IsFinalPipelineProcessing() bool {
return r.isPhaseProgressing(finalProcessedConditionType)
}

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

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

// IsTenantCollectorsPipelineProcessing checks whether the Release Tenant Collectors Pipeline processing is in progress.
func (r *Release) IsTenantCollectorsPipelineProcessing() bool {
return r.isPhaseProgressing(tenantCollectorsProcessedConditionType)
}

// IsTenantPipelineProcessing checks whether the Release Tenant Pipeline processing is in progress.
func (r *Release) IsTenantPipelineProcessing() bool {
return r.isPhaseProgressing(tenantProcessedConditionType)
Expand Down Expand Up @@ -263,6 +303,24 @@ func (r *Release) MarkFinalPipelineProcessed() {
)
}

// MarkManagedCollectorsPipelineProcessed marks the Release Managed Collectors Pipeline as processed.
func (r *Release) MarkManagedCollectorsPipelineProcessed() {
if !r.IsManagedCollectorsPipelineProcessing() || r.HasManagedCollectorsPipelineProcessingFinished() {
return
}

r.Status.CollectorsProcessing.ManagedCollectorsProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, managedCollectorsProcessedConditionType, metav1.ConditionTrue, SucceededReason)

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.CollectorsProcessing.ManagedCollectorsProcessing.StartTime,
r.Status.CollectorsProcessing.ManagedCollectorsProcessing.CompletionTime,
SucceededReason.String(),
r.Status.Target,
metadata.ManagedCollectorsPipelineType,
)
}

// MarkManagedPipelineProcessed marks the Release Managed Pipeline as processed.
func (r *Release) MarkManagedPipelineProcessed() {
if !r.IsManagedPipelineProcessing() || r.HasManagedPipelineProcessingFinished() {
Expand All @@ -281,6 +339,24 @@ func (r *Release) MarkManagedPipelineProcessed() {
)
}

// MarkTenantCollectorsPipelineProcessed marks the Release Tenant Collectors Pipeline as processed.
func (r *Release) MarkTenantCollectorsPipelineProcessed() {
if !r.IsTenantCollectorsPipelineProcessing() || r.HasTenantCollectorsPipelineProcessingFinished() {
return
}

r.Status.CollectorsProcessing.TenantCollectorsProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, tenantCollectorsProcessedConditionType, metav1.ConditionTrue, SucceededReason)

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.CollectorsProcessing.TenantCollectorsProcessing.StartTime,
r.Status.CollectorsProcessing.TenantCollectorsProcessing.CompletionTime,
SucceededReason.String(),
r.Status.Target,
metadata.TenantCollectorsPipelineType,
)
}

// MarkTenantPipelineProcessed marks the Release Tenant Pipeline as processed.
func (r *Release) MarkTenantPipelineProcessed() {
if !r.IsTenantPipelineProcessing() || r.HasTenantPipelineProcessingFinished() {
Expand Down Expand Up @@ -320,6 +396,27 @@ func (r *Release) MarkFinalPipelineProcessing() {
)
}

// MarkManagedCollectorsPipelineProcessing marks the Release Managed Collectors Pipeline as processing.
func (r *Release) MarkManagedCollectorsPipelineProcessing() {
if r.HasManagedCollectorsPipelineProcessingFinished() {
return
}

if !r.IsManagedCollectorsPipelineProcessing() {
r.Status.CollectorsProcessing.ManagedCollectorsProcessing.StartTime = &metav1.Time{Time: time.Now()}
}

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

go metrics.RegisterNewReleasePipelineProcessing(
r.Status.CollectorsProcessing.ManagedCollectorsProcessing.StartTime,
r.Status.StartTime,
ProgressingReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

// MarkManagedPipelineProcessing marks the Release Managed Pipeline as processing.
func (r *Release) MarkManagedPipelineProcessing() {
if r.HasManagedPipelineProcessingFinished() {
Expand All @@ -341,6 +438,27 @@ func (r *Release) MarkManagedPipelineProcessing() {
)
}

// MarkTenantCollectorsPipelineProcessing marks the Release Tenant Collectors Pipeline as processing.
func (r *Release) MarkTenantCollectorsPipelineProcessing() {
if r.HasTenantCollectorsPipelineProcessingFinished() {
return
}

if !r.IsTenantCollectorsPipelineProcessing() {
r.Status.CollectorsProcessing.TenantCollectorsProcessing.StartTime = &metav1.Time{Time: time.Now()}
}

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

go metrics.RegisterNewReleasePipelineProcessing(
r.Status.CollectorsProcessing.TenantCollectorsProcessing.StartTime,
r.Status.StartTime,
ProgressingReason.String(),
r.Status.Target,
metadata.TenantCollectorsPipelineType,
)
}

// MarkTenantPipelineProcessing marks the Release Tenant Pipeline as processing.
func (r *Release) MarkTenantPipelineProcessing() {
if r.HasTenantPipelineProcessingFinished() {
Expand Down Expand Up @@ -380,6 +498,24 @@ func (r *Release) MarkFinalPipelineProcessingFailed(message string) {
)
}

// MarkManagedCollectorsPipelineProcessingFailed marks the Release Managed Collectors Pipeline processing as failed.
func (r *Release) MarkManagedCollectorsPipelineProcessingFailed(message string) {
if !r.IsManagedCollectorsPipelineProcessing() || r.HasManagedCollectorsPipelineProcessingFinished() {
return
}

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

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.CollectorsProcessing.ManagedCollectorsProcessing.StartTime,
r.Status.CollectorsProcessing.ManagedCollectorsProcessing.CompletionTime,
FailedReason.String(),
r.Status.Target,
metadata.ManagedCollectorsPipelineType,
)
}

// MarkManagedPipelineProcessingFailed marks the Release Managed Pipeline processing as failed.
func (r *Release) MarkManagedPipelineProcessingFailed(message string) {
if !r.IsManagedPipelineProcessing() || r.HasManagedPipelineProcessingFinished() {
Expand All @@ -398,6 +534,24 @@ func (r *Release) MarkManagedPipelineProcessingFailed(message string) {
)
}

// MarkTenantCollectorsPipelineProcessingFailed marks the Release Tenant Collectors Pipeline processing as failed.
func (r *Release) MarkTenantCollectorsPipelineProcessingFailed(message string) {
if !r.IsTenantCollectorsPipelineProcessing() || r.HasTenantCollectorsPipelineProcessingFinished() {
return
}

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

go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.CollectorsProcessing.TenantCollectorsProcessing.StartTime,
r.Status.CollectorsProcessing.TenantCollectorsProcessing.CompletionTime,
FailedReason.String(),
r.Status.Target,
metadata.TenantCollectorsPipelineType,
)
}

// MarkTenantPipelineProcessingFailed marks the Release Tenant Pipeline processing as failed.
func (r *Release) MarkTenantPipelineProcessingFailed(message string) {
if !r.IsTenantPipelineProcessing() || r.HasTenantPipelineProcessingFinished() {
Expand Down Expand Up @@ -425,6 +579,15 @@ func (r *Release) MarkFinalPipelineProcessingSkipped() {
conditions.SetCondition(&r.Status.Conditions, finalProcessedConditionType, metav1.ConditionTrue, SkippedReason)
}

// MarkManagedCollectorsPipelineProcessingSkipped marks the Release Managed Collectors Pipeline processing as skipped.
func (r *Release) MarkManagedCollectorsPipelineProcessingSkipped() {
if r.HasManagedCollectorsPipelineProcessingFinished() {
return
}

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

// MarkManagedPipelineProcessingSkipped marks the Release Managed Pipeline processing as skipped.
func (r *Release) MarkManagedPipelineProcessingSkipped() {
if r.HasManagedPipelineProcessingFinished() {
Expand All @@ -434,6 +597,15 @@ func (r *Release) MarkManagedPipelineProcessingSkipped() {
conditions.SetCondition(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionTrue, SkippedReason)
}

// MarkTenantCollectorsPipelineProcessingSkipped marks the Release Tenant Collectors Pipeline processing as skipped.
func (r *Release) MarkTenantCollectorsPipelineProcessingSkipped() {
if r.HasTenantCollectorsPipelineProcessingFinished() {
return
}

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

// MarkTenantPipelineProcessingSkipped marks the Release Tenant Pipeline processing as skipped.
func (r *Release) MarkTenantPipelineProcessingSkipped() {
if r.HasTenantPipelineProcessingFinished() {
Expand All @@ -455,12 +627,14 @@ func (r *Release) MarkReleased() {
go metrics.RegisterCompletedRelease(
r.Status.StartTime,
r.Status.CompletionTime,
r.getPhaseReason(finalProcessedConditionType),
r.getPhaseReason(managedCollectorsProcessedConditionType),
r.getPhaseReason(managedProcessedConditionType),
SucceededReason.String(),
r.Status.Target,
r.getPhaseReason(tenantCollectorsProcessedConditionType),
r.getPhaseReason(tenantProcessedConditionType),
r.getPhaseReason(finalProcessedConditionType),
r.getPhaseReason(validatedConditionType),
SucceededReason.String(),
r.Status.Target,
)
}

Expand Down Expand Up @@ -491,12 +665,14 @@ func (r *Release) MarkReleaseFailed(message string) {
go metrics.RegisterCompletedRelease(
r.Status.StartTime,
r.Status.CompletionTime,
r.getPhaseReason(tenantProcessedConditionType),
r.getPhaseReason(managedProcessedConditionType),
r.getPhaseReason(finalProcessedConditionType),
r.getPhaseReason(managedCollectorsProcessedConditionType),
r.getPhaseReason(managedProcessedConditionType),
r.getPhaseReason(tenantCollectorsProcessedConditionType),
r.getPhaseReason(tenantProcessedConditionType),
r.getPhaseReason(validatedConditionType),
FailedReason.String(),
r.Status.Target,
r.getPhaseReason(validatedConditionType),
)
}

Expand Down
Loading

0 comments on commit db69aa6

Please sign in to comment.