Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement kubectl check for lagoon-build and add more tests #3039

Merged
merged 5 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion local-dev/git/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ RUN mkdir -m 700 /git/.ssh && \
git --bare init /git/python.git && \
git --bare init /git/node-mongodb.git && \
git --bare init /git/tasks.git && \
git --bare init /git/image-cache.git
git --bare init /git/image-cache.git && \
git --bare init /git/generic.git

USER root

Expand Down
2 changes: 2 additions & 0 deletions local-dev/git/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ if [ "$GIT_AUTHORIZED_KEYS" ]; then
echo -e "$GIT_AUTHORIZED_KEYS" > /git/.ssh/authorized_keys
fi

ls -d -- git/*

exec /sbin/runsvdir /etc/service
3 changes: 2 additions & 1 deletion tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ RUN apk add --no-cache --virtual .build-deps \
PyJWT==2.3.* \
requests==2.26.* \
jmespath==0.10.* \
kubernetes==21.7.* \
&& apk del .build-deps

RUN ansible-galaxy collection install ansible.posix community.general
RUN ansible-galaxy collection install ansible.posix community.general kubernetes.core

# download, extract and install kubectl binary
# https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.20.md#downloads-for-v1204
Expand Down
1 change: 1 addition & 0 deletions tests/files/generic/GENERIC_FILES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copy the project to deploy into this folder
35 changes: 35 additions & 0 deletions tests/tasks/api/deploy-no-sha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@
- fail:
msg: "unsuccessful deploy"
when: apiresponse.json.data.deployEnvironmentBranch != "success"
- name: Get the build pod name
kubernetes.core.k8s_info:
kind: Pod
wait: yes
namespace: "{{ namespace }}"
label_selectors:
- lagoon.sh/jobType = build
field_selectors:
- status.phase=Running
wait_sleep: 1
wait_timeout: 60
register: build_pod
- name: Print build_pod
ansible.builtin.debug:
msg: "build_pod: {{ build_pod.resources[0].metadata.name }} {{ build_pod.resources[0].status.phase }}"
- name: Wait until the build pod is completed
kubernetes.core.k8s_info:
kind: Pod
wait: yes
name: "{{ build_pod.resources[0].metadata.name }}"
namespace: "{{ namespace }}"
label_selectors:
- lagoon.sh/jobType = build
field_selectors:
- status.phase=Succeeded
wait_condition:
type: Ready
reason: PodCompleted
status: "False"
wait_sleep: 10
wait_timeout: 600
register: build_complete
- name: Print build_complete
ansible.builtin.debug:
msg: "build_complete: {{ build_complete.resources[0].metadata.name }} {{ build_complete.resources[0].status.phase }}"
- name: "Set the retry count back to 0 when successful"
set_fact:
retry_count: 0
Expand Down
35 changes: 35 additions & 0 deletions tests/tasks/api/deploy-pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@
- fail:
msg: "unsuccessful deploy"
when: apiresponse.json.data.deployEnvironmentPullrequest != "success"
- name: Get the build pod name
kubernetes.core.k8s_info:
kind: Pod
wait: yes
namespace: "{{ namespace }}"
label_selectors:
- lagoon.sh/jobType = build
field_selectors:
- status.phase=Running
wait_sleep: 1
wait_timeout: 60
register: build_pod
- name: Print build_pod
ansible.builtin.debug:
msg: "build_pod: {{ build_pod.resources[0].metadata.name }} {{ build_pod.resources[0].status.phase }}"
- name: Wait until the build pod is completed
kubernetes.core.k8s_info:
kind: Pod
wait: yes
name: "{{ build_pod.resources[0].metadata.name }}"
namespace: "{{ namespace }}"
label_selectors:
- lagoon.sh/jobType = build
field_selectors:
- status.phase=Succeeded
wait_condition:
type: Ready
reason: PodCompleted
status: "False"
wait_sleep: 10
wait_timeout: 600
register: build_complete
- name: Print build_complete
ansible.builtin.debug:
msg: "build_complete: {{ build_complete.resources[0].metadata.name }} {{ build_complete.resources[0].status.phase }}"
- name: "Set the retry count back to 0 when successful"
set_fact:
retry_count: 0
Expand Down
37 changes: 36 additions & 1 deletion tests/tasks/api/deploy-sha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@
- fail:
msg: "unsuccessful deploy"
when: apiresponse.json.data.deployEnvironmentBranch != "success"
- name: Get the build pod name
kubernetes.core.k8s_info:
kind: Pod
wait: yes
namespace: "{{ namespace }}"
label_selectors:
- lagoon.sh/jobType = build
field_selectors:
- status.phase=Running
wait_sleep: 1
wait_timeout: 60
register: build_pod
- name: Print build_pod
ansible.builtin.debug:
msg: "build_pod: {{ build_pod.resources[0].metadata.name }} {{ build_pod.resources[0].status.phase }}"
- name: Wait until the build pod is completed
kubernetes.core.k8s_info:
kind: Pod
wait: yes
name: "{{ build_pod.resources[0].metadata.name }}"
namespace: "{{ namespace }}"
label_selectors:
- lagoon.sh/jobType = build
field_selectors:
- status.phase=Succeeded
wait_condition:
type: Ready
reason: PodCompleted
status: "False"
wait_sleep: 10
wait_timeout: 600
register: build_complete
- name: Print build_complete
ansible.builtin.debug:
msg: "build_complete: {{ build_complete.resources[0].metadata.name }} {{ build_complete.resources[0].status.phase }}"
- name: "Set the retry count back to 0 when successful"
set_fact:
retry_count: 0
Expand All @@ -34,4 +69,4 @@
seconds: 10
- debug:
msg: "Failed to connect - Retrying..."
- include_tasks: ./deploy-sha.yaml
- include_tasks: ./deploy-sha.yaml
2 changes: 2 additions & 0 deletions tests/tests/active-standby/active-standby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
vars:
branch: "{{ prod_branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ prod_branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand All @@ -33,6 +34,7 @@
vars:
branch: "{{ standby_branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ standby_branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
4 changes: 4 additions & 0 deletions tests/tests/api/deploy-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down Expand Up @@ -45,6 +46,7 @@
branch: "{{ branch }}"
project: "{{ project }}"
sha: "{{ second_commit_hash }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-sha.yaml

Expand All @@ -62,6 +64,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand All @@ -79,6 +82,7 @@
branch: "{{ branch }}"
project: "{{ project }}"
sha: "{{ second_commit_hash }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-sha.yaml

Expand Down
2 changes: 2 additions & 0 deletions tests/tests/api/deploy-pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
git_pr_commit_hash: "{{ pr_commit_hash }}"
git_pr_number: 1
git_pr_title: "PR Title"
namespace: "{{ project | regex_replace('_', '-') }}-pr-1"
tasks:
- include: ../../tasks/api/deploy-pullrequest.yaml

Expand Down Expand Up @@ -80,6 +81,7 @@
git_pr_commit_hash: "{{ pr_2nd_commit_hash }}"
git_pr_number: 1
git_pr_title: "PR Title - UPDATE"
namespace: "{{ project | regex_replace('_', '-') }}-pr-1"
tasks:
- include: ../../tasks/api/deploy-pullrequest.yaml

Expand Down
1 change: 1 addition & 0 deletions tests/tests/api/promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
vars:
branch: "{{ source_environment }}"
project: "{{ project }}"
namespace: "{{ project }}-{{ source_environment }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
1 change: 1 addition & 0 deletions tests/tests/api/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
65 changes: 65 additions & 0 deletions tests/tests/dbaas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- include: features/random-wait.yaml

- include: features/api-token.yaml
vars:
testname: "API TOKEN"

- include: api/add-project.yaml
vars:
project: ci-drupal-80-{{ cluster_type }}
git_repo_name: drupal-80.git
git_url: "{{ localgit_url }}/{{ git_repo_name }}"

- include: drupal/drupal.yaml
vars:
testname: "Drupal 9 composer PHP 8.0 - MARIADB DBAAS {{ cluster_type|upper }}"
drupal_version: 9
db: mariadb
php_version: 8.0
git_repo_name: drupal-80.git
project: ci-drupal-80-{{ cluster_type }}
branch: drupal9-php80-mariadb-dbaas

- include: api/delete-project.yaml
vars:
project: ci-drupal-80-{{ cluster_type }}

- include: api/add-project.yaml
vars:
project: ci-drupal-pg-{{ cluster_type }}
git_repo_name: drupal-postgres.git
git_url: "{{ localgit_url }}/{{ git_repo_name }}"

- include: drupal/drupal.yaml
vars:
testname: "Drupal 9 composer PHP 8.0 - POSTGRES DBAAS {{ cluster_type|upper }}"
drupal_version: 9
db: postgres
php_version: 8.0
git_repo_name: drupal-postgres.git
project: ci-drupal-pg-{{ cluster_type }}
branch: drupal9-php80-postgres-dbaas

- include: api/delete-project.yaml
vars:
project: ci-drupal-pg-{{ cluster_type }}

- include: api/add-project.yaml
vars:
project: ci-node-mongodb-{{ cluster_type }}
git_repo_name: node-mongodb.git
git_url: "{{ localgit_url }}/{{ git_repo_name }}"

- include: node-mongodb/node-mongodb.yaml
vars:
testname: "Node 16 - MONGODB DBAAS {{ cluster_type|upper }}"
node_version: 16
db: mongodb
git_repo_name: node-mongodb.git
project: ci-node-mongodb-{{ cluster_type }}
branch: node-mongodb-dbaas

- include: api/delete-project.yaml
vars:
project: ci-node-mongodb-{{ cluster_type }}
2 changes: 2 additions & 0 deletions tests/tests/deploytarget/deploytarget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand All @@ -37,6 +38,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
2 changes: 2 additions & 0 deletions tests/tests/drupal/drupal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand All @@ -38,6 +39,7 @@
vars:
branch: "{{ branch }}"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
3 changes: 3 additions & 0 deletions tests/tests/drupal/drush-la.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
vars:
branch: "drush-first"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-drush-first"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand All @@ -39,6 +40,7 @@
vars:
branch: "drush-second"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-drush-second"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down Expand Up @@ -219,6 +221,7 @@
vars:
branch: "foo/bar"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-foo-bar"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
3 changes: 3 additions & 0 deletions tests/tests/drupal/drush-sa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
vars:
branch: "drush-first"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-drush-first"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand All @@ -39,6 +40,7 @@
vars:
branch: "drush-second"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-drush-second"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down Expand Up @@ -211,6 +213,7 @@
vars:
branch: "foo/bar"
project: "{{ project }}"
namespace: "{{ project | regex_replace('_', '-') }}-foo-bar"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

Expand Down
1 change: 1 addition & 0 deletions tests/tests/drush.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
drupal_version: 9
db: mariadb
php_version: 8.0
overwrite_docker_compose: docker-compose.single.yml
git_repo_name: drush.git
project: ci-drush-la-{{ cluster_type }}

Expand Down
Loading