func()

in controllers/cdstagedeploy/chain/resolve_status.go [118:158]


func (r *ResolveStatus) shouldStartCDStageDeploy(
	ctx context.Context,
	currentCDStageDeployName, stage, pipeline, namespace string,
	pipelines []tektonpipelineApi.PipelineRun,
) (bool, error) {
	log := ctrl.LoggerFrom(ctx)

	if !allPipelineRunsCompleted(pipelines) {
		log.Info("Some PipelineRuns are still running.")

		return false, nil
	}

	cdStageDeploy := &codebaseApi.CDStageDeployList{}

	if err := r.client.List(
		ctx,
		cdStageDeploy,
		client.InNamespace(namespace),
		client.MatchingLabels{
			codebaseApi.CdPipelineLabel: pipeline,
			codebaseApi.CdStageLabel:    stage,
		},
	); err != nil {
		return false, fmt.Errorf("failed to list CDStageDeploys: %w", err)
	}

	if !allCdStageDeploysInQue(cdStageDeploy) {
		log.Info("Some CDStageDeploys are processing.")

		return false, nil
	}

	if !isFirsCdStageDeployInQue(cdStageDeploy, currentCDStageDeployName) {
		log.Info("Another CDStageDeploys is in queue before current.")

		return false, nil
	}

	return true, nil
}