diff --git a/kubernetes/gitea/gitea-playbook.yaml b/kubernetes/gitea/gitea-playbook.yaml index ac07dc7b0d..5f02f03982 100644 --- a/kubernetes/gitea/gitea-playbook.yaml +++ b/kubernetes/gitea/gitea-playbook.yaml @@ -1,6 +1,5 @@ - hosts: localhost tasks: - # Deploy the service - name: Set up gitea namespace k8s: state: present @@ -30,15 +29,15 @@ k8s: state: present definition: "{{ lookup('template', 'k8s/service.yaml') | from_yaml }}" - - # Bootstrap - # TODO: wait until service is up - name: Get service IP k8s: namespace: gitea kind: Service name: gitea-service register: gitea_service + until: gitea_service.result.status.loadBalancer and gitea_service.result.status.loadBalancer.ingress and gitea_service.result.status.loadBalancer.ingress | length > 0 and gitea_service.result.status.loadBalancer.ingress[0].ip + delay: 1 + retries: 300 - name: Set service url fact set_fact: gitea_url: "http://{{ gitea_service.result.status.loadBalancer.ingress[0].ip }}" diff --git a/kubernetes/gitea/setup-org.yaml b/kubernetes/gitea/setup-org.yaml index f2462ec63d..fdb3b477db 100644 --- a/kubernetes/gitea/setup-org.yaml +++ b/kubernetes/gitea/setup-org.yaml @@ -49,8 +49,3 @@ - name: Parse org repo list set_fact: gitea_org_repos: "{{ gitea_org_repo_list.json | map(attribute='name') | list }}" -- name: Create repos in org - loop: "{{ (gerrit_projects.keys() | map('regex_search', '^' + org + '/.*') | select | map('regex_replace', '^.*/', '') | list) }}" - loop_control: - loop_var: repo - include_tasks: 'setup-repo.yaml' diff --git a/kubernetes/gitea/setup-repo.yaml b/kubernetes/gitea/setup-repo.yaml index 697ed35bc0..27cf7f1cb3 100644 --- a/kubernetes/gitea/setup-repo.yaml +++ b/kubernetes/gitea/setup-repo.yaml @@ -1,6 +1,10 @@ - name: debug debug: - msg: "{{ gerrit_projects[org+'/'+repo] }}" + msg: "{{ project }}" +- name: Parse project name + set_fact: + org: "{{ project.project | regex_replace('^(.*)/(.*)$', '\\1') }}" + repo: "{{ project.project | regex_replace('^(.*)/(.*)$', '\\2') }}" - name: Create repo when: repo not in gitea_org_repos uri: @@ -13,7 +17,7 @@ body_format: json body: auto_init: false - description: "{{ gerrit_projects[org+'/'+repo]['description'] | default('') }}" + description: "{{ project.description | default('') }}" name: "{{ repo }}" private: false register: create_repo_result @@ -32,4 +36,4 @@ - name: Adjust repo settings when: "sql_statement is defined" command: | - /home/corvus/opendev/kubectl exec gitea-pxc-0 -c database -n gitea-db -- mysql gitea -e '{{ sql_statement }}' + kubectl exec gitea-pxc-0 -c database -n gitea-db -- mysql gitea -e '{{ sql_statement }}' diff --git a/kubernetes/gitea/sync-repos.yaml b/kubernetes/gitea/sync-repos.yaml index e2b2210b64..22ccaa63e6 100644 --- a/kubernetes/gitea/sync-repos.yaml +++ b/kubernetes/gitea/sync-repos.yaml @@ -1,19 +1,20 @@ - hosts: localhost vars: - gitea_url: http://38.108.68.66 + gitea_url: http://38.108.68.64 + project_config_ref: master + project_config_dest: /tmp/project_config tasks: + - name: Clone project-config + git: + repo: https://git.openstack.org/openstack-infra/project-config + dest: "{{ project_config_dest }}" + version: "{{ project_config_ref }}" - name: Get Gerrit project list - uri: - url: "https://review.openstack.org/projects/" - status_code: 200 - return_content: true - register: gerrit_project_list - - name: Parse Gerrit project list set_fact: - gerrit_projects: "{{ gerrit_project_list.content[4:] | from_json }}" + gerrit_projects: "{{ lookup('file', project_config_dest + '/gerrit/projects.yaml') | from_yaml }}" - name: Parse Gerrit org list set_fact: - gerrit_orgs: "{{ gerrit_projects.keys() | map('regex_search', '^(.*?)/') | list | unique | select | map('regex_replace', '/', '') | list }}" + gerrit_orgs: "{{ gerrit_projects | map(attribute='project') | map('regex_search', '^(.*?)/') | list | unique | select | map('regex_replace', '/', '') | list }}" - name: debug debug: msg: "{{ gerrit_orgs }}" @@ -34,3 +35,8 @@ loop_control: loop_var: org include_tasks: 'setup-org.yaml' + - name: Create repos + loop: "{{ gerrit_projects }}" + loop_control: + loop_var: project + include_tasks: 'setup-repo.yaml'