From c4a2ca0d10edb88ba6f19f1f54115967439f01ca Mon Sep 17 00:00:00 2001 From: "Szekeres, Balazs (Nokia - HU/Budapest)" Date: Thu, 2 May 2019 13:52:55 +0200 Subject: [PATCH] Added seed code for caas-lcm. Added seed code for caas-lcm. Change-Id: I557508ec2fe7d14e96ab8abff87145fdf33312c0 Signed-off-by: Szekeres, Balazs (Nokia - HU/Budapest) --- LICENSE | 178 +++++++++++++++++++++ ansible/playbooks/pre_config_lcm.yaml | 22 +++ ansible/roles/pre_config_lcm/tasks/main.yml | 27 ++++ .../group_vars/controller-1.caas_master/params.yml | 24 +++ deploy/playbook_bm_onboard.yml | 20 +++ deploy/playbook_clean_chart.yml | 21 +++ deploy/playbook_clean_registry.yml | 21 +++ deploy/playbook_helm_delete.yml | 20 +++ deploy/playbook_helm_install.yml | 22 +++ deploy/playbook_helm_upgrade.yml | 20 +++ deploy/playbook_list_application_deployments.yml | 20 +++ deploy/playbook_list_application_packages.yml | 20 +++ deploy/playbook_list_docker_images.yml | 20 +++ deploy/roles/bm_onboard/tasks/main.yml | 52 ++++++ deploy/roles/clean_chart/tasks/main.yml | 59 +++++++ deploy/roles/clean_registry/tasks/main.yml | 47 ++++++ deploy/roles/helm_delete/tasks/main.yml | 24 +++ deploy/roles/helm_install/tasks/main.yml | 43 +++++ deploy/roles/helm_upgrade/tasks/main.yml | 27 ++++ .../tasks/list_application_deployments.yml | 29 ++++ .../list_application_deployments/tasks/main.yml | 25 +++ .../return_value_list_application_deployments.j2 | 28 ++++ .../tasks/list_application_packages.yml | 29 ++++ .../roles/list_application_packages/tasks/main.yml | 25 +++ .../return_value_list_application_packages.j2 | 28 ++++ .../tasks/list_docker_images.yml | 52 ++++++ deploy/roles/list_docker_images/tasks/main.yml | 25 +++ .../tasks/return_value_list_docker_images.j2 | 24 +++ rpmbuild.spec | 85 ++++++++++ su/roles/su_prepare/tasks/main.yml | 154 ++++++++++++++++++ su/roles/su_prepare/tasks/merge-charts.yml | 96 +++++++++++ su/roles/su_prepare/tasks/merge-images.yml | 22 +++ su/su_prepare_playbook.yml | 23 +++ su/tasks/start_vnfc.yml | 33 ++++ su/tasks/wait_pod_start.yml | 33 ++++ 35 files changed, 1398 insertions(+) create mode 100644 LICENSE create mode 100644 ansible/playbooks/pre_config_lcm.yaml create mode 100644 ansible/roles/pre_config_lcm/tasks/main.yml create mode 100644 deploy/group_vars/controller-1.caas_master/params.yml create mode 100644 deploy/playbook_bm_onboard.yml create mode 100644 deploy/playbook_clean_chart.yml create mode 100644 deploy/playbook_clean_registry.yml create mode 100644 deploy/playbook_helm_delete.yml create mode 100644 deploy/playbook_helm_install.yml create mode 100644 deploy/playbook_helm_upgrade.yml create mode 100644 deploy/playbook_list_application_deployments.yml create mode 100644 deploy/playbook_list_application_packages.yml create mode 100644 deploy/playbook_list_docker_images.yml create mode 100644 deploy/roles/bm_onboard/tasks/main.yml create mode 100644 deploy/roles/clean_chart/tasks/main.yml create mode 100644 deploy/roles/clean_registry/tasks/main.yml create mode 100644 deploy/roles/helm_delete/tasks/main.yml create mode 100644 deploy/roles/helm_install/tasks/main.yml create mode 100644 deploy/roles/helm_upgrade/tasks/main.yml create mode 100644 deploy/roles/list_application_deployments/tasks/list_application_deployments.yml create mode 100644 deploy/roles/list_application_deployments/tasks/main.yml create mode 100644 deploy/roles/list_application_deployments/tasks/return_value_list_application_deployments.j2 create mode 100644 deploy/roles/list_application_packages/tasks/list_application_packages.yml create mode 100644 deploy/roles/list_application_packages/tasks/main.yml create mode 100644 deploy/roles/list_application_packages/tasks/return_value_list_application_packages.j2 create mode 100644 deploy/roles/list_docker_images/tasks/list_docker_images.yml create mode 100644 deploy/roles/list_docker_images/tasks/main.yml create mode 100644 deploy/roles/list_docker_images/tasks/return_value_list_docker_images.j2 create mode 100644 rpmbuild.spec create mode 100644 su/roles/su_prepare/tasks/main.yml create mode 100644 su/roles/su_prepare/tasks/merge-charts.yml create mode 100644 su/roles/su_prepare/tasks/merge-images.yml create mode 100644 su/su_prepare_playbook.yml create mode 100644 su/tasks/start_vnfc.yml create mode 100644 su/tasks/wait_pod_start.yml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e454a52 --- /dev/null +++ b/LICENSE @@ -0,0 +1,178 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ansible/playbooks/pre_config_lcm.yaml b/ansible/playbooks/pre_config_lcm.yaml new file mode 100644 index 0000000..2b5ef2c --- /dev/null +++ b/ansible/playbooks/pre_config_lcm.yaml @@ -0,0 +1,22 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# cmframework.requires: pre_config_all.yaml +- hosts: caas_master + strategy: free + become: true + become_user: "{{ users.admin_user_name }}" + roles: + - pre_config_lcm diff --git a/ansible/roles/pre_config_lcm/tasks/main.yml b/ansible/roles/pre_config_lcm/tasks/main.yml new file mode 100644 index 0000000..e5583c3 --- /dev/null +++ b/ansible/roles/pre_config_lcm/tasks/main.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: generating {{ lcm_path }}/deploy/inventory for LCM workflows + copy: + content: | + #!/bin/bash + cat <<"EOF" + {{ lookup('pipe', '/usr/local/bin/cmcli --ip 127.0.0.1 ansible-inventory') }} + EOF + mode: 0500 + owner: "{{ users.admin_user_name }}" + dest: {{ lcm_path }}/deploy/inventory + become_user: "root" + when: nodename | search("caas_master1") diff --git a/deploy/group_vars/controller-1.caas_master/params.yml b/deploy/group_vars/controller-1.caas_master/params.yml new file mode 100644 index 0000000..b9e7ced --- /dev/null +++ b/deploy/group_vars/controller-1.caas_master/params.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +logics: "{% if vnf_context_data is defined %}{{vnf_context_data.operation_params.additionalParams.level}}{% else %}['common']{% endif %}" +use_local_manifest: false +use_local_versions: false +cbam: false +helm_install_set: "" + +swift_admin_path: "/etc/swift/usr/admin" +image_versions_path: "{{ caas_manifest_path }}" +manifest_path: "{{ use_local_manifest|bool | ternary('manifests', '/tmp') }}" diff --git a/deploy/playbook_bm_onboard.yml b/deploy/playbook_bm_onboard.yml new file mode 100644 index 0000000..4b485a5 --- /dev/null +++ b/deploy/playbook_bm_onboard.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: "{{ users.admin_user_name }}" + roles: + - bm_onboard diff --git a/deploy/playbook_clean_chart.yml b/deploy/playbook_clean_chart.yml new file mode 100644 index 0000000..61f23f0 --- /dev/null +++ b/deploy/playbook_clean_chart.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - clean_chart + diff --git a/deploy/playbook_clean_registry.yml b/deploy/playbook_clean_registry.yml new file mode 100644 index 0000000..c7ca920 --- /dev/null +++ b/deploy/playbook_clean_registry.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - clean_registry + diff --git a/deploy/playbook_helm_delete.yml b/deploy/playbook_helm_delete.yml new file mode 100644 index 0000000..140ed3b --- /dev/null +++ b/deploy/playbook_helm_delete.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - helm_delete diff --git a/deploy/playbook_helm_install.yml b/deploy/playbook_helm_install.yml new file mode 100644 index 0000000..8e5f0af --- /dev/null +++ b/deploy/playbook_helm_install.yml @@ -0,0 +1,22 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + strategy: linear + remote_user: cloudadmin + roles: + - role: helm_delete + - helm_install diff --git a/deploy/playbook_helm_upgrade.yml b/deploy/playbook_helm_upgrade.yml new file mode 100644 index 0000000..6576646 --- /dev/null +++ b/deploy/playbook_helm_upgrade.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - helm_upgrade diff --git a/deploy/playbook_list_application_deployments.yml b/deploy/playbook_list_application_deployments.yml new file mode 100644 index 0000000..4fdac04 --- /dev/null +++ b/deploy/playbook_list_application_deployments.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - list_application_deployments diff --git a/deploy/playbook_list_application_packages.yml b/deploy/playbook_list_application_packages.yml new file mode 100644 index 0000000..d078193 --- /dev/null +++ b/deploy/playbook_list_application_packages.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - list_application_packages diff --git a/deploy/playbook_list_docker_images.yml b/deploy/playbook_list_docker_images.yml new file mode 100644 index 0000000..90eb914 --- /dev/null +++ b/deploy/playbook_list_docker_images.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + remote_user: cloudadmin + roles: + - list_docker_images diff --git a/deploy/roles/bm_onboard/tasks/main.yml b/deploy/roles/bm_onboard/tasks/main.yml new file mode 100644 index 0000000..c59554b --- /dev/null +++ b/deploy/roles/bm_onboard/tasks/main.yml @@ -0,0 +1,52 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: set cloudadmin home + set_fact: + home: "/home/{{ users.admin_user_name }}/" + +- name: find app images + find: + paths: "{{ home }}" + patterns: '{{app_image_name}}*' + register: app_image_properties + +- fail: + msg: "There is no app image in {{ home }} folder" + when: app_image_properties.files == [] + +- name: get app image extension + shell: "qemu-img info {{ app_image_properties.files[0].path }} | grep \"file format:\" | cut -d\" \" -f3" + register: app_image_format + +- name: convert image if needed + shell: "qemu-img convert -f {{ app_image_format.stdout }} -O raw {{ app_image_properties.files[0].path }} {{ app_image_properties.files[0].path }}.raw" + when: app_image_format.stdout != "raw" + +- name: Run existing SU ansible to onboard Swift image content to deployed Swift workspace + shell: '/usr/bin/ansible-playbook -i {{ lcm_path }}/deploy/inventory {{ lcm_path }}/su/su_prepare_playbook.yml -e "swift_image_path={{ app_image_properties.files[0].path }}.raw"' + +- name: find app images + find: + paths: "{{ home }}" + patterns: "{{ app_image_properties.files[0].path | basename }}*" + register: files_to_delete + +- name: delete app images + file: + path: "{{ item.path }}" + state: absent + with_items: "{{ files_to_delete.files }}" + diff --git a/deploy/roles/clean_chart/tasks/main.yml b/deploy/roles/clean_chart/tasks/main.yml new file mode 100644 index 0000000..1b1afb7 --- /dev/null +++ b/deploy/roles/clean_chart/tasks/main.yml @@ -0,0 +1,59 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: fetch files from server which contains the necessary variables + fetch: src={{ item }} dest=/tmp/ flat=yes + with_items: + - /etc/swift/usr/admin/admin.yml + +- name: register infos for swift_auth + set_fact: + swift_credential: "{{ lookup('file', swift_admin_path + '/admin.yml') | from_yaml }}" + +- name: authenticate on swift + uri: + url: "{{ caas.swift }}/auth/v1.0" + headers: + X_Auth_User: admin:admin + X_Auth_Key: "{{ swift_credential.swift_password }}" + register: auth + +- name: clean charts list file if exists + file: + path: /tmp/charts_list + state: absent + +- name: get current charts list + shell: "curl -H'X_Auth_Token: {{ auth.x_auth_token }}' {{ caas.swift }}/v1.0/AUTH_admin/packages > /tmp/charts_list" + +- name: chart_pattern + set_fact: + chart_pattern: "{{ chart_name | replace('*', '.*') }}" + +- name: version_pattern + set_fact: + version_pattern: "{{ chart_version | replace('*', '[0-9]+') }}" + +- name: search + shell: cat /tmp/charts_list | egrep "charts/{{ chart_pattern }}-[0-9]+\.[0-9]+\.[0-9]+" | egrep "{{ version_pattern }}\.tgz" + register: chart_matched + +- name: delete the chart from swift + shell: "curl -XDELETE {{ caas.chart_repo }}/{{ item }}" + with_items: "{{ chart_matched.stdout_lines }}" + +- name: helm repo update + shell: helm repo update default {{ caas.chart_repo }}/charts + diff --git a/deploy/roles/clean_registry/tasks/main.yml b/deploy/roles/clean_registry/tasks/main.yml new file mode 100644 index 0000000..17b001e --- /dev/null +++ b/deploy/roles/clean_registry/tasks/main.yml @@ -0,0 +1,47 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: get the properties of the image:tag manifest + shell: "curl -i -H'Accept: application/vnd.docker.distribution.manifest.v2+json' {{ registry }}/v2/{{ image_name }}/manifests/{{ image_tag }}" + register: result + +- fail: + msg: "{{ image_name }}/manifests/{{ image_tag }} manifest not found!" + when: ( result.stdout.find("MANIFEST_UNKNOWN") != -1) + +- name: get the properties of the image:tag manifest + shell: "echo '{{ result.stdout }}' > /tmp/{{ image_name|replace('/', '_') }}_{{ image_tag }}.manifest" + +- name: get the digest property + shell: grep Docker-Content-Digest /tmp/{{ image_name|replace('/', '_') }}_{{ image_tag }}.manifest | awk -F" " '{print $2}' + register: Docker_Content_Digest + +- name: delete the manifest using the digest property + shell: "curl -XDELETE -H'Accept: application/vnd.docker.distribution.manifest.v2+json' {{ registry }}/v2/{{ image_name }}/manifests/{{ Docker_Content_Digest.stdout }}" + +- name: get a registry pod id + shell: kubectl get pods -n kube-system | grep registry | grep Running | head -n 1 | awk -F" " '{print $1}' + register: registry_pod_id + +- fail: + msg: "failure: no registry pod running" + when: ( registry_pod_id.stdout == "" ) + +- name: get the registry config file + shell: kubectl exec {{ registry_pod_id.stdout }} -c registry -n kube-system -- ps -o args | grep "registry serve" | awk -F'serve ' '{print $2}' + register: registry_config_file + +- name: run the registry garbage collector + shell: kubectl exec {{ registry_pod_id.stdout }} -c registry -n kube-system -- /usr/bin/registry garbage-collect {{ registry_config_file.stdout }} > /tmp/{{ image_name|replace('/', '_') }}_{{ image_tag }}.gclog diff --git a/deploy/roles/helm_delete/tasks/main.yml b/deploy/roles/helm_delete/tasks/main.yml new file mode 100644 index 0000000..ce35241 --- /dev/null +++ b/deploy/roles/helm_delete/tasks/main.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: run helm delete from install workflow + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm delete {{ release_name|lower }} --purge --timeout {{ helm_operation_timeout }} + ignore_errors: yes + when: del_workflow is not defined + +- name: run helm delete from delete workflow + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm delete {{ release_name|lower }} --purge --timeout {{ helm_operation_timeout }} + when: del_workflow is defined + diff --git a/deploy/roles/helm_install/tasks/main.yml b/deploy/roles/helm_install/tasks/main.yml new file mode 100644 index 0000000..cc8cd2a --- /dev/null +++ b/deploy/roles/helm_install/tasks/main.yml @@ -0,0 +1,43 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: helm-list + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm list --all | grep -i {{ release_name|lower }} | wc -l + register: list_result + until: list_result.stdout != 0 + retries: 5 + delay: 2 + +- pause: + seconds: 30 + +- name: set helm_install_set if undefined + set_fact: + helm_install_set: "" + when: ( helm_install_set is not defined ) or ( helm_install_set is none ) + +- name: set helm_flags if undefined + set_fact: + helm_flags: "" + when: ( helm_flags is not defined ) or ( helm_flags is none ) + +- name: run helm install + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm install default/{{ chart_name }} --name {{ release_name|lower }} {{ helm_flags }} --wait --timeout {{ helm_operation_timeout }} {{ helm_install_set }} + register: helm_result + + +- name: print result + debug: + msg: "{{ helm_result.stdout }}" diff --git a/deploy/roles/helm_upgrade/tasks/main.yml b/deploy/roles/helm_upgrade/tasks/main.yml new file mode 100644 index 0000000..96c9b77 --- /dev/null +++ b/deploy/roles/helm_upgrade/tasks/main.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: set helm_flags if undefined + set_fact: + helm_flags: "" + when: ( helm_flags is not defined ) or ( helm_flags is none ) + +- name: run helm upgrade + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm upgrade {{ release_name|lower }} default/{{ chart_name }} {{ helm_flags }} + register: helm_result + +- name: print result + debug: + msg: "{{ helm_result.stdout }}" diff --git a/deploy/roles/list_application_deployments/tasks/list_application_deployments.yml b/deploy/roles/list_application_deployments/tasks/list_application_deployments.yml new file mode 100644 index 0000000..7db267c --- /dev/null +++ b/deploy/roles/list_application_deployments/tasks/list_application_deployments.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: list application deployments + user: cloudadmin + hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + gather_facts: "False" + tasks: + - name: list application deployments + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm list --all | tr '\n' ',' | tr '\t' ' ' + register: list_application_deployments_result + + - name: create a json from list of application deployments + template: + src: "return_value_list_application_deployments.j2" + dest: "/tmp/return_value_list_application_deployments.json" diff --git a/deploy/roles/list_application_deployments/tasks/main.yml b/deploy/roles/list_application_deployments/tasks/main.yml new file mode 100644 index 0000000..7a74970 --- /dev/null +++ b/deploy/roles/list_application_deployments/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: run ansible + shell: "/usr/bin/ansible-playbook -i {{ lcm_path }}/deploy/inventory {{ lcm_path }}/deploy/roles/list_application_deployments/tasks/list_application_deployments.yml" + environment: + ANSIBLE_RETRY_FILES_ENABLED: 'False' + +- name: save the result of helm list + fetch: + src: "/tmp/return_value_list_application_deployments.json" + dest: "~/ansible-execution-result.json" + flat: "yes" diff --git a/deploy/roles/list_application_deployments/tasks/return_value_list_application_deployments.j2 b/deploy/roles/list_application_deployments/tasks/return_value_list_application_deployments.j2 new file mode 100644 index 0000000..235939e --- /dev/null +++ b/deploy/roles/list_application_deployments/tasks/return_value_list_application_deployments.j2 @@ -0,0 +1,28 @@ +{# +Copyright 2019 Nokia + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#} +{% set application_deployments_result = list_application_deployments_result.stdout.split(",") %} +{ +"application_deployments_result" : [ +{%- for item in application_deployments_result[:-1] %} + {% if loop.last %} + {{ item|to_json }} + {% else %} + {{ item|to_json }}, + {% endif %} +{% endfor -%} + ] + +} diff --git a/deploy/roles/list_application_packages/tasks/list_application_packages.yml b/deploy/roles/list_application_packages/tasks/list_application_packages.yml new file mode 100644 index 0000000..4b97cb5 --- /dev/null +++ b/deploy/roles/list_application_packages/tasks/list_application_packages.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: list application packages + user: cloudadmin + hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + gather_facts: "False" + tasks: + - name: list application packages + shell: HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }} helm search | tr '\n' ',' | tr '\t' ' ' + register: list_application_packages_result + + - name: create a json from list of application packages + template: + src: "return_value_list_application_packages.j2" + dest: "/tmp/return_value_list_application_packages.json" diff --git a/deploy/roles/list_application_packages/tasks/main.yml b/deploy/roles/list_application_packages/tasks/main.yml new file mode 100644 index 0000000..95b7c2c --- /dev/null +++ b/deploy/roles/list_application_packages/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: run ansible + shell: "/usr/bin/ansible-playbook -i {{ lcm_path }}/deploy/inventory {{ lcm_path }}/deploy/roles/list_application_packages/tasks/list_application_packages.yml" + environment: + ANSIBLE_RETRY_FILES_ENABLED: 'False' + +- name: save the result of application packages list + fetch: + src: "/tmp/return_value_list_application_packages.json" + dest: "~/ansible-execution-result.json" + flat: "yes" diff --git a/deploy/roles/list_application_packages/tasks/return_value_list_application_packages.j2 b/deploy/roles/list_application_packages/tasks/return_value_list_application_packages.j2 new file mode 100644 index 0000000..536fbe6 --- /dev/null +++ b/deploy/roles/list_application_packages/tasks/return_value_list_application_packages.j2 @@ -0,0 +1,28 @@ +{# +Copyright 2019 Nokia + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#} +{% set application_packages_temp = list_application_packages_result.stdout.split(",") %} +{ +"application_packages" : [ +{%- for item in application_packages_temp[:-1] %} + {% if loop.last %} + {{ item|to_json }} + {% else %} + {{ item|to_json }}, + {% endif %} +{% endfor -%} + ] + +} diff --git a/deploy/roles/list_docker_images/tasks/list_docker_images.yml b/deploy/roles/list_docker_images/tasks/list_docker_images.yml new file mode 100644 index 0000000..dfbca09 --- /dev/null +++ b/deploy/roles/list_docker_images/tasks/list_docker_images.yml @@ -0,0 +1,52 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: List docker images and tags + user: cloudadmin + hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + gather_facts: "False" + tasks: + - name: Get images + register: images_result + command: '/usr/bin/curl -sS + --key /etc/docker-registry/registry{{ nodeindex }}-key.pem + --cert /etc/docker-registry/registry{{ nodeindex }}.pem + {{ caas.registry }}/v2/_catalog' + + - name: Get tags from image names + register: tags_result + command: '/usr/bin/curl -sS + --key /etc/docker-registry/registry{{ nodeindex }}-key.pem + --cert /etc/docker-registry/registry{{ nodeindex }}.pem + -H "Accept: application/vnd.docker.distribution.manifest.v2+json" + {{ caas.registry }}/v2/{{ item }}/tags/list' + with_items: + - "{{ (images_result.stdout|from_json).repositories }}" + + - name: List of image names and tags + set_fact: + image_names_and_tags: {} + + - name: Create images names and tags dictionary + set_fact: + image_names_and_tags: "{{ image_names_and_tags|combine( {(item.stdout|from_json).name: (item.stdout|from_json).tags} ) }}" + with_items: + - "{{ tags_result.results }}" + + - name: Create a json from list of docker images and tags + template: + src: "return_value_list_docker_images.j2" + dest: "/tmp/return_value_list_docker_images.json" diff --git a/deploy/roles/list_docker_images/tasks/main.yml b/deploy/roles/list_docker_images/tasks/main.yml new file mode 100644 index 0000000..a321506 --- /dev/null +++ b/deploy/roles/list_docker_images/tasks/main.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: run ansible + shell: "/usr/bin/ansible-playbook -i {{ lcm_path }}/deploy/inventory {{ lcm_path }}/deploy/roles/list_docker_images/tasks/list_docker_images.yml" + environment: + ANSIBLE_RETRY_FILES_ENABLED: 'False' + +- name: save the result of images and tags + fetch: + src: "/tmp/return_value_list_docker_images.json" + dest: "~/ansible-execution-result.json" + flat: "yes" diff --git a/deploy/roles/list_docker_images/tasks/return_value_list_docker_images.j2 b/deploy/roles/list_docker_images/tasks/return_value_list_docker_images.j2 new file mode 100644 index 0000000..7019951 --- /dev/null +++ b/deploy/roles/list_docker_images/tasks/return_value_list_docker_images.j2 @@ -0,0 +1,24 @@ +{# +Copyright 2019 Nokia + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +#} +{ + {% for key,value in image_names_and_tags.items() %} + {% if loop.last %} + "{{ key }}" : "{{ value|join(', ') }}" + {% else %} + "{{ key }}" : "{{ value|join(', ') }}", + {% endif %} + {% endfor %} +} diff --git a/rpmbuild.spec b/rpmbuild.spec new file mode 100644 index 0000000..65ae61f --- /dev/null +++ b/rpmbuild.spec @@ -0,0 +1,85 @@ +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +%define COMPONENT lcm +%define RPM_NAME caas-%{COMPONENT} +%define RPM_MAJOR_VERSION 1.0.0 +%define RPM_MINOR_VERSION 1 +%define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSIONi} +%define LCM_PATH /opt/caas_lcm +%define DEPLOY_PATH %{LCM_PATH}/deploy +%define SU_PATH %{LCM_PATH}/su + +Name: %{RPM_NAME} +Version: %{RPM_MAJOR_VERSION} +Release: %{RPM_MINOR_VERSION}%{?dist} +Summary: Containers as a Service Life Cycle Managemnet workflows +License: %{_platform_license} +BuildArch: x86_64 +Vendor: %{_platform_vendor} +Source0: %{name}-%{version}.tar.gz + +Requires: rsync >= 3.1.0 + +%description +This RPM contains Life Cycle Managemnet workflows for the CaaS subsystem. + +%prep +%autosetup + +%build + +%install +mkdir -p %{buildroot}/%{SU_PATH}/ +rsync -av su/* %{buildroot}/%{SU_PATH}/ + +mkdir -p %{buildroot}/%{DEPLOY_PATH}/ +rsync -av deploy/* %{buildroot}/%{DEPLOY_PATH}/ + +mkdir -p %{buildroot}/%{_playbooks_path}/ +rsync -av ansible/playbooks/pre_config_lcm.yaml %{buildroot}/%{_playbooks_path}/ + +mkdir -p %{buildroot}/%{_roles_path}/ +rsync -av ansible/roles/pre_config_lcm %{buildroot}/%{_roles_path}/ + +# ------- set lcm path inside deploy +sed -i 's|{{ lcm_path }}|%{LCM_PATH}|g' %{buildroot}/%{DEPLOY_PATH}/roles/bm_onboard/tasks/main.yml +sed -i 's|{{ lcm_path }}|%{LCM_PATH}|g' %{buildroot}/%{DEPLOY_PATH}/roles/list_application_deployments/tasks/main.yml +sed -i 's|{{ lcm_path }}|%{LCM_PATH}|g' %{buildroot}/%{DEPLOY_PATH}/roles/list_application_packages/tasks/main.yml +sed -i 's|{{ lcm_path }}|%{LCM_PATH}|g' %{buildroot}/%{DEPLOY_PATH}/roles/list_docker_images/tasks/main.yml +sed -i 's|{{ caas_manifest_path }}|%{_caas_manifest_path}|g' %{buildroot}/%{DEPLOY_PATH}/group_vars/controller-1.caas_master/params.yml +# ------- set lcm path inside roles +sed -i 's|{{ lcm_path }}|%{LCM_PATH}|g' %{buildroot}/%{_roles_path}/pre_config_lcm/tasks/main.yml +# ------- + +%files +%{SU_PATH} +%{DEPLOY_PATH} +%{_playbooks_path}/pre_config_lcm.yaml +%{_roles_path}/pre_config_lcm + +%preun + +%post +mkdir -p %{_postconfig_path}/ +ln -sf %{_playbooks_path}/pre_config_lcm.yaml %{_postconfig_path}/ + +%postun +if [ $1 -eq 0 ]; then + rm -f %{_postconfig_path}/pre_config_lcm.yaml +fi + +%clean +rm -rf ${buildroot} + diff --git a/su/roles/su_prepare/tasks/main.yml b/su/roles/su_prepare/tasks/main.yml new file mode 100644 index 0000000..bb18342 --- /dev/null +++ b/su/roles/su_prepare/tasks/main.yml @@ -0,0 +1,154 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- set_fact: + start_time: "{{ lookup('pipe', 'date +%Y%m%d-%H:%M:%S') }}" + +- file: + path: "/var/log/sw_package_load.log" + state: absent + become: true + + +- lineinfile: + dest: "/var/log/sw_package_load.log" + create: yes + line: "start_time: {{ start_time }}" + become: true + +- block: + - name: Compose the device path of swift volume on BareMetal + set_fact: + swift_dev: "{{ swift_image_path }}" + + - name: Run what_is_the_filesystem.yml + include_role: + name: common_tasks + tasks_from: what_is_the_filesystem.yml + vars: + device: "{{swift_dev}}" + + - name: Mount the device + mount: + name: /srv/node/swift-update/ + src: "{{swift_dev}}" + fstype: "{{ filesystem_type.stdout | lower | default('ext4') }}" + state: mounted + become: true + when: swift_image_path is defined and swift_image_path != "" + +- name: Prepare mount dir + file: + path: /srv/node/swift-update/ + state: directory + mode: 0755 + owner: 146 + group: 146 + recurse: yes + become: true + +- block: + - include: tasks/start_vnfc.yml + vars: + vnfcs: + - swift_update + - swift_update_service + - docker-registry-update + - update_registry_service + + - include: tasks/wait_pod_start.yml + vars: + name: swift-update + ccount: 1 + + - name: wait for container service - swift-update + wait_for: + host: "{{ groups.caas_master[0] }}" + port: "{{ caas.update_swift_port }}" + state: started + timeout: 300 + + - include: tasks/wait_pod_start.yml + vars: + name: registry-update + ccount: 1 + + - name: wait for registry-update kubernetes service to start + wait_for: + host: "{{ caas.update_registry_url }}" + port: "{{ caas.update_registry_port }}" + state: started + timeout: 60 + + + - name: wait for swift-update kubernetes service to start + wait_for: + host: "{{ caas.swift_update_url }}" + port: "{{ caas.update_swift_port }}" + state: started + timeout: 60 + + - include: merge-charts.yml + - include: merge-images.yml + + rescue: + - debug: + msg: Something went wrong during merge. + + always: + - name: clean after charts upload + file: + state: absent + path: /tmp/su_chart + + - name: Delete the registry and swift for su + shell: kubectl delete -f /var/lib/caas/manifests/{{item}} + with_items: + - update_registry_service.yml + - docker-registry-update.yml + - swift_update_service.yml + - swift_update.yml + + - name: Wait for registry and swift deleted + shell: kubectl get pods --all-namespaces | grep -c {{item}} + register: ret_rc + until: ret_rc.stdout == "0" + failed_when: ret_rc.stdout == "" + retries: 60 + delay: 5 + with_items: + - swift-update + - registry-update + + - name: Umount the device of the new swift volume + mount: + name: /srv/node/swift-update/ + src: "{{swift_dev}}" + state: unmounted + become: true + + - name: Make sure the fstab entry is removed + mount: + name: /srv/node/swift-update/ + src: "{{swift_dev}}" + state: absent + become: true + + - lineinfile: + dest: "/var/log/sw_package_load.log" + state: present + line: "end_time: {{ lookup('pipe', 'date +%Y%m%d-%H:%M:%S') }}" + become: true + diff --git a/su/roles/su_prepare/tasks/merge-charts.yml b/su/roles/su_prepare/tasks/merge-charts.yml new file mode 100644 index 0000000..cff001a --- /dev/null +++ b/su/roles/su_prepare/tasks/merge-charts.yml @@ -0,0 +1,96 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: fetch files from server which contains the necessary variables + fetch: + src: /etc/swift/usr/admin/admin.yml + dest: /tmp/ + flat: yes + +- name: register infos for swift_auth + set_fact: + swift_credential: "{{ lookup('file', '/tmp/admin.yml') | from_yaml }}" + +- name: pause to wait for swift-update to be ready + pause: + minutes: 1 + +- name: authenticate on swift-upgrade + uri: + url: "{{ caas.swift_update }}/auth/v1.0" + headers: + X_Auth_User: admin:admin + X_Auth_Key: "{{ swift_credential.swift_password }}" + register: auth + +- name: get packages + uri: + url: "{{ caas.swift_update }}/v1.0/AUTH_admin/packages" + return_content: yes + headers: + X_Auth_Token: "{{ auth.x_auth_token }}" + register: packages + +- name: get charts from packages + set_fact: + charts: "{{ (packages.get('content','')|trim).split('\n') | select('search', 'charts.+\\.tgz') | list }}" + +- name: get value files from packages + set_fact: + value_files: "{{ (packages.get('content','')|trim).split('\n') | select('search', 'releases.+\\.yaml') | list }}" + ignore_errors: yes + +- name: create chart directory + file: + name: /tmp/su_chart + state: directory + +- name: download charts + args: + chdir: /tmp/su_chart + command: "curl -O -XGET -H'X-Auth-Token: {{ auth.x_auth_token }}' {{ caas.swift_update }}/v1.0/AUTH_admin/packages/{{ item }}" + with_items: "{{ charts }}" + +- name: download value files + args: + chdir: /tmp/su_chart + command: "curl -O -XGET -H'X-Auth-Token: {{ auth.x_auth_token }}' {{ caas.swift_update }}/v1.0/AUTH_admin/packages/{{ item }}" + with_items: "{{ value_files }}" + ignore_errors: yes + +- name: upload charts via chart-repo + args: + chdir: /tmp/su_chart/ + shell: "curl -sS -XPOST --cacert /etc/chart-repo/ssl/ca.pem --cert /etc/chart-repo/ssl/chart-repo?.pem --key /etc/chart-repo/ssl/chart-repo?-key.pem -H 'Content-Type: application/gzip' --data-binary @{{ item | basename }} {{ caas.chart_repo }}/{{ item }}" + with_items: "{{ charts }}" + +- name: helm repo update + shell: helm repo update default {{ caas.chart_repo }}/charts + +- name: authenticate on swift + uri: + url: "{{ caas.swift }}/auth/v1.0" + headers: + X_Auth_User: admin:admin + X_Auth_Key: "{{ swift_credential.swift_password }}" + register: auth_orig + ignore_errors: yes + +- name: upload value file via swift + args: + chdir: /tmp/su_chart/ + shell: "curl -XPUT -H 'X-Auth-Token: {{ auth_orig.x_auth_token }}' -T {{ item | basename }} {{ caas.swift }}/v1.0/AUTH_admin/packages/{{ item }}" + with_items: "{{ value_files }}" + ignore_errors: yes diff --git a/su/roles/su_prepare/tasks/merge-images.yml b/su/roles/su_prepare/tasks/merge-images.yml new file mode 100644 index 0000000..3a0abc9 --- /dev/null +++ b/su/roles/su_prepare/tasks/merge-images.yml @@ -0,0 +1,22 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: List all the image repo in the new registry + shell: curl --cert /etc/docker-update-registry/update-registry.pem --key /etc/docker-update-registry/update-registry-key.pem --cacert /etc/docker-update-registry/ca.pem {{ caas.update_registry }}/v2/_catalog + register: ret_repo_in_new_registry + +# Tags may different between images. So we get tag for each image in script. +- name: Merge new images to original registry + shell: /usr/libexec/nokia/merge_image.sh --from-registry={{ caas.update_registry_url }}:{{ caas.update_registry_port }} --to-registry={{ caas.registry_url }}:{{ caas.registry_port }} "{{ ret_repo_in_new_registry.stdout }}" diff --git a/su/su_prepare_playbook.yml b/su/su_prepare_playbook.yml new file mode 100644 index 0000000..bead93f --- /dev/null +++ b/su/su_prepare_playbook.yml @@ -0,0 +1,23 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Software upgrade preparation + strategy: linear + hosts: "{{ groups.caas_master[0] | default('nowhere') }}" + connection: local + user: cloudadmin + gather_facts: false + roles: + - role: su_prepare diff --git a/su/tasks/start_vnfc.yml b/su/tasks/start_vnfc.yml new file mode 100644 index 0000000..afaffe7 --- /dev/null +++ b/su/tasks/start_vnfc.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- block: + - name: "create vnfcs" + command: "/bin/kubectl create -f /var/lib/caas/manifests/{{ item }}.yml" + with_items: "{{ vnfcs }}" + register: out + until: out|succeeded or (out.stderr.find('already exists') != -1) + retries: 3 + delay: 2 + rescue: + - debug: + msg: "[Info]: VNFC already exists" + when: item.find('already exists') != -1 + with_items: "{{ out.results|map(attribute='stderr')|list }}" + + - fail: + msg: "{{ item }}" + when: item and (item.find('already exists') == -1) + with_items: "{{ out.results|map(attribute='stderr')|list }}" diff --git a/su/tasks/wait_pod_start.yml b/su/tasks/wait_pod_start.yml new file mode 100644 index 0000000..bab0a97 --- /dev/null +++ b/su/tasks/wait_pod_start.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: assemble regular expressions + set_fact: + wait_regex_all: '^({{ name }}[\.\w\d-]+)' + wait_regex_ok: '^({{ name }}[\.\w\d-]+) +({{ ccount }}/{{ ccount }}) +(Running)' + +- block: + - name: wait for pods to start + command: /usr/bin/kubectl get po --namespace kube-system + register: result + until: (result.stdout_lines|select("search", wait_regex_all)|list|length == result.stdout_lines|select("search", wait_regex_ok)|list|length) + and + (result.stdout_lines|select("search", wait_regex_all)|list|length > 0) + retries: 24 # 2 minutes + delay: 5 + + rescue: + - debug: + msg: "[Warning]: Pods for {{ name }} did not start as expected." -- 2.16.6