Skip to content

Commit 1585cee

Browse files
authored
Bug 1570603: Make postgresql-apb (de)provision idempotent (#45)
* Make postgresql-apb ansible galaxy compatible * Update RPM Spec * Move travis to use apb-test-shim * Remove pvc on upgrade/downgrade
1 parent b584032 commit 1585cee

21 files changed

+349
-363
lines changed

.travis.yml

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
language: go
2-
go:
3-
- "1.8.x"
4-
dist: trusty
1+
---
2+
services: docker
53
sudo: required
6-
group: edge
7-
8-
before_script:
9-
- curl -s https://raw.githubusercontent.com/openshift/ansible-service-broker/master/scripts/travis.sh | bash -s before_install
10-
- curl -s https://raw.githubusercontent.com/openshift/ansible-service-broker/master/scripts/travis.sh | bash -s install
11-
- curl -s https://raw.githubusercontent.com/openshift/ansible-service-broker/master/scripts/travis.sh | bash -s before_script
12-
- curl -s https://raw.githubusercontent.com/openshift/ansible-service-broker/master/scripts/broker-ci/setup-cluster.sh | bash -s
13-
- go get github.com/rthallisey/service-broker-ci/cmd/ci
4+
language: python
5+
python:
6+
- '2.7'
7+
8+
env:
9+
- OPENSHIFT_VERSION=v3.9
10+
- OPENSHIFT_VERSION=v3.10
11+
- KUBERNETES_VERSION=v1.9.0
12+
- KUBERNETES_VERSION=v1.10.0
13+
# Allow failures on oc latest
14+
# TODO: re-enable latest when it isn't busted
15+
matrix:
16+
allow_failures:
17+
- env: OPENSHIFT_VERSION=v3.10
18+
- env: KUBERNETES_VERSION=v1.10.0
19+
1420
script:
15-
- ci
21+
# Configure test values
22+
- export apb_name='postgresql-apb'
23+
- export dockerfile='Dockerfile-canary'
24+
25+
# Download test shim.
26+
- wget -O ${PWD}/apb-test.sh https://raw.githubusercontent.com/ansibleplaybookbundle/apb-test-shim/master/apb-test.sh
27+
- chmod +x ${PWD}/apb-test.sh
28+
29+
# Run tests.
30+
- ${PWD}/apb-test.sh
31+
32+
notifications:
33+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

Dockerfile-canary

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM ansibleplaybookbundle/apb-base:canary
2-
# MAINTAINER {{ $MAINTAINER }}
2+
MAINTAINER Ansible Playbook Bundle Community
33

44
LABEL "com.redhat.apb.spec"=\
55
"LS0tCgp2ZXJzaW9uOiAxLjAKbmFtZTogcG9zdGdyZXNxbC1hcGIKZGVzY3JpcHRpb246IFNDTCBQ\
@@ -56,8 +56,11 @@ ICcxMEdpJ10KICAgICAgICB0aXRsZTogUG9zdGdyZVNRTCBWb2x1bWUgU2l6ZQogICAgICAgIHJl\
5656
cXVpcmVkOiB0cnVlCiAgICB1cGRhdGVzX3RvOgogICAgICAtIGRldgo="
5757

5858

59-
COPY roles /opt/ansible/roles
60-
COPY playbooks/* /opt/apb/actions/
59+
ADD playbooks /opt/apb/actions
60+
61+
# Add our role into the ansible roles dir
62+
ADD . /opt/ansible/roles/postgresql-apb
63+
6164
RUN chmod -R g=u /opt/{ansible,apb}
6265

6366
USER apb

README.md

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
postgresql-apb
2-
======================
1+
[![Build
2+
Status](https://travis-ci.org/ansibleplaybookbundle/postgresql-apb.svg?branch=master)](https://travis-ci.org/ansibleplaybookbundle/postgresql-apb)
33

4-
[![Build Status](https://travis-ci.org/ansibleplaybookbundle/postgresql-apb.svg?branch=master)](https://travis-ci.org/openshift/ansible-service-broker)
4+
PostgreSQL APB
5+
==============
56

6-
An apb for deploying [PostgreSQL](https://www.postgresql.org).
7+
Ansible Role for installing (and uninstalling) [postgresql](https://www.postgresql.org/about/)
8+
in a Kubernetes/OpenShift Cluster.
79

8-
## What it does
9-
* Deploys 1 postgresql container.
10+
Requirements
11+
------------
1012

11-
## Requirements
12-
* N/A
13+
- [openshift-restclient-python](https://github.com/openshift/openshift-restclient-python)
14+
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
1315

14-
## Parameters
15-
* namespace: Optional, default 'rhscl-postgresql-apb', Namespace to deploy the cluster in.
16-
* postgresql_database, Optional, default 'admin', Postgresql database name.
17-
* postgresql_password, Optional, default is a randomly generated string, Postgresql databaase password.
18-
* postgresql_user, Optional, default 'admin', Postgresql database username.
19-
* postgresql_version, Optional, default '9.6', Postgresql version. 9.4, 9.5, and 9.6 are supported.
16+
Role Variables
17+
--------------
2018

21-
## Running the application
22-
`docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID docker.io/ansibleplaybookbundle/postresql-apb provision`
19+
See [defaults/main.yaml](defaults/main.yaml).
2320

24-
## Tearing down the application
25-
`docker run -e "OPENSHIFT_TARGET=<openshift_target>" -e "OPENSHIFT_TOKEN=<token>" ansibleplaybookbundle/postgresql-apb deprovision`
21+
Example Playbook
22+
----------------
23+
24+
See [playbooks/provision.yml](playbooks/provision.yml).
25+
26+
License
27+
-------
28+
29+
Apache-2.0
30+
31+
Author Information
32+
------------------
33+
34+
http://automationbroker.io

config.yaml

-9
This file was deleted.

defaults/main.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
# Defaults for values we could expect from a broker
4+
_apb_plan_id: default
5+
_apb_service_class_id: 0
6+
_apb_service_instance_id: 0
7+
8+
app_name: "postgresql-{{ _apb_service_instance_id }}"
9+
app_image: registry.access.redhat.com/rhscl/postgresql-{{ postgresql_version | replace('.', '') }}-rhel7
10+
namespace: "{{ lookup('env','NAMESPACE') | default('postgresql', true) }}"
11+
12+
# Postgresql defaults
13+
postgresql_database: admin
14+
postgresql_user: admin
15+
postgresql_password: changeme
16+
postgresql_volume_size: 1Gi
17+
postgresql_version: "9.6"

meta/main.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
galaxy_info:
2+
author: Automation Broker Team
3+
description: Deploys PostgreSQL Database in OpenShift/Kubernetes
4+
company: Red Hat
5+
license: Apache 2.0
6+
min_ansible_version: 1.5
7+
8+
#
9+
# platforms is a list of platforms, and each platform has a name and a list of versions.
10+
#
11+
platforms:
12+
- name: Centos
13+
14+
galaxy_tags:
15+
- apb
16+
17+
dependencies: []
18+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
19+
# if you add dependencies to this list.

playbooks/deprovision.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
- name: Deploy rhscl-postgresql-apb to "{{ cluster }}"
1+
- name: postgresql-apb deprovision
22
hosts: localhost
33
gather_facts: false
44
connection: local
5-
vars:
6-
state: absent
75
roles:
8-
- role: ansible.kubernetes-modules
9-
install_python_requirements: no
10-
- role: ansibleplaybookbundle.asb-modules
11-
- rhscl-postgresql-apb
6+
- ansibleplaybookbundle.asb-modules
7+
- postgresql-apb
8+
vars:
9+
apb_action: deprovision

playbooks/provision.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
- name: Deploy rhscl-postgresql-apb to "{{ cluster }}"
1+
- name: postgresql-apb provision
22
hosts: localhost
33
gather_facts: false
44
connection: local
55
roles:
6-
- role: ansible.kubernetes-modules
7-
install_python_requirements: no
8-
- role: ansibleplaybookbundle.asb-modules
9-
- rhscl-postgresql-apb
6+
- ansibleplaybookbundle.asb-modules
7+
- postgresql-apb
8+
vars:
9+
apb_action: provision

playbooks/test.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
3+
- name: Test postgresql-apb
4+
hosts: localhost
5+
gather_facts: false
6+
connection: local
7+
8+
roles:
9+
- ansibleplaybookbundle.asb-modules
10+
11+
tasks:
12+
- name: Provision test
13+
include_role:
14+
name: postgresql-apb
15+
vars:
16+
apb_action: provision
17+
in_cluster: False
18+
19+
- name: Deprovision test
20+
include_role:
21+
name: postgresql-apb
22+
vars:
23+
apb_action: deprovision
24+
in_cluster: False

playbooks/update.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
- name: Deploy rhscl-postgresql-apb to "{{ cluster }}"
1+
- name: postgresql-apb update
22
hosts: localhost
33
gather_facts: false
44
connection: local
5-
vars:
6-
update: true
75
roles:
8-
- role: ansible.kubernetes-modules
9-
install_python_requirements: no
10-
- role: ansibleplaybookbundle.asb-modules
11-
- rhscl-postgresql-apb
6+
- ansibleplaybookbundle.asb-modules
7+
- postgresql-apb
8+
vars:
9+
apb_action: update

postgresql-apb-role.spec

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ BuildArch: noarch
2121
%setup -q -n %{name}-%{version}
2222

2323
%install
24-
mkdir -p %{buildroot}/opt/apb/ %{buildroot}/opt/ansible/
24+
mkdir -p %{buildroot}/opt/apb/ %{buildroot}/opt/ansible/roles/postgresql-apb
2525
mv playbooks %{buildroot}/opt/apb/actions
26-
mv roles %{buildroot}/opt/ansible/roles
26+
mv defaults tasks templates vars %{buildroot}/opt/ansible/roles/postgresql-apb
2727

2828
%files
2929
%doc

roles/rhscl-postgresql-apb/defaults/main.yml

-7
This file was deleted.

roles/rhscl-postgresql-apb/tasks/dev.yml

-79
This file was deleted.

0 commit comments

Comments
 (0)