Skip to content

Commit

Permalink
k8-cluster: continue on failure
Browse files Browse the repository at this point in the history
Convert the k8-cluster test to the `continue on failure.  Addresses
issue projectatomic#375.
  • Loading branch information
mike-nguyen committed May 24, 2018
1 parent e3eea1d commit 371b4b3
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 119 deletions.
19 changes: 19 additions & 0 deletions tests/k8-cluster/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# set ft=ansible
#

- import_role:
name: k8_remove_all
tags:
- k8_remove_all

- import_role:
name: docker_remove_all
tags:
- docker_remove_all

- when: ansible_distribution == 'RedHat'
import_role:
name: redhat_unsubscribe
tags:
- redhat_unsubscribe
163 changes: 44 additions & 119 deletions tests/k8-cluster/main.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,47 @@
---
# vim: set ft=ansible:
#
# This playbook creates a kubernetes cluster on a single system using the
# example in the Red Hat documentation. The cluster contains a database
# and a webserver pod with data from the database to present a webpage that
# says "Red Hat Rocks!"
#
# Execution Steps:
# 1. Subscribe to RedHat if running RHEL Atomic Host
# 2. Create an insecure private registry
# 3. Copy over the mariadb and apache webserver Dockerfile and supporting
# files, build the docker image, tag the image, then push to the private
# registry.
# 4. Setup and start the kubernetes pods
# 5. Setup and start the mariadb and webserver pods
# 6. Verify that the pods are running and that the mariadb and webserver
# can communicate through the kubernetes services
#
- name: k8-cluster
- name: Kubernetes Cluster - Test Suite
hosts: all
become: true

# This giant mess of pre-tasks is here to workaround the problem that is fixed
# in this PR - https://github.com/projectatomic/atomic/pull/1185
#
# The fallout from that missing functionality is that the 'kube-proxy' system
# container will not start correctly unless atomic 1.22 is used to install
# the system container with the right SELinux labels.

pre_tasks:
- import_role:
name: rpm_version
vars:
rv_rpms: atomic

- when:
- ansible_distribution == 'Fedora'
- ansible_distribution_major_version | version_compare('26', '>')
- g_atomic_host is defined
- g_atomic_host['atomic'] | version_compare('1.22', '<=')
block:
- name: Grab the atomic 1.22 RPMs
get_url:
url: "{{ item }}"
dest: /root/
with_items:
- https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-1.22.1-1.fc27.x86_64.rpm
- https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-registries-1.22.1-1.fc27.x86_64.rpm

- name: Override the atomic package
command: rpm-ostree override replace /root/atomic-1.22.1-1.fc27.x86_64.rpm /root/atomic-registries-1.22.1-1.fc27.x86_64.rpm

- import_role:
name: reboot

roles:
- role: ansible_version_check
tags:
- ansible_version_check

- role: osname_set_fact
tags:
- osname_set_fact

- when: ansible_distribution == 'RedHat'
role: redhat_subscription
tags:
- redhat_subscription

- role: docker_private_registry
tags:
- docker_private_registry

- role: docker_build_tag_push
tags:
- docker_build_tag_push

- when: ansible_distribution == "CentOSDev"
role: resize_lv
rl_lvname: 'root'
rl_lvsize: '6'
tags:
- resize_lv

- role: kubernetes_setup
tags:
- kubernetes_setup

- role: k8_cluster_services_rc_setup
tags:
- k8_cluster_services_rc_setup

post_tasks:
- name: Check if everything works!
shell: curl http://localhost:80/cgi-bin/action | grep "RedHat rocks"
register: curl
retries: 6
delay: 10
until: curl|success


- name: Kubernetes Cluster - Cleanup
hosts: all
become: true

tags:
- cleanup

roles:
- role: k8_remove_all
tags:
- k8_remove_all

- role: docker_remove_all
tags:
- docker_remove_all

- when: ansible_distribution == 'RedHat'
role: redhat_unsubscribe
tags:
- redhat_unsubscribe
vars:
tests: []

tasks:
- name: Set logging
set_fact:
log_results: true
result_file: "{{ playbook_dir }}/k8-cluster-result.log"
tags: setup

- include_tasks: 'setup.yml'
tags: setup

# TEST
# Verify setup of single node kubernetes cluster
- block:
- include_tasks: 'single_node_cluster.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Single Node Kubernetes Test', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Single Node Kubernetes Test', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: single_node_cluster

# CLEANUP
- block:
- include_tasks: 'cleanup.yml'
- set_fact:
tests: "{{ tests + [ { 'name': 'Cleanup', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Cleanup', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
always:
# WRITE RESULTS TO FILE
- name: Remove existing log files
local_action: file path={{ result_file }} state=absent
become: false

- name: Save result to file
when: log_results
local_action: copy content={{ tests | to_nice_yaml(indent=2) }} dest={{ result_file }}
become: false
tags: cleanup
45 changes: 45 additions & 0 deletions tests/k8-cluster/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# set ft=ansible
#

- import_role:
name: ansible_version_check
tags:
- ansible_version_check

- import_role:
name: osname_set_fact
tags:
- osname_set_fact

- when: ansible_distribution == 'RedHat'
import_role:
name: redhat_subscription
tags:
- redhat_subscription

- import_role:
name: rpm_version
vars:
rv_rpms: atomic

- when:
- ansible_distribution == 'Fedora'
- ansible_distribution_major_version | version_compare('26', '>')
- g_atomic_host is defined
- g_atomic_host['atomic'] | version_compare('1.22', '<=')
block:
- name: Grab the atomic 1.22 RPMs
get_url:
url: "{{ item }}"
dest: /root/
with_items:
- https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-1.22.1-1.fc27.x86_64.rpm
- https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-registries-1.22.1-1.fc27.x86_64.rpm

- name: Override the atomic package
command: rpm-ostree override replace /root/atomic-1.22.1-1.fc27.x86_64.rpm /root/atomic-registries-1.22.1-1.fc27.x86_64.rpm

- import_role:
name: reboot

81 changes: 81 additions & 0 deletions tests/k8-cluster/single_node_cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
# set ft=ansible
#

- import_role:
name: ansible_version_check
tags:
- ansible_version_check

- import_role:
name: osname_set_fact
tags:
- osname_set_fact

- import_role:
name: rpm_version
vars:
rv_rpms: atomic

- when:
- ansible_distribution == 'Fedora'
- ansible_distribution_major_version | version_compare('26', '>')
- g_atomic_host is defined
- g_atomic_host['atomic'] | version_compare('1.22', '<=')
block:
- name: Grab the atomic 1.22 RPMs
get_url:
url: "{{ item }}"
dest: /root/
with_items:
- https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-1.22.1-1.fc27.x86_64.rpm
- https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-registries-1.22.1-1.fc27.x86_64.rpm

- name: Override the atomic package
command: rpm-ostree override replace /root/atomic-1.22.1-1.fc27.x86_64.rpm /root/atomic-registries-1.22.1-1.fc27.x86_64.rpm

- import_role:
name: reboot

- when: ansible_distribution == 'RedHat'
import_role:
name: redhat_subscription
tags:
- redhat_subscription

- import_role:
name: docker_private_registry
tags:
- docker_private_registry

- import_role:
name: docker_build_tag_push
tags:
- docker_build_tag_push

- when: ansible_distribution == "CentOSDev"
import_role:
name: resize_lv
vars:
rl_lvname: 'root'
rl_lvsize: '6'
tags:
- resize_lv

- import_role:
name: kubernetes_setup
tags:
- kubernetes_setup

- import_role:
name: k8_cluster_services_rc_setup
tags:
- k8_cluster_services_rc_setup

- name: Check if everything works!
shell: curl http://localhost:80/cgi-bin/action | grep "RedHat rocks"
register: curl
retries: 6
delay: 10
until: curl|success

0 comments on commit 371b4b3

Please sign in to comment.