Skip to content

Commit

Permalink
zuul - add support for git connection
Browse files Browse the repository at this point in the history
Change-Id: Ia6890e1c4ee1cb05fc08ad0b94cb1f0d85fa04bb
  • Loading branch information
morucci committed Nov 30, 2023
1 parent 3945530 commit 37cb593
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
8 changes: 8 additions & 0 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 5 additions & 11 deletions controllers/git_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
14 changes: 11 additions & 3 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions roles/health-check/zuul-connections/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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 }}"

Expand All @@ -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:
Expand All @@ -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 }}"

Expand Down

0 comments on commit 37cb593

Please sign in to comment.