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

Modernized Hello-World APB #3

Merged
merged 18 commits into from Mar 27, 2018
Merged

Modernized Hello-World APB #3

merged 18 commits into from Mar 27, 2018

Conversation

djzager
Copy link
Contributor

@djzager djzager commented Feb 5, 2018

No description provided.

@djzager
Copy link
Contributor Author

djzager commented Feb 5, 2018

I'm playing around/investigating with a "modernized" APB example. The end goal is to have something showing off openshift_raw and k8s_raw as well as a functioning test playbook. Right now though I've restructured this APB into a single role and wanted to get feedback before moving any further.

@@ -5,5 +5,6 @@
roles:
- role: ansible.kubernetes-modules
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you won't need this anymore, right?

@@ -0,0 +1,27 @@
---
# Notice that the prefix was removed from apps.openshift.io/v1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you aren't inlining these?

@@ -0,0 +1,2 @@
---
state: absent
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little overkill to have a whole vars directory for these two 1-line files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I really just wanted to pull vars out of the playbook but I don't think this improves on that.

@djzager
Copy link
Contributor Author

djzager commented Feb 5, 2018

Example runthrough with multiple provisions in same namespace:

Provision apb with apb_id=2

(apb) ➜  hello-world-apb git:(apb-ref-example) ✗ docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID hello-world-apb provision --extra-vars 'apb_id=2'
+ [[ provision --extra-vars apb_id=2 == *\s\2\i\/\a\s\s\e\m\b\l\e* ]]
+ ACTION=provision
+ shift
+ playbooks=/opt/apb/actions
+ CREDS=/var/tmp/bind-creds
+ TEST_RESULT=/var/tmp/test-result
+ whoami
+ '[' -w /etc/passwd ']'
++ id -u
+ echo 'apb:x:1000:0:apb user:/opt/apb:/sbin/nologin'
+ set +x
+ [[ -e /opt/apb/actions/provision.yaml ]]
+ [[ -e /opt/apb/actions/provision.yml ]]
+ ANSIBLE_ROLES_PATH=/etc/ansible/roles:/opt/ansible/roles
+ ansible-playbook /opt/apb/actions/provision.yml --extra-vars apb_id=2

PLAY [hello-world-apb provision] ***********************************************

TASK [hello-world-apb : deployment config] *************************************
changed: [localhost]

TASK [hello-world-apb : hello-world service] ***********************************
changed: [localhost]

TASK [hello-world-apb : create hello-world route] ******************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0

+ EXIT_CODE=0
+ set +ex
+ '[' -f /var/tmp/test-result ']'
+ exit 0

Provision apb with apb_id=1

$  hello-world-apb git:(apb-ref-example) ✗ docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID hello-world-apb provision --extra-vars 'apb_id=1'
+ [[ provision --extra-vars apb_id=1 == *\s\2\i\/\a\s\s\e\m\b\l\e* ]]
+ ACTION=provision
+ shift
+ playbooks=/opt/apb/actions
+ CREDS=/var/tmp/bind-creds
+ TEST_RESULT=/var/tmp/test-result
+ whoami
+ '[' -w /etc/passwd ']'
++ id -u
+ echo 'apb:x:1000:0:apb user:/opt/apb:/sbin/nologin'
+ set +x
+ [[ -e /opt/apb/actions/provision.yaml ]]
+ [[ -e /opt/apb/actions/provision.yml ]]
+ ANSIBLE_ROLES_PATH=/etc/ansible/roles:/opt/ansible/roles
+ ansible-playbook /opt/apb/actions/provision.yml --extra-vars apb_id=1

PLAY [hello-world-apb provision] ***********************************************

TASK [hello-world-apb : deployment config] *************************************
changed: [localhost]

TASK [hello-world-apb : hello-world service] ***********************************
changed: [localhost]

TASK [hello-world-apb : create hello-world route] ******************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0

+ EXIT_CODE=0
+ set +ex
+ '[' -f /var/tmp/test-result ']'
+ exit 0

See all in the namespace

$ oc get all -n hello-world
NAME                                                                 REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfigs/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   1          1         0         config
deploymentconfigs/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   1          1         0         config

NAME                                                      HOST/PORT                                                                        PATH      SERVICES                                           PORT      TERMINATION   WILDCARD
routes/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab-hello-world.172.17.0.1.nip.io             hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   web                     None
routes/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-hello-world.172.17.0.1.nip.io             hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   web                     None

