From 37cb59330055ae94d053bad95346fa298c80e27d Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Tue, 21 Nov 2023 14:09:03 +0000 Subject: [PATCH] zuul - add support for git connection Change-Id: Ia6890e1c4ee1cb05fc08ad0b94cb1f0d85fa04bb --- api/v1/softwarefactory_types.go | 8 ++++++++ controllers/git_server.go | 16 +++++----------- controllers/zuul.go | 14 +++++++++++--- .../zuul-connections/tasks/main.yaml | 7 +++++++ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/api/v1/softwarefactory_types.go b/api/v1/softwarefactory_types.go index 9542f122..edb90de1 100644 --- a/api/v1/softwarefactory_types.go +++ b/api/v1/softwarefactory_types.go @@ -298,6 +298,14 @@ func GetGitHubConnectionsName(spec *ZuulSpec) []string { return res } +func GetGitConnectionsName(spec *ZuulSpec) []string { + var res []string + for _, conn := range spec.GitConns { + res = append(res, conn.Name) + } + return res +} + func GetGitHubConnectionsSecretName(spec *ZuulSpec) []string { var res []string for _, conn := range spec.GitHubConns { diff --git a/controllers/git_server.go b/controllers/git_server.go index 23720fec..7d9a5455 100644 --- a/controllers/git_server.go +++ b/controllers/git_server.go @@ -33,22 +33,16 @@ var preInitScriptTemplate string // This function creates dummy connections to be used during the config-check func makeZuulConnectionConfig(spec *sfv1.ZuulSpec) string { var sb strings.Builder + connectionNames := sfv1.GetGerritConnectionsName(spec) + connectionNames = append(connectionNames, sfv1.GetGitHubConnectionsName(spec)...) + connectionNames = append(connectionNames, sfv1.GetGitLabConnectionsName(spec)...) + connectionNames = append(connectionNames, sfv1.GetGitConnectionsName(spec)...) sb.WriteString("\n") - for _, name := range sfv1.GetGerritConnectionsName(spec) { + for _, name := range connectionNames { sb.WriteString(fmt.Sprintf("[connection %s]\n", name)) sb.WriteString("driver=git\n") sb.WriteString("baseurl=localhost\n\n") } - for _, name := range sfv1.GetGitHubConnectionsName(spec) { - sb.WriteString(fmt.Sprintf("[connection %s]\n", name)) - sb.WriteString("driver=gitlab\n") - sb.WriteString("baseurl=localhost\n\n") - } - for _, name := range sfv1.GetGitLabConnectionsName(spec) { - sb.WriteString(fmt.Sprintf("[connection %s]\n", name)) - sb.WriteString("driver=github\n") - sb.WriteString("baseurl=localhost\n\n") - } return sb.String() } diff --git a/controllers/zuul.go b/controllers/zuul.go index 8e424efe..1ff13c4d 100644 --- a/controllers/zuul.go +++ b/controllers/zuul.go @@ -866,11 +866,15 @@ func (r *SFController) AddGitLabConnection(cfg *ini.File, conn sfv1.GitLabConnec } -func AddGitConnection(cfg *ini.File, name string, baseurl string) { +func AddGitConnection(cfg *ini.File, name string, baseurl string, poolDelay int32) { section := "connection " + name cfg.NewSection(section) cfg.Section(section).NewKey("driver", "git") cfg.Section(section).NewKey("baseurl", baseurl) + // When poolDelay is set to a positive value, then we add the setting or Zuul default will apply + if poolDelay > 0 { + cfg.Section(section).NewKey("poll_delay", strconv.Itoa(int(poolDelay))) + } } func AddWebClientSection(cfg *ini.File) { @@ -881,10 +885,10 @@ func AddWebClientSection(cfg *ini.File) { func (r *SFController) AddDefaultConnections(cfg *ini.File) { // Internal git-server for system config - AddGitConnection(cfg, "git-server", "git://git-server/") + AddGitConnection(cfg, "git-server", "git://git-server/", 0) // Git connection to opendev.org - AddGitConnection(cfg, "opendev.org", "https://opendev.org/") + AddGitConnection(cfg, "opendev.org", "https://opendev.org/", 0) // Add Web Client for zuul-client AddWebClientSection(cfg) @@ -936,6 +940,10 @@ func (r *SFController) DeployZuul() bool { r.AddGitLabConnection(cfgINI, conn) } + for _, conn := range r.cr.Spec.Zuul.GitConns { + AddGitConnection(cfgINI, conn.Name, conn.Baseurl, conn.PollDelay) + } + // Add default connections r.AddDefaultConnections(cfgINI) diff --git a/roles/health-check/zuul-connections/tasks/main.yaml b/roles/health-check/zuul-connections/tasks/main.yaml index 6dbbb597..621e4e3a 100644 --- a/roles/health-check/zuul-connections/tasks/main.yaml +++ b/roles/health-check/zuul-connections/tasks/main.yaml @@ -11,6 +11,9 @@ dummy_gitlabconns: - name: dummy-gitlab-conn secrets: gitlabconnectionsecret + dummy_gitconns: + - name: dummy-git-conn + baseurl: git://test - name: Create GitHub Connection Secret kubernetes.core.k8s: @@ -62,6 +65,7 @@ gerritconns: "{{ gerritconns_orig + dummy_gerritconn }}" githubconns: "{{ dummy_githubconns }}" gitlabconns: "{{ dummy_gitlabconns }}" + gitconns: "{{ dummy_gitconns }}" - name: Wait for the new Zuul connections to appear in the Zuul API ansible.builtin.uri: @@ -74,6 +78,7 @@ - "'dummy-gerrit-conn' in this.content" - "'dummy-github-conn' in this.content" - "'dummy-gitlab-conn' in this.content" + - "'dummy-git-conn' in this.content" retries: "{{ retries }}" delay: "{{ delay }}" @@ -86,6 +91,7 @@ gerritconns: "{{ gerritconns_orig }}" githubconns: [] gitlabconns: [] + gitconns: [] - name: Wait for the dummy Zuul connections to be removed from the API ansible.builtin.uri: @@ -98,6 +104,7 @@ - "'dummy-gerrit-conn' not in this.content" - "'dummy-github-conn' not in this.content" - "'dummy-gitlab-conn' not in this.content" + - "'dummy-git-conn' not in this.content" retries: "{{ retries }}" delay: "{{ delay }}"