diff --git a/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go b/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go index 9ce98ad9..2fa046a7 100644 --- a/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go +++ b/cli/sfconfig/cmd/bootstrap-tenant-config-repo/bootstrap-tenant-config-repo.go @@ -142,7 +142,7 @@ pipeline to receive an initial +/-1 Verified vote.`, Approval: []utils.PipelineRequireApproval{ { Username: "zuul", - Verified: []utils.GerritReporter{ + Verified: []utils.GerritVotePoint{ utils.GetZuulPipelineReporterVerified("-1"), utils.GetZuulPipelineReporterVerified("-2"), }, diff --git a/controllers/git_server.go b/controllers/git_server.go index 391ee8db..3f6b3ed4 100644 --- a/controllers/git_server.go +++ b/controllers/git_server.go @@ -116,11 +116,204 @@ func (r *SFController) makePreInitScript() string { }, } + pipelines := zuulcf.PipelineConfig{ + { + Pipeline: zuulcf.PipelineBody{ + Name: "post", + PostReview: true, + Description: "This pipeline runs jobs that operate after each change is merged.", + Manager: zuulcf.Supercedent, + Precedence: zuulcf.Low, + Trigger: zuulcf.PipelineGenericTrigger{ + "git-server": zuulcf.PipelineTriggerGitArray{ + { + Event: "ref-updated", + }, + }, + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerGitArray{ + { + Event: "ref-updated", + Ref: []string{ + "^refs/heads/.*$", + }, + }, + }, + }, + }, + }, + { + Pipeline: zuulcf.PipelineBody{ + Name: "check", + Description: "Newly uploaded patchsets enter this pipeline to receive an initial +/-1 Verified vote.", + Manager: zuulcf.Independent, + Require: zuulcf.PipelineRequire{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineRequireApproval{ + Open: true, + CurrentPatchset: true, + }, + }, + Trigger: zuulcf.PipelineGenericTrigger{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerGitArray{ + { + Event: "patchset-created", + }, + { + Event: "change-restored", + }, + { + Event: "comment-added", + Comment: "(?i)^(Patch Set [0-9]+:)?( [\\w\\+-]*)*(\\n\\n)?\\s*(recheck|reverify)", + }, + { + Event: "comment-added", + Gerrit: zuulcf.PipelineTriggerGitGerrit{ + Approval: []zuulcf.PipelineRequireApproval{ + { + Verified: []zuulcf.GerritVotePoint{ + zuulcf.GerritVotePointMinusOne, + zuulcf.GerritVotePointMinusTwo, + }, + Username: "zuul", + }, + }, + }, + Approval: []zuulcf.PipelineRequireGerritApproval{ + { + Workflow: zuulcf.GetGerritWorkflowValue("1"), + }, + }, + }, + }, + }, + Start: zuulcf.PipelineReporter{ + GerritReporter: zuulcf.GerritReporterMap{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointZero, + }, + }, + }, + Success: zuulcf.PipelineReporter{ + GerritReporter: zuulcf.GerritReporterMap{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointOne, + }, + }, + }, + Failure: zuulcf.PipelineReporter{ + GerritReporter: zuulcf.GerritReporterMap{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointMinusOne, + }, + }, + }, + }, + }, + { + Pipeline: zuulcf.PipelineBody{ + Name: "gate", + Description: "Changes that have been approved by core developers are enqueued in order in this pipeline, and if they pass tests, will be merged.", + SuccessMessage: "Build succeeded (gate pipeline).", + FailureMessage: "Build failed (gate pipeline).", + Manager: zuulcf.Dependent, + Precedence: zuulcf.High, + Supercedes: []string{ + "check", + }, + PostReview: true, + Require: zuulcf.PipelineRequire{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineRequireApproval{ + Open: true, + CurrentPatchset: true, + GerritApproval: []zuulcf.PipelineRequireGerritApproval{ + { + Workflow: zuulcf.GetGerritWorkflowValue("1"), + }, + }, + }, + }, + Trigger: zuulcf.PipelineGenericTrigger{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerGitArray{ + { + Event: "comment-added", + Approval: []zuulcf.PipelineRequireGerritApproval{ + { + Workflow: zuulcf.GetGerritWorkflowValue("1"), + }, + }, + }, + { + Event: "comment-added", + Approval: []zuulcf.PipelineRequireGerritApproval{ + { + Verified: zuulcf.GerritVotePointOne, + }, + }, + Username: "zuul", + }, + }, + }, + Start: zuulcf.PipelineReporter{ + GerritReporter: zuulcf.GerritReporterMap{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointZero, + }, + }, + }, + Success: zuulcf.PipelineReporter{ + GerritReporter: zuulcf.GerritReporterMap{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointTwo, + Submit: true, + }, + }, + }, + Failure: zuulcf.PipelineReporter{ + GerritReporter: zuulcf.GerritReporterMap{ + r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{ + Verified: zuulcf.GerritVotePointMinusTwo, + }, + }, + }, + WindowFloor: 20, + WindowIncreaseFactor: 2, + }, + }, + } + + projects := zuulcf.ProjectConfig{ + { + Project: zuulcf.ZuulProjectBody{ + Name: r.cr.Spec.ConfigLocation.Name, + Pipeline: zuulcf.ZuulProjectPipelineMap{ + "check": zuulcf.ZuulProjectPipeline{ + Jobs: []string{ + "config-check", + }, + }, + "gate": zuulcf.ZuulProjectPipeline{ + Jobs: []string{ + "config-check", + }, + }, + "post": zuulcf.ZuulProjectPipeline{ + Jobs: []string{ + "config-update", + }, + }, + }, + }, + }, + } + semaphoreOutput, _ := yaml.Marshal(semaphore) jobbaseOutput, _ := yaml.Marshal(jobs) + pipelineOutput, _ := yaml.Marshal(pipelines) + projectOutput, _ := yaml.Marshal(projects) - preInitScriptTemplate = strings.Replace(preInitScriptTemplate, "# Semaphore", string(semaphoreOutput), 1) - preInitScriptTemplate = strings.Replace(preInitScriptTemplate, "# JobBase", string(jobbaseOutput), 1) + preInitScriptTemplate = strings.Replace(preInitScriptTemplate, "# Semaphores", string(semaphoreOutput), 1) + preInitScriptTemplate = strings.Replace(preInitScriptTemplate, "# JobsBase", string(jobbaseOutput), 1) + preInitScriptTemplate = strings.Replace(preInitScriptTemplate, "# Pipelines", string(pipelineOutput), 1) + preInitScriptTemplate = strings.Replace(preInitScriptTemplate, "# Projects", string(projectOutput), 1) return strings.Replace( preInitScriptTemplate, diff --git a/controllers/libs/zuulcf/zuulcf.go b/controllers/libs/zuulcf/zuulcf.go index cb1fde51..84e316ad 100644 --- a/controllers/libs/zuulcf/zuulcf.go +++ b/controllers/libs/zuulcf/zuulcf.go @@ -180,105 +180,91 @@ func GetZuulPipelinePrecedence(precedence string) PipelinePrecedence { return precedencestr } -func GetZuulPipelineReporterVerified(verified string) GerritReporter { - var verifiedstr GerritReporter +func GetZuulPipelineReporterVerified(verified string) GerritVotePoint { + var verifiedstr GerritVotePoint switch verified { case "2": - verifiedstr = VerifiedTwo + verifiedstr = GerritVotePointTwo case "1": - verifiedstr = VerifiedOne + verifiedstr = GerritVotePointOne case "0": - verifiedstr = VerifiedZero + verifiedstr = GerritVotePointZero case "-1": - verifiedstr = VerifiedMinusOne + verifiedstr = GerritVotePointMinusOne case "-2": - verifiedstr = VerifiedMinusTwo + verifiedstr = GerritVotePointMinusTwo default: - verifiedstr = VerifiedZero + verifiedstr = GerritVotePointZero } return verifiedstr } -type GerritReporter int8 +type GerritVotePoint int8 const ( // This is needed due to https://go.dev/ref/spec#The_zero_value // Zero Values for int's will not show while printing the structure - VerifiedTwo = 2 - VerifiedOne = 1 - VerifiedZero = 0 - VerifiedMinusOne = -1 - VerifiedMinusTwo = -2 + GerritVotePointTwo = 2 + GerritVotePointOne = 1 + GerritVotePointZero = 0 + GerritVotePointMinusOne = -1 + GerritVotePointMinusTwo = -2 ) // This struct defines Trigger Configurations for Gerrit, Gitlab and GitHub // The fields defined are common to all three configurations -func GetGerritWorkflowValue(value string) GerritWorkflowColumn { - var workflowvalue GerritWorkflowColumn +func GetGerritWorkflowValue(value string) GerritWorkflow { + var workflowvalue GerritWorkflow switch value { case "1": - workflowvalue = GerritWorkflowPlusOne + workflowvalue = GerritVotePointOne case "0": - workflowvalue = GerritWorkflowZero + workflowvalue = GerritVotePointZero case "-1": - workflowvalue = GerritWorkflowMinusOne + workflowvalue = GerritVotePointMinusOne default: - workflowvalue = GerritWorkflowZero + workflowvalue = GerritVotePointZero } return workflowvalue } -const ( - GerritWorkflowPlusOne = 1 - GerritWorkflowZero = 0 - GerritWorkflowMinusOne = -1 -) - -type GerritWorkflowColumn int8 +type GerritWorkflow GerritVotePoint func GetGerritCodeReviewValue(value string) GerritCodeReview { var codereviewvalue GerritCodeReview switch value { case "2": - codereviewvalue = GerritCodeReviewPlusTwo + codereviewvalue = GerritVotePointTwo case "1": - codereviewvalue = GerritCodeReviewPlusOne + codereviewvalue = GerritVotePointOne case "0": - codereviewvalue = GerritCodeReviewZero + codereviewvalue = GerritVotePointZero case "-1": - codereviewvalue = GerritCodeReviewMinusOne + codereviewvalue = GerritVotePointMinusOne case "-2": - codereviewvalue = GerritCodeReviewMinusTwo + codereviewvalue = GerritVotePointMinusTwo default: - codereviewvalue = GerritWorkflowZero + codereviewvalue = GerritVotePointZero } return codereviewvalue } -const ( - GerritCodeReviewPlusTwo = 2 - GerritCodeReviewPlusOne = 1 - GerritCodeReviewZero = 0 - GerritCodeReviewMinusOne = -1 - GerritCodeReviewMinusTwo = -2 -) - -type GerritCodeReview int8 +type GerritCodeReview GerritVotePoint type PipelineRequireGerritApproval struct { - Workflow GerritWorkflowColumn `yaml:"Workflow,omitempty"` - Verified GerritReporter `yaml:"Verified,omitempty,flow"` - CodeReview GerritCodeReview `yaml:"Code-Review,omitempty"` + Workflow GerritWorkflow `yaml:"Workflow,omitempty"` + Verified GerritVotePoint `yaml:"Verified,omitempty,flow"` + CodeReview GerritCodeReview `yaml:"Code-Review,omitempty"` } type PipelineRequireApproval struct { Username string `yaml:"username,omitempty"` Open bool `yaml:"open,omitempty"` CurrentPatchset bool `yaml:"current-patchset,omitempty"` - Verified []GerritReporter `yaml:"Verified,omitempty,flow"` + Verified []GerritVotePoint `yaml:"Verified,omitempty,flow"` GerritApproval []PipelineRequireGerritApproval `yaml:"approval,omitempty"` - Workflow GerritWorkflowColumn `yaml:"Workflow,omitempty"` + Workflow GerritWorkflow `yaml:"Workflow,omitempty"` } type PipelineTriggerGitGerrit struct { @@ -299,8 +285,8 @@ type PipelineTriggerGitArray []PipelineTriggerGit type PipelineGenericTrigger map[string]PipelineTriggerGitArray type PipelineGerritReporter struct { - Submit bool `yaml:"submit,omitempty"` - Verified GerritReporter `yaml:"Verified"` + Submit bool `yaml:"submit,omitempty"` + Verified GerritVotePoint `yaml:"Verified"` } type GerritReporterMap map[string]PipelineGerritReporter @@ -329,19 +315,21 @@ const ( type PipelineRequire map[string]PipelineRequireApproval type PipelineBody struct { - Name string `yaml:"name"` - Description string `yaml:"description,omitempty"` - Manager PipelineManager `yaml:"manager"` - PostReview bool `yaml:"post-review,omitempty"` - Precedence PipelinePrecedence `yaml:"precedence,omitempty"` - Supercedes []string `yaml:"supercedes,omitempty"` - SuccessMessage string `yaml:"success-message,omitempty"` - FailureMessage string `yaml:"failure-message,omitempty"` - Require PipelineRequire `yaml:"require,omitempty"` - Start PipelineReporter `yaml:"start,omitempty"` - Success PipelineReporter `yaml:"success,omitempty"` - Failure PipelineReporter `yaml:"failure,omitempty"` - Trigger PipelineGenericTrigger `yaml:"trigger,omitempty"` + Name string `yaml:"name"` + Description string `yaml:"description,omitempty"` + Manager PipelineManager `yaml:"manager"` + PostReview bool `yaml:"post-review,omitempty"` + Precedence PipelinePrecedence `yaml:"precedence,omitempty"` + Supercedes []string `yaml:"supercedes,omitempty"` + SuccessMessage string `yaml:"success-message,omitempty"` + FailureMessage string `yaml:"failure-message,omitempty"` + Require PipelineRequire `yaml:"require,omitempty"` + Start PipelineReporter `yaml:"start,omitempty"` + Success PipelineReporter `yaml:"success,omitempty"` + Failure PipelineReporter `yaml:"failure,omitempty"` + Trigger PipelineGenericTrigger `yaml:"trigger,omitempty"` + WindowFloor uint8 `yaml:"window-floor,omitempty"` + WindowIncreaseFactor uint8 `yaml:"window-increase-factor,omitempty"` } type Pipeline struct { diff --git a/controllers/static/git-server/update-system-config.sh b/controllers/static/git-server/update-system-config.sh index e1f0f955..6a44d3c3 100755 --- a/controllers/static/git-server/update-system-config.sh +++ b/controllers/static/git-server/update-system-config.sh @@ -17,112 +17,17 @@ git config user.email "admin@${FQDN}" mkdir -p zuul.d playbooks/base playbooks/config cat << EOF > zuul.d/jobs-base.yaml -# Semaphore -# JobBase +# Semaphores +# JobsBase EOF if [ -n "${CONFIG_REPO_NAME}" -a -n "${CONFIG_ZUUL_CONNECTION_NAME}" ]; then cat << EOF > zuul.d/config-project.yaml --- -- pipeline: - name: post - post-review: true - description: This pipeline runs jobs that operate after each change is merged. - manager: supercedent - precedence: low - trigger: - git-server: - event: - - ref-updated - ${CONFIG_ZUUL_CONNECTION_NAME}: - - event: ref-updated - ref: ^refs/heads/.*$ - -- pipeline: - name: check - description: | - Newly uploaded patchsets enter this pipeline to receive an - initial +/-1 Verified vote. - manager: independent - require: - ${CONFIG_ZUUL_CONNECTION_NAME}: - open: True - current-patchset: True - trigger: - ${CONFIG_ZUUL_CONNECTION_NAME}: - - event: patchset-created - - event: change-restored - - event: comment-added - comment: (?i)^(Patch Set [0-9]+:)?( [\w\\+-]*)*(\n\n)?\s*(recheck|reverify) - - event: comment-added - require: - approval: - - Verified: [-1, -2] - username: zuul - approval: - - Workflow: 1 - start: - ${CONFIG_ZUUL_CONNECTION_NAME}: - Verified: 0 - success: - ${CONFIG_ZUUL_CONNECTION_NAME}: - Verified: 1 - failure: - ${CONFIG_ZUUL_CONNECTION_NAME}: - Verified: -1 - -- pipeline: - name: gate - description: | - Changes that have been approved by core developers are enqueued - in order in this pipeline, and if they pass tests, will be - merged. - success-message: Build succeeded (gate pipeline). - failure-message: Build failed (gate pipeline). - manager: dependent - precedence: high - supercedes: check - post-review: True - require: - ${CONFIG_ZUUL_CONNECTION_NAME}: - open: True - current-patchset: True - approval: - - Workflow: 1 - trigger: - ${CONFIG_ZUUL_CONNECTION_NAME}: - - event: comment-added - approval: - - Workflow: 1 - - event: comment-added - approval: - - Verified: 1 - username: zuul - start: - ${CONFIG_ZUUL_CONNECTION_NAME}: - Verified: 0 - success: - ${CONFIG_ZUUL_CONNECTION_NAME}: - Verified: 2 - submit: true - failure: - ${CONFIG_ZUUL_CONNECTION_NAME}: - Verified: -2 - window-floor: 20 - window-increase-factor: 2 - -- project: - name: ${CONFIG_REPO_NAME} - check: - jobs: - - config-check - gate: - jobs: - - config-check - post: - jobs: - - config-update +# Pipelines +# Projects + EOF else cat << EOF > zuul.d/config-project.yaml