NAME                                                           READY     STATUS    RESTARTS   AGE
po/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab-1-deploy   0/1       Error     0          14s
po/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1-deploy   0/1       Error     0          8s

NAME                                                    DESIRED   CURRENT   READY     AGE
rc/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab-1   0         0         0         14s
rc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1   0         0         0         8s

NAME                                                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
svc/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   ClusterIP   172.30.237.56    <none>        8080/TCP   13s
svc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   ClusterIP   172.30.221.152   <none>        8080/TCP   7s

Deprovision apb_id=2

$ docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID hello-world-apb deprovision --extra-vars 'apb_id=2'
+ [[ deprovision --extra-vars apb_id=2 == *\s\2\i\/\a\s\s\e\m\b\l\e* ]]
+ ACTION=deprovision
+ shift
+ playbooks=/opt/apb/actions
+ CREDS=/var/tmp/bind-creds
+ TEST_RESULT=/var/tmp/test-result
+ whoami
+ '[' -w /etc/passwd ']'
++ id -u
+ echo 'apb:x:1000:0:apb user:/opt/apb:/sbin/nologin'
+ set +x
+ [[ -e /opt/apb/actions/deprovision.yaml ]]
+ [[ -e /opt/apb/actions/deprovision.yml ]]
+ ANSIBLE_ROLES_PATH=/etc/ansible/roles:/opt/ansible/roles
+ ansible-playbook /opt/apb/actions/deprovision.yml --extra-vars apb_id=2

PLAY [hello-world-apb deprovision] *********************************************

TASK [hello-world-apb : deployment config] *************************************
changed: [localhost]

TASK [hello-world-apb : hello-world service] ***********************************
changed: [localhost]

TASK [hello-world-apb : create hello-world route] ******************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0

+ EXIT_CODE=0
+ set +ex
+ '[' -f /var/tmp/test-result ']'
+ exit 0

See if apb_id=1 survived

$ oc get all -n hello-world
NAME                                                                 REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfigs/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   1          1         0         config

NAME                                                      HOST/PORT                                                                        PATH      SERVICES                                           PORT      TERMINATION   WILDCARD
routes/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-hello-world.172.17.0.1.nip.io             hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   web                     None

NAME                                                           READY     STATUS    RESTARTS   AGE
po/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1-deploy   0/1       Error     0          6m

NAME                                                    DESIRED   CURRENT   READY     AGE
rc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1   0         0         0         6m

NAME                                                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
svc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   ClusterIP   172.30.221.152   <none>        8080/TCP   6m

@LorbusChris
Copy link

@djzager I'm liking the simplified structure!

Here's an idea of what it could look like to add per-container config-roles (aka container-enabled) to the APB:
https://github.com/djzager/Hello-World-APB/pull/1

@@ -0,0 +1,4 @@
---
app_name: "hello-world-{{ 99 | random(seed=apb_id) | to_uuid }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I like this approach a lot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like _apb_service_instance_id better :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just make a filter for this, so you could do something like {{ 'hello-world' | apb_uuid }} or something. Would let us control how the names are generated as well, if we could do it deterministically based on the service instance id then idempotence would be easy as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we make a filter for this? I like this idea a lot...service instance id is a uuid, so it is unique and preserves idempotence. My concern is making it so that when you run the apb without a broker it still works (with sane defaults or you providing the value).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also really like it if we were able to untie the APB variables from the broker. By this I mean that _apb_service_instance_id limits that variable to being used only when the APB is associated with a service instance. If we could go to more generics like apb_id or having a filter apb_uuid, I would really be on board.

@LorbusChris
Copy link

LorbusChris commented Feb 6, 2018

Maybe the container name shouldn't be the same as the pod's name, in case there's multiple containers deployed to the pod and we want to easily differentiate them?

---
app: hello-world
apb_id: 0
app_name: "{{ app }}-{{ apb_id }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hope is to have the broker provide the service instance id as apb_id instead of _apb_service_instance_id (and have apb_id passed on all APB actions) to make this work with and w/o a broker. If _apb_service_instance_id stays, then I'll change this.

version: 1.0
name: hello-world-apb
description: deploys hello-world web application
bindable: False
bindable: "False"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason these need to be strings and not bools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://travis-ci.org/djzager/Hello-World-APB/jobs/339544060

apb.yml
  1:1       warning  missing document start "---"  (document-start)
  4:11      warning  truthy value is not quoted  (truthy)
  8:81      error    line too long (89 > 80 characters)  (line-length)
  14:11     warning  truthy value is not quoted  (truthy)
  17:81     error    line too long (88 > 80 characters)  (line-length)

