Skip to content

Commit

Permalink
Merge "ci - add a step in olm jobs to first deploy the minimal CR"
Browse files Browse the repository at this point in the history
  • Loading branch information
Microzuul CI authored and Gerrit Code Review committed Jan 2, 2024
2 parents 9a21337 + a28dd93 commit 9ca656a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 31 deletions.
2 changes: 2 additions & 0 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ type SoftwareFactorySpec struct {
Zookeeper ZookeeperSpec `json:"zookeeper,omitempty"`

// Logserver service spec
// +kubebuilder:validation:Optional
// +kubebuilder:default={"loopDelay": 3600, retentionDays: 60}
Logserver LogServerSpecSettings `json:"logserver,omitempty"`

// MariaDB service spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ spec:
- server
type: object
logserver:
default:
loopDelay: 3600
retentionDays: 60
description: Logserver service spec
properties:
loopDelay:
Expand Down
2 changes: 1 addition & 1 deletion controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *SFController) SetupConfigJob() bool {
// or zuul internal tenant reconfigure
cmName = "zs-internal-tenant-reconfigure"
zsInternalTenantReconfigure apiv1.ConfigMap
configHash = utils.Checksum([]byte(preInitScriptTemplate))
configHash = utils.Checksum([]byte(r.MkPreInitScript()))
internalTenantSecretsVersion = "1"
needReconfigureTenant = false
needCMUpdate = false
Expand Down
45 changes: 25 additions & 20 deletions controllers/git_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func makeZuulConnectionConfig(spec *sfv1.ZuulSpec) string {
return sb.String()
}

func (r *SFController) makePreInitScript() string {
func (r *SFController) MkPreInitScript() string {
configRepoConnectionName := r.cr.Spec.ConfigLocation.ZuulConnectionName
configRepoName := r.cr.Spec.ConfigLocation.Name

parentJobName := "base"

Expand Down Expand Up @@ -130,7 +132,7 @@ func (r *SFController) makePreInitScript() string {
Event: "ref-updated",
},
},
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerGitArray{
configRepoConnectionName: zuulcf.PipelineTriggerGitArray{
{
Event: "ref-updated",
Ref: []string{
Expand All @@ -147,13 +149,13 @@ func (r *SFController) makePreInitScript() string {
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{
configRepoConnectionName: zuulcf.PipelineRequireApproval{
Open: true,
CurrentPatchset: true,
},
},
Trigger: zuulcf.PipelineGenericTrigger{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerGitArray{
configRepoConnectionName: zuulcf.PipelineTriggerGitArray{
{
Event: "patchset-created",
},
Expand Down Expand Up @@ -187,21 +189,21 @@ func (r *SFController) makePreInitScript() string {
},
Start: zuulcf.PipelineReporter{
GerritReporter: zuulcf.GerritReporterMap{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{
configRepoConnectionName: zuulcf.PipelineGerritReporter{
Verified: zuulcf.GerritVotePointZero,
},
},
},
Success: zuulcf.PipelineReporter{
GerritReporter: zuulcf.GerritReporterMap{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{
configRepoConnectionName: zuulcf.PipelineGerritReporter{
Verified: zuulcf.GerritVotePointOne,
},
},
},
Failure: zuulcf.PipelineReporter{
GerritReporter: zuulcf.GerritReporterMap{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{
configRepoConnectionName: zuulcf.PipelineGerritReporter{
Verified: zuulcf.GerritVotePointMinusOne,
},
},
Expand All @@ -221,7 +223,7 @@ func (r *SFController) makePreInitScript() string {
},
PostReview: true,
Require: zuulcf.PipelineRequire{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineRequireApproval{
configRepoConnectionName: zuulcf.PipelineRequireApproval{
Open: true,
CurrentPatchset: true,
GerritApproval: []zuulcf.PipelineRequireGerritApproval{
Expand All @@ -232,7 +234,7 @@ func (r *SFController) makePreInitScript() string {
},
},
Trigger: zuulcf.PipelineGenericTrigger{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineTriggerGitArray{
configRepoConnectionName: zuulcf.PipelineTriggerGitArray{
{
Event: "comment-added",
Approval: []zuulcf.PipelineRequireGerritApproval{
Expand All @@ -254,22 +256,22 @@ func (r *SFController) makePreInitScript() string {
},
Start: zuulcf.PipelineReporter{
GerritReporter: zuulcf.GerritReporterMap{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{
configRepoConnectionName: zuulcf.PipelineGerritReporter{
Verified: zuulcf.GerritVotePointZero,
},
},
},
Success: zuulcf.PipelineReporter{
GerritReporter: zuulcf.GerritReporterMap{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{
configRepoConnectionName: zuulcf.PipelineGerritReporter{
Verified: zuulcf.GerritVotePointTwo,
Submit: true,
},
},
},
Failure: zuulcf.PipelineReporter{
GerritReporter: zuulcf.GerritReporterMap{
r.cr.Spec.ConfigLocation.ZuulConnectionName: zuulcf.PipelineGerritReporter{
configRepoConnectionName: zuulcf.PipelineGerritReporter{
Verified: zuulcf.GerritVotePointMinusTwo,
},
},
Expand All @@ -283,7 +285,7 @@ func (r *SFController) makePreInitScript() string {
projects := zuulcf.ProjectConfig{
{
Project: zuulcf.ZuulProjectBody{
Name: r.cr.Spec.ConfigLocation.Name,
Name: configRepoName,
Pipeline: zuulcf.ZuulProjectPipelineMap{
"check": zuulcf.ZuulProjectPipeline{
Jobs: []string{
Expand All @@ -310,19 +312,22 @@ func (r *SFController) makePreInitScript() string {
pipelineOutput, _ := yaml.Marshal(pipelines)
projectOutput, _ := yaml.Marshal(projects)

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)
// We need to copy the global value `preInitScriptTemplate` to avoid updating the global
// and thus loosing the markers.
template := preInitScriptTemplate
template = strings.Replace(template, "# Semaphores", string(semaphoreOutput), 1)
template = strings.Replace(template, "# JobsBase", string(jobbaseOutput), 1)
template = strings.Replace(template, "# Pipelines", string(pipelineOutput), 1)
template = strings.Replace(template, "# Projects", string(projectOutput), 1)

return strings.Replace(
preInitScriptTemplate,
template,
"# ZUUL_CONNECTIONS",
makeZuulConnectionConfig(&r.cr.Spec.Zuul), 1)
}

func (r *SFController) DeployGitServer() bool {
preInitScript := r.makePreInitScript()
preInitScript := r.MkPreInitScript()
cmData := make(map[string]string)
cmData["pre-init.sh"] = preInitScript
r.EnsureConfigMap(GitServerIdent+"-pi", cmData)
Expand Down Expand Up @@ -378,7 +383,7 @@ func (r *SFController) DeployGitServer() bool {
if r.isConfigRepoSet() {
initContainer.Env = append(initContainer.Env,
base.MkEnvVar("CONFIG_REPO_NAME", r.cr.Spec.ConfigLocation.Name),
base.MkEnvVar("CONFIG_ZUUL_CONNECTION_NAME", r.cr.Spec.ConfigLocation.ZuulConnectionName))
)
}

sts.Spec.Template.Spec.InitContainers = []apiv1.Container{initContainer}
Expand Down
2 changes: 1 addition & 1 deletion controllers/static/git-server/update-system-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cat << EOF > zuul.d/jobs-base.yaml
EOF

if [ -n "${CONFIG_REPO_NAME}" -a -n "${CONFIG_ZUUL_CONNECTION_NAME}" ]; then
if [ -n "${CONFIG_REPO_NAME}" ]; then
cat << EOF > zuul.d/config-project.yaml
---
# Pipelines
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ _Appears in:_
| `zuul` _[ZuulSpec](#zuulspec)_ | Zuul service spec | -|
| `nodepool` _[NodepoolSpec](#nodepoolspec)_ | Nodepool services spec | -|
| `zookeeper` _[ZookeeperSpec](#zookeeperspec)_ | Zookeeper service spec | -|
| `logserver` _[LogServerSpecSettings](#logserverspecsettings)_ | Logserver service spec | -|
| `logserver` _[LogServerSpecSettings](#logserverspecsettings)_ | Logserver service spec | {map[loopDelay:3600 retentionDays:60]}|
| `mariadb` _[MariaDBSpec](#mariadbspec)_ | MariaDB service spec | -|
| `gitserver` _[GitServerSpec](#gitserverspec)_ | Git server spec | -|

Expand Down
28 changes: 20 additions & 8 deletions playbooks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@
- sanity-check
- sfconfig-dev-prepare
tasks:
- name: CI process(OLM install)
ansible.builtin.include_role:
name: "{{ item }}"
loop:
- build-operator-assets
- clean-installations
- install-operator
- apply-custom-resources
- name: Run OLM specific tasks
when: mode == 'olm'
block:
- name: CI process(OLM install)
ansible.builtin.include_role:
name: "{{ item }}"
loop:
- build-operator-assets
- clean-installations
- install-operator

- name: Apply the minimal SF CR and ensure reconciled happened
ansible.builtin.include_role:
name: update-custom-resource
vars:
cr_spec:
fqdn: "{{ fqdn }}"

- name: Apply the base CI SF CR and ensure reconciled happened
ansible.builtin.include_role:
name: apply-custom-resources

- name: Run tests
ansible.builtin.include_role:
Expand Down

0 comments on commit 9ca656a

Please sign in to comment.