diff --git a/e2e/provision/nephio.yaml b/e2e/provision/nephio.yaml index 826f7337..60b36cc9 100644 --- a/e2e/provision/nephio.yaml +++ b/e2e/provision/nephio.yaml @@ -15,9 +15,9 @@ all: gitea_password: secret validate_certs: true container_engine: podman - installation_mode: online #online/offline + installation_mode: online # online/offline proxy: - http_proxy: + http_proxy: https_proxy: no_proxy: host_os: "linux" # use "darwin" for MacOS X, "windows" for Windows @@ -28,7 +28,8 @@ all: tmp_directory: "/tmp" bin_directory: "/usr/local/bin" kubectl_version: "1.25.0" - kubectl_checksum_binary: "sha512:fac91d79079672954b9ae9f80b9845fbf373e1c4d3663a84cc1538f89bf70cb85faee1bcd01b6263449f4a2995e7117e1c85ed8e5f137732650e8635b4ecee09" + kubectl_checksum_binary: "sha512:fac91d79079672954b9ae9f80b9845fbf373e1c4d3663a84cc1538f89bf70cb8\ + 5faee1bcd01b6263449f4a2995e7117e1c85ed8e5f137732650e8635b4ecee09" kind_version: "0.17.0" cni_version: "0.8.6" kpt_version: "1.0.0-beta.31" diff --git a/e2e/provision/playbooks/cluster.yml b/e2e/provision/playbooks/cluster.yml index e0de77e8..b1e202de 100644 --- a/e2e/provision/playbooks/cluster.yml +++ b/e2e/provision/playbooks/cluster.yml @@ -109,11 +109,13 @@ block: - name: Install container lab on Ubuntu family OS ansible.builtin.apt: - deb: "{{ clab.download_url }}/v{{ clab.version }}/containerlab_{{ clab.version }}_linux_{{ 'amd64' if ansible_architecture == 'x86_64' else ansible_architecture }}.deb" + deb: "{{ clab.download_url }}/v{{ clab.version }}/containerlab_{{ clab.version }}_linux_\ + {{ 'amd64' if ansible_architecture == 'x86_64' else ansible_architecture }}.deb" when: ansible_os_family == 'Debian' - name: Install container lab on RedHat family OS ansible.builtin.yum: - name: "{{ clab.download_url }}/v{{ clab.version }}/containerlab_{{ clab.version }}_linux_{{ 'amd64' if ansible_architecture == 'x86_64' else ansible_architecture }}.rpm" + name: "{{ clab.download_url }}/v{{ clab.version }}/containerlab_{{ clab.version }}_linux_\ + {{ 'amd64' if ansible_architecture == 'x86_64' else ansible_architecture }}.rpm" state: present disable_gpg_check: true when: ansible_os_family == 'RedHat' diff --git a/e2e/provision/playbooks/roles/bootstrap/tasks/prep-gitea.yml b/e2e/provision/playbooks/roles/bootstrap/tasks/prep-gitea.yml index 26da3460..be64f79b 100644 --- a/e2e/provision/playbooks/roles/bootstrap/tasks/prep-gitea.yml +++ b/e2e/provision/playbooks/roles/bootstrap/tasks/prep-gitea.yml @@ -64,7 +64,7 @@ password: "{{ gitea.k8s.db_password }}" no_log: true -- name: Create gitea user password +- name: Create gitea user password in Gitea namespace kubernetes.core.k8s: context: "{{ k8s.context }}" state: present diff --git a/e2e/provision/playbooks/roles/install/defaults/main.yml b/e2e/provision/playbooks/roles/install/defaults/main.yml index 68cf27cd..9ab8e8dc 100644 --- a/e2e/provision/playbooks/roles/install/defaults/main.yml +++ b/e2e/provision/playbooks/roles/install/defaults/main.yml @@ -15,6 +15,8 @@ gitea: k8s: username: nephio password: secret + ingress_ip: 172.18.0.200 + ingress_port: 3000 nephio_pkg_version: v1.0.1 nephio_example_repo_uri: https://github.com/nephio-project/nephio-example-packages.git diff --git a/e2e/provision/playbooks/roles/install/molecule/ci/molecule.yml b/e2e/provision/playbooks/roles/install/molecule/ci/molecule.yml index e2115193..c8e75678 100644 --- a/e2e/provision/playbooks/roles/install/molecule/ci/molecule.yml +++ b/e2e/provision/playbooks/roles/install/molecule/ci/molecule.yml @@ -38,10 +38,24 @@ platforms: provisioner: name: ansible playbooks: - prepare: ${MOLECULE_PROJECT_DIRECTORY}/../kpt/molecule/default/prepare.yml + prepare: ${MOLECULE_PROJECT_DIRECTORY}/molecule/default/prepare.yml converge: ${MOLECULE_PROJECT_DIRECTORY}/molecule/default/converge.yml env: ANSIBLE_LIBRARY: ${MOLECULE_PROJECT_DIRECTORY}/../../../playbooks/library + inventory: + group_vars: + all: + k8s: + context: kind-kind + gitea: + k8s: + namespace: gitea + postgres_password: c2VjcmV0 # echo -n "secret" | base64 + db_password: c2VjcmV0 + username: nephio + password: secret + nephio_pkg_version: v1.0.1 + nephio_example_repo_uri: https://github.com/nephio-project/nephio-example-packages.git verifier: name: testinfra directory: ${MOLECULE_PROJECT_DIRECTORY}/molecule/default/tests diff --git a/e2e/provision/playbooks/roles/install/molecule/default/molecule.yml b/e2e/provision/playbooks/roles/install/molecule/default/molecule.yml index 8446ecbe..1258c9dd 100644 --- a/e2e/provision/playbooks/roles/install/molecule/default/molecule.yml +++ b/e2e/provision/playbooks/roles/install/molecule/default/molecule.yml @@ -29,9 +29,21 @@ platforms: gui: false provisioner: name: ansible - playbooks: - prepare: ${MOLECULE_PROJECT_DIRECTORY}/../kpt/molecule/default/prepare.yml env: ANSIBLE_LIBRARY: ${MOLECULE_PROJECT_DIRECTORY}/../../../playbooks/library + inventory: + group_vars: + all: + k8s: + context: kind-kind + gitea: + k8s: + namespace: gitea + postgres_password: c2VjcmV0 # echo -n "secret" | base64 + db_password: c2VjcmV0 + username: nephio + password: secret + nephio_pkg_version: v1.0.1 + nephio_example_repo_uri: https://github.com/nephio-project/nephio-example-packages.git verifier: name: testinfra diff --git a/e2e/provision/playbooks/roles/install/molecule/default/prepare.yml b/e2e/provision/playbooks/roles/install/molecule/default/prepare.yml new file mode 100644 index 00000000..dd61aa5c --- /dev/null +++ b/e2e/provision/playbooks/roles/install/molecule/default/prepare.yml @@ -0,0 +1,57 @@ +--- +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2023 The Nephio Authors. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +- name: Include the kpt role's prepare playbook + ansible.builtin.import_playbook: ../../../kpt/molecule/default/prepare.yml + +- name: Deploy Gitea + hosts: all + pre_tasks: + - name: Update Apt cache + ansible.builtin.raw: apt-get update --allow-releaseinfo-change + become: true + changed_when: false + when: ansible_distribution == 'Ubuntu' + - name: Install pip package + become: true + ansible.builtin.package: + name: python3-pip + state: present + when: ansible_distribution == 'Ubuntu' + - name: Install kubernetes python package + become: true + ansible.builtin.pip: + name: kubernetes==26.1.0 + tasks: + - name: Set local git facts + ansible.builtin.include_tasks: ../../../bootstrap/tasks/prep-gitea.yml + - name: Deploy gitea kpt packages + ansible.builtin.include_role: + name: kpt + vars: + repo_uri: "{{ nephio_example_repo_uri }}" + pkg: "{{ item }}" + version: "{{ nephio_pkg_version }}" + context: "{{ k8s.context }}" + kpt_async: 1020 + kpt_poll: 5 + loop: + - gitea + - metallb + - metallb-sandbox-config + - name: Wait for deployments + ansible.builtin.include_tasks: ../../tasks/wait_deployments.yml + loop_control: + loop_var: namespace + vars: + context: "{{ k8s.context }}" + loop: + - gitea + - metallb-system diff --git a/e2e/provision/playbooks/roles/install/tasks/main.yml b/e2e/provision/playbooks/roles/install/tasks/main.yml index be7f1912..f8d3d983 100644 --- a/e2e/provision/playbooks/roles/install/tasks/main.yml +++ b/e2e/provision/playbooks/roles/install/tasks/main.yml @@ -42,7 +42,7 @@ vars: context: "{{ k8s.context }}" -- name: Create gitea user password in nephio-system namespace +- name: Save local git server credentials in nephio-system namespace kubernetes.core.k8s: context: "{{ k8s.context }}" state: present @@ -75,39 +75,21 @@ context: "{{ k8s.context }}" namespace: "{{ nephio_webui.k8s.namespace }}" -- name: Create stock repositories - kubernetes.core.k8s: - state: present - context: "{{ k8s.context }}" - definition: - apiVersion: config.porch.kpt.dev/v1alpha1 - kind: Repository - metadata: - name: "{{ item.name }}" - namespace: default - spec: - content: Package - deployment: false - git: - branch: "{{ item.branch }}" - directory: / - repo: "{{ item.repo }}" - type: git +- name: Clone stock GitHub repositories to Gitea + ansible.builtin.include_tasks: mirror_git_repo_to_gitea.yaml loop: "{{ nephio_stock_repos }}" -- name: Wait for stock repositories +- name: "Wait for stock repository: {{ item.name }}" kubernetes.core.k8s: context: "{{ k8s.context }}" definition: apiVersion: config.porch.kpt.dev/v1alpha1 kind: Repository metadata: - name: "{{ item }}" + name: "{{ item.name }}" namespace: default wait: true wait_condition: type: Ready status: true - loop: - - nephio-example-packages - - free5gc-packages + loop: "{{ nephio_stock_repos }}" diff --git a/e2e/provision/playbooks/roles/install/tasks/mirror_git_repo_to_gitea.yaml b/e2e/provision/playbooks/roles/install/tasks/mirror_git_repo_to_gitea.yaml new file mode 100644 index 00000000..0cae2a68 --- /dev/null +++ b/e2e/provision/playbooks/roles/install/tasks/mirror_git_repo_to_gitea.yaml @@ -0,0 +1,92 @@ +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2023 The Nephio Authors. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +- name: "Define local git variables" + ansible.builtin.set_fact: + local_git_push_uri: "http://{{ gitea.k8s.username }}:{{ gitea.k8s.password }}@{{ gitea.k8s.ingress_ip }}:{{ gitea.k8s.ingress_port }}/nephio" + local_git_fetch_uri: "http://{{ gitea.k8s.ingress_ip }}:{{ gitea.k8s.ingress_port }}/nephio" + no_log: true + +- name: "Create new repo in local git: {{ item.name }}" + kubernetes.core.k8s: + context: "{{ k8s.context }}" + state: present + definition: + apiVersion: infra.nephio.org/v1alpha1 + kind: Repository + metadata: + name: "{{ item.name }}" + namespace: default + spec: + description: "Clone of GitHub repository {{ item.name }}" + defaultBranch: main + +- name: "Fetch GitHub repo {{ item.name }}" + ansible.builtin.git: # noqa: latest[git] + repo: "{{ item.repo }}" + dest: "/tmp/repository/{{ item.name }}.git" + bare: true + +- name: "Add git remote for local repo" + ansible.builtin.command: # noqa: command-instead-of-module + cmd: git remote add local {{ local_git_push_uri }}/{{ item.name }}.git + chdir: "/tmp/repository/{{ item.name }}.git" + register: add_remote_result + changed_when: false + ignore_errors: true + no_log: true + +- name: "Push tags to local git repo: {{ item.name }}" + ansible.builtin.command: # noqa: command-instead-of-module + cmd: git push local --tags --force + chdir: /tmp/repository/{{ item.name }}.git + environment: + http_proxy: "" + https_proxy: "" + HTTP_PROXY: "" + HTTPS_PROXY: "" + register: push_result + until: push_result is not failed + retries: 12 + delay: 10 + changed_when: "'Everything up-to-date' not in push_result.stdout" + +- name: "Push branches to local git repo: {{ item.name }}" + ansible.builtin.command: # noqa: command-instead-of-module + cmd: git push local --all --force + chdir: /tmp/repository/{{ item.name }}.git + environment: + http_proxy: "" + https_proxy: "" + HTTP_PROXY: "" + HTTPS_PROXY: "" + register: push_result + changed_when: "'Everything up-to-date' not in push_result.stdout" + +- name: "Create porch repository object: {{ item.name }}" + kubernetes.core.k8s: + context: "{{ k8s.context }}" + state: present + definition: + apiVersion: config.porch.kpt.dev/v1alpha1 + kind: Repository + metadata: + name: "{{ item.name }}" + namespace: default + labels: + kpt.dev/repository-access: read-only + kpt.dev/repository-content: external-blueprints + spec: + content: Package + deployment: false + git: + branch: "{{ item.branch }}" + directory: / + repo: "{{ local_git_fetch_uri }}/{{ item.name }}.git" + type: git