dependencies: ['docker.io/ansibleplaybookbundle/hello-world:latest']
providerDisplayName: "Red Hat, Inc."
plans:
- name: default
description: A sample APB which deploys Hello World
free: True
free: "True"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

playbook_debug: false
- role: hello-world-apb
vars:
state: absent

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like state should be set by apb_action inside the role

playbook_debug: false
- role: hello-world-apb
vars:
state: present

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

---

- name: "verify deployment config removed"
shell: "oc get deploymentconfig -n {{ namespace }} {{ app_name }}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think chouseknecht has added a lookup module for this, probably a good place to showcase it: https://docs.ansible.com/ansible/devel/plugins/lookup/openshift.html

.travis.yml Outdated
script:
# Check if committed APB spec matches Dockerfile
- apb build
- if ! git diff --exit-code; then echo "Committed APB spec differs from built apb.yml spec"; exit 1; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart, good idea

@@ -0,0 +1,10 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to how you organized this. Good idea including defaults for what the broker provides

@dymurray
Copy link
Contributor

Any ideas why deprovision is failing?

@@ -0,0 +1,13 @@
---

- name: "Verify {{ app_name }} objects removed"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabianvf @dymurray I scrapped the use of lookups for verification because they don't work as you would expect and I think this is cleaner and makes more sense. I'll consider writing an issue against Ansible, but for now, I think this is the most correct way to do this.

@jwmatthews
Copy link

@djzager what are next steps with this PR?

@djzager
Copy link
Contributor Author

djzager commented Feb 26, 2018

@jwmatthews The next steps are:

  1. Figure out what to do with the test playbook. If you look at the mariadb-apb HA PR, specifically the test playbook there are some good things going on there that we should investigate. It goes beyond the typical "verifications" that I've seen in other test playbooks and actually interacts with the database as a test. It's also a little complex. I want to be sure that test playbooks are supported by any apb-test-shim we develop. There may be nothing more to do here as the apb-test-shim already runs the test playbook if it exists in the project.
  2. Talk with @dymurray and make sure that what I'm doing here lines up with the ansible-galaxy integration.
  3. Move the apb-test-shim project under one of our organizations.

@djzager djzager changed the title WIP: Initial attempt at modernized APB Initial attempt at modernized APB Mar 5, 2018
@djzager djzager changed the title Initial attempt at modernized APB Modernized Hello-World APB Mar 5, 2018
@djzager
Copy link
Contributor Author

djzager commented Mar 6, 2018

I'm using this PR to test the changes in --> ansibleplaybookbundle/apb-test-shim#4 In the end this will rely on that PR being merged.

@djzager
Copy link
Contributor Author

djzager commented Mar 6, 2018

@fabianvf + @dymurray I think this is ready to go

when: cluster == "kubernetes"

- name: "Wait for deployment config to be available"
command: >-
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think chouseknecht has added a lookup module for this, probably a good place to showcase it: https://docs.ansible.com/ansible/devel/plugins/lookup/openshift.html

I think ansible also has a jsonquery/path filter built in to it, probably should add the dependency to apb-base since it's pretty useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmontleon
I did a cursory look to see if jmespath was available in the EPEL repo for centos in order to update the apb-base image and it wasn't there. I see a few bugs related to this https://bugzilla.redhat.com/show_bug.cgi?id=1484910 but I don't see how we could update the apb-base with jmespath. If we can't easily add it then I think we should push off the lookup stuff.

@djzager
Copy link
Contributor Author

djzager commented Mar 16, 2018

Updated the example to use lookups based on @fabianvf request. Now this is blocked by ansible/ansible#37533 ... once that is merged I'll make sure everything is good to go and get 👍 again.

@djzager djzager removed the blocked label Mar 20, 2018
playbook_debug: false
- role: ansibleplaybookbundle.asb-modules
- role: hello-world-apb
vars:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing here and in provision.yml looks weird to me, does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work. Not sure what I would do to improve it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, seeing it in the email cleared it up. Thought the var was attached to the role include and not the play.

Copy link
Contributor

@dymurray dymurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I really like the asb_last_operation calls to give us some status reporting. ACK Pending Travis.

@djzager
Copy link
Contributor Author

djzager commented Mar 22, 2018

Putting this here for when I forget. The kubernetes latest is going to fail because of kubernetes/minikube#2629

Copy link

@fabianvf fabianvf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm :shipit:

@djzager djzager merged commit 9843792 into ansibleplaybookbundle:master Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants