From 5d958b07761b3e9339d6a9b636578d55facb794c Mon Sep 17 00:00:00 2001 From: Matthieu Huguet Date: Wed, 8 Jan 2020 17:56:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(playbook)=20introduce=20static=20serv?= =?UTF-8?q?ices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for static services, with fixed name, in addition to the services deployed with a deployment stamp in their name. It allows applications inside the cluster to use the services exposed by other applications, with a consistent fqdn. BREAKING CHANGE : blue/green related tasks are now updating static services instead of routes --- CHANGELOG.md | 4 ++ .../templates/services/nginx/route_cms.yml.j2 | 3 +- .../templates/services/nginx/route_lms.yml.j2 | 3 +- .../services/nginx/route_preview.yml.j2 | 3 +- .../services/nginx/static-svc.yml.j2 | 30 ++++++++++++ .../templates/services/nginx/route.yml.j2 | 3 +- .../services/nginx/static-svc.yml.j2 | 26 +++++++++++ .../forum/templates/services/app/route.yml.j2 | 3 +- .../templates/services/app/static-svc.yml.j2 | 22 +++++++++ .../hello/templates/services/app/route.yml.j2 | 2 +- .../templates/services/app/static-svc.yml.j2 | 20 ++++++++ .../templates/services/nginx/route.yml.j2 | 3 +- .../services/nginx/static-svc.yml.j2 | 26 +++++++++++ .../templates/services/nginx/route.yml.j2 | 3 +- .../services/nginx/static-svc.yml.j2 | 26 +++++++++++ .../templates/services/nginx/route.yml.j2 | 3 +- .../services/nginx/static-svc.yml.j2 | 26 +++++++++++ create_services.yml | 20 ++++++++ delete_previous.yml | 4 +- deploy.yml | 8 ++-- group_vars/all/main.yml | 2 +- init_project.yml | 1 + rollback.yml | 2 +- switch.yml | 14 +++--- tasks/clean_app_orphans.yml | 2 +- tasks/create_static_services.yml | 10 ++++ tasks/create_static_services_routes.yml | 2 +- tasks/delete_app_objects_kind.yml | 2 + tasks/deploy_get_stamp_from_route.yml | 46 ------------------- .../deploy_get_stamp_from_static_service.yml | 37 +++++++++++++++ tasks/deploy_patch_static_service.yml | 23 ++++++++++ tasks/get_objects_for_app.yml | 1 + ...outes.yml => rollback_static_services.yml} | 12 ++--- tasks/switch_route.yml | 24 ---------- tasks/switch_static_service.yml | 23 ++++++++++ ..._routes.yml => switch_static_services.yml} | 12 ++--- 36 files changed, 335 insertions(+), 116 deletions(-) create mode 100644 apps/edxapp/templates/services/nginx/static-svc.yml.j2 create mode 100644 apps/edxec/templates/services/nginx/static-svc.yml.j2 create mode 100644 apps/forum/templates/services/app/static-svc.yml.j2 create mode 100644 apps/hello/templates/services/app/static-svc.yml.j2 create mode 100644 apps/learninglocker/templates/services/nginx/static-svc.yml.j2 create mode 100644 apps/marsha/templates/services/nginx/static-svc.yml.j2 create mode 100644 apps/richie/templates/services/nginx/static-svc.yml.j2 create mode 100644 create_services.yml create mode 100644 tasks/create_static_services.yml delete mode 100644 tasks/deploy_get_stamp_from_route.yml create mode 100644 tasks/deploy_get_stamp_from_static_service.yml create mode 100644 tasks/deploy_patch_static_service.yml rename tasks/{rollback_routes.yml => rollback_static_services.yml} (55%) delete mode 100644 tasks/switch_route.yml create mode 100644 tasks/switch_static_service.yml rename tasks/{switch_routes.yml => switch_static_services.yml} (55%) diff --git a/CHANGELOG.md b/CHANGELOG.md index af41ec81a..d975c235e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased +### Added + +- Introduce static services to expose services to other apps with a fixed name + ### Fixed - Avoid downtime during a switch or rollback diff --git a/apps/edxapp/templates/services/nginx/route_cms.yml.j2 b/apps/edxapp/templates/services/nginx/route_cms.yml.j2 index c6a7239c3..1c5cfcd82 100644 --- a/apps/edxapp/templates/services/nginx/route_cms.yml.j2 +++ b/apps/edxapp/templates/services/nginx/route_cms.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "edxapp" service: "nginx" - version: "{{ edxapp_nginx_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "cms" annotations: @@ -25,4 +24,4 @@ spec: targetPort: "{{ edxapp_nginx_cms_port }}-tcp" to: kind: Service - name: "edxapp-nginx-{{ deployment_stamp }}" + name: "edxapp-nginx-{{ prefix }}" diff --git a/apps/edxapp/templates/services/nginx/route_lms.yml.j2 b/apps/edxapp/templates/services/nginx/route_lms.yml.j2 index 379d21eef..cee442c26 100644 --- a/apps/edxapp/templates/services/nginx/route_lms.yml.j2 +++ b/apps/edxapp/templates/services/nginx/route_lms.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "edxapp" service: "nginx" - version: "{{ edxapp_nginx_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "lms" annotations: @@ -25,4 +24,4 @@ spec: targetPort: "{{ edxapp_nginx_lms_port }}-tcp" to: kind: Service - name: "edxapp-nginx-{{ deployment_stamp }}" + name: "edxapp-nginx-{{ prefix }}" diff --git a/apps/edxapp/templates/services/nginx/route_preview.yml.j2 b/apps/edxapp/templates/services/nginx/route_preview.yml.j2 index 60c6f993e..93122a729 100644 --- a/apps/edxapp/templates/services/nginx/route_preview.yml.j2 +++ b/apps/edxapp/templates/services/nginx/route_preview.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "edxapp" service: "nginx" - version: "{{ edxapp_nginx_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "lms" annotations: @@ -25,4 +24,4 @@ spec: targetPort: "{{ edxapp_nginx_lms_port }}-tcp" to: kind: Service - name: "edxapp-nginx-{{ deployment_stamp }}" + name: "edxapp-nginx-{{ prefix }}" diff --git a/apps/edxapp/templates/services/nginx/static-svc.yml.j2 b/apps/edxapp/templates/services/nginx/static-svc.yml.j2 new file mode 100644 index 000000000..1330f4384 --- /dev/null +++ b/apps/edxapp/templates/services/nginx/static-svc.yml.j2 @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: edxapp + service: nginx + deployment_stamp: "{{ deployment_stamp }}" + service_prefix: "{{ prefix }}" + type: static-service + removable: "no" + name: "edxapp-nginx-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: "{{ edxapp_nginx_cms_port }}-tcp" + port: {{ edxapp_nginx_cms_port }} + protocol: TCP + targetPort: {{ edxapp_nginx_cms_port }} + - name: "{{ edxapp_nginx_lms_port }}-tcp" + port: {{ edxapp_nginx_lms_port }} + protocol: TCP + targetPort: {{ edxapp_nginx_lms_port }} + - name: "{{ edxapp_nginx_healthcheck_port }}-tcp" + port: {{ edxapp_nginx_healthcheck_port }} + protocol: TCP + targetPort: {{ edxapp_nginx_healthcheck_port }} + selector: + app: edxapp + deploymentconfig: "edxapp-nginx-{{ deployment_stamp | default('undefined', true) }}" + type: ClusterIP diff --git a/apps/edxec/templates/services/nginx/route.yml.j2 b/apps/edxec/templates/services/nginx/route.yml.j2 index 1a16cec82..cda0b0523 100644 --- a/apps/edxec/templates/services/nginx/route.yml.j2 +++ b/apps/edxec/templates/services/nginx/route.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "edxec" service: "nginx" - version: "{{ edxec_nginx_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "app" annotations: @@ -24,4 +23,4 @@ spec: targetPort: "{{ edxec_nginx_port }}-tcp" to: kind: Service - name: "edxec-nginx-{{ deployment_stamp }}" + name: "edxec-nginx-{{ prefix }}" diff --git a/apps/edxec/templates/services/nginx/static-svc.yml.j2 b/apps/edxec/templates/services/nginx/static-svc.yml.j2 new file mode 100644 index 000000000..5b2c7fabc --- /dev/null +++ b/apps/edxec/templates/services/nginx/static-svc.yml.j2 @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: edxec + service: nginx + deployment_stamp: "{{ deployment_stamp }}" + service_prefix: "{{ prefix }}" + type: static-service + removable: "no" + name: "edxec-nginx-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: {{ edxec_nginx_port }}-tcp + port: {{ edxec_nginx_port }} + protocol: TCP + targetPort: {{ edxec_nginx_port }} + - name: "{{ edxec_nginx_healthcheck_port }}-tcp" + port: {{ edxec_nginx_healthcheck_port }} + protocol: TCP + targetPort: {{ edxec_nginx_healthcheck_port }} + selector: + app: edxec + deploymentconfig: "edxec-nginx-{{ deployment_stamp | default('undefined', true) }}" + type: ClusterIP diff --git a/apps/forum/templates/services/app/route.yml.j2 b/apps/forum/templates/services/app/route.yml.j2 index 398212843..a0be95d93 100644 --- a/apps/forum/templates/services/app/route.yml.j2 +++ b/apps/forum/templates/services/app/route.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "forum" service: "app" - version: "{{ forum_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "app" annotations: @@ -24,4 +23,4 @@ spec: targetPort: "{{ forum_port }}-tcp" to: kind: Service - name: "forum-app-{{ deployment_stamp }}" + name: "forum-app-{{ prefix }}" diff --git a/apps/forum/templates/services/app/static-svc.yml.j2 b/apps/forum/templates/services/app/static-svc.yml.j2 new file mode 100644 index 000000000..da56722ce --- /dev/null +++ b/apps/forum/templates/services/app/static-svc.yml.j2 @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: forum + service: forum + deployment_stamp: "{{ deployment_stamp }}" + service_prefix: "{{ prefix }}" + type: static-service + removable: "no" + name: "forum-app-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: "{{ forum_port }}-tcp" + port: {{ forum_port }} + protocol: TCP + targetPort: {{ forum_port }} + selector: + app: forum + deploymentconfig: "forum-app-{{ deployment_stamp | default('undefined', true) }}" + type: ClusterIP diff --git a/apps/hello/templates/services/app/route.yml.j2 b/apps/hello/templates/services/app/route.yml.j2 index ace835209..19685d09f 100644 --- a/apps/hello/templates/services/app/route.yml.j2 +++ b/apps/hello/templates/services/app/route.yml.j2 @@ -21,4 +21,4 @@ spec: targetPort: "{{ hello_app_port }}-tcp" to: kind: Service - name: "hello-app-{{ deployment_stamp }}" + name: "hello-app-{{ prefix }}" diff --git a/apps/hello/templates/services/app/static-svc.yml.j2 b/apps/hello/templates/services/app/static-svc.yml.j2 new file mode 100644 index 000000000..be957f8e9 --- /dev/null +++ b/apps/hello/templates/services/app/static-svc.yml.j2 @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: hello + deployment_stamp: "{{ deployment_stamp }}" + service_prefix: "{{ prefix }}" + type: static-service + removable: "no" + name: "hello-app-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: {{ hello_app_port }}-tcp + port: {{ hello_app_port }} + protocol: TCP + targetPort: {{ hello_app_port }} + type: ClusterIP + selector: + deploymentconfig: "hello-app-{{ deployment_stamp | default('undefined', true) }}" diff --git a/apps/learninglocker/templates/services/nginx/route.yml.j2 b/apps/learninglocker/templates/services/nginx/route.yml.j2 index 8b52df8b4..4ede05c3d 100644 --- a/apps/learninglocker/templates/services/nginx/route.yml.j2 +++ b/apps/learninglocker/templates/services/nginx/route.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "learninglocker" service: "nginx" - version: "{{ learninglocker_nginx_image_tag }}" route_prefix: "{{ prefix }}" annotations: kubernetes.io/tls-acme: "true" @@ -23,4 +22,4 @@ spec: targetPort: "{{ learninglocker_nginx_port }}-tcp" to: kind: Service - name: "learninglocker-nginx-{{ deployment_stamp }}" + name: "learninglocker-nginx-{{ prefix }}" diff --git a/apps/learninglocker/templates/services/nginx/static-svc.yml.j2 b/apps/learninglocker/templates/services/nginx/static-svc.yml.j2 new file mode 100644 index 000000000..dbfe83a2f --- /dev/null +++ b/apps/learninglocker/templates/services/nginx/static-svc.yml.j2 @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: learninglocker + service: nginx + deployment_stamp: "{{ deployment_stamp }}" + service_prefix: "{{ prefix }}" + type: static-service + removable: "no" + name: "learninglocker-nginx-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: "{{ learninglocker_nginx_port }}-tcp" + port: {{ learninglocker_nginx_port }} + protocol: TCP + targetPort: {{ learninglocker_nginx_port }} + - name: "{{ learninglocker_nginx_healthcheck_port }}-tcp" + port: {{ learninglocker_nginx_healthcheck_port }} + protocol: TCP + targetPort: {{ learninglocker_nginx_healthcheck_port }} + selector: + app: learninglocker + deploymentconfig: "learninglocker-nginx-{{ deployment_stamp | default('undefined', true) }}" + type: ClusterIP diff --git a/apps/marsha/templates/services/nginx/route.yml.j2 b/apps/marsha/templates/services/nginx/route.yml.j2 index 8d5d4eee6..e6f5b7661 100644 --- a/apps/marsha/templates/services/nginx/route.yml.j2 +++ b/apps/marsha/templates/services/nginx/route.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "marsha" service: "nginx" - version: "{{ marsha_nginx_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "app" annotations: @@ -24,4 +23,4 @@ spec: targetPort: "{{ marsha_nginx_port }}-tcp" to: kind: Service - name: "marsha-nginx-{{ deployment_stamp }}" + name: "marsha-nginx-{{ prefix }}" diff --git a/apps/marsha/templates/services/nginx/static-svc.yml.j2 b/apps/marsha/templates/services/nginx/static-svc.yml.j2 new file mode 100644 index 000000000..864416d21 --- /dev/null +++ b/apps/marsha/templates/services/nginx/static-svc.yml.j2 @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: marsha + service: nginx + deployment_stamp: "{{ deployment_stamp }}" + service_prefix: "{{ prefix }}" + type: static-service + removable: "no" + name: "marsha-nginx-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: {{ marsha_nginx_port }}-tcp + port: {{ marsha_nginx_port }} + protocol: TCP + targetPort: {{ marsha_nginx_port }} + - name: "{{ marsha_nginx_healthcheck_port }}-tcp" + port: {{ marsha_nginx_healthcheck_port }} + protocol: TCP + targetPort: {{ marsha_nginx_healthcheck_port }} + selector: + app: marsha + deploymentconfig: "marsha-nginx-{{ deployment_stamp | default('undefined', true) }}" + type: ClusterIP diff --git a/apps/richie/templates/services/nginx/route.yml.j2 b/apps/richie/templates/services/nginx/route.yml.j2 index 3d634cafe..582c9c161 100644 --- a/apps/richie/templates/services/nginx/route.yml.j2 +++ b/apps/richie/templates/services/nginx/route.yml.j2 @@ -8,7 +8,6 @@ metadata: customer: "{{ customer }}" app: "richie" service: "nginx" - version: "{{ richie_nginx_image_tag }}" route_prefix: "{{ prefix }}" route_target_service: "app" annotations: @@ -24,4 +23,4 @@ spec: targetPort: "{{ richie_nginx_port }}-tcp" to: kind: Service - name: "richie-nginx-{{ deployment_stamp }}" + name: "richie-nginx-{{ prefix }}" diff --git a/apps/richie/templates/services/nginx/static-svc.yml.j2 b/apps/richie/templates/services/nginx/static-svc.yml.j2 new file mode 100644 index 000000000..1288e5d2a --- /dev/null +++ b/apps/richie/templates/services/nginx/static-svc.yml.j2 @@ -0,0 +1,26 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: richie + service: nginx + service_prefix: "{{ prefix }}" + deployment_stamp: "{{ deployment_stamp }}" + type: static-service + removable: "no" + name: "richie-nginx-{{ prefix }}" + namespace: "{{ project_name }}" +spec: + ports: + - name: {{ richie_nginx_port }}-tcp + port: {{ richie_nginx_port }} + protocol: TCP + targetPort: {{ richie_nginx_port }} + - name: "{{ richie_nginx_healthcheck_port }}-tcp" + port: {{ richie_nginx_healthcheck_port }} + protocol: TCP + targetPort: {{ richie_nginx_healthcheck_port }} + type: ClusterIP + selector: + app: richie + deploymentconfig: "richie-nginx-{{ deployment_stamp | default('undefined', true) }}" diff --git a/create_services.yml b/create_services.yml new file mode 100644 index 000000000..62ecd0795 --- /dev/null +++ b/create_services.yml @@ -0,0 +1,20 @@ +- hosts: local + gather_facts: False + + pre_tasks: + - import_tasks: tasks/check_configuration.yml + + tasks: + - name: Display playbook name + debug: msg="==== Starting create_services playbook ====" + tags: deploy + + - import_tasks: tasks/set_vars.yml + + - include_tasks: tasks/run_tasks_for_apps.yml + vars: + tasks: + - get_objects_for_app + - create_static_services + tags: + - static_service diff --git a/delete_previous.yml b/delete_previous.yml index 5b20a33ad..af8433bb4 100644 --- a/delete_previous.yml +++ b/delete_previous.yml @@ -21,9 +21,9 @@ vars: tasks: - get_objects_for_app - - deploy_get_stamp_from_route + - deploy_get_stamp_from_static_service - delete_app prefix: previous tags: - - route + - static_service - switch diff --git a/deploy.yml b/deploy.yml index 3f294e143..509572b66 100644 --- a/deploy.yml +++ b/deploy.yml @@ -46,15 +46,15 @@ - config - deploy - # Patch all next routes of all apps after deploy + # Patch all next static services of all apps after deploy - include_tasks: tasks/run_tasks_for_apps.yml vars: prefix: "next" tasks: - get_objects_for_app - - deploy_get_stamp_from_route - - deploy_patch_route + - deploy_get_stamp_from_static_service + - deploy_patch_static_service - delete_app tags: - - route + - static_service - deploy diff --git a/group_vars/all/main.yml b/group_vars/all/main.yml index 761135105..aec3b1345 100644 --- a/group_vars/all/main.yml +++ b/group_vars/all/main.yml @@ -47,7 +47,7 @@ trashable_env_types: - "feature" # Blue/Green deployment route prefixes -blue_green_route_prefixes: +blue_green_prefixes: - "previous" - "current" - "next" diff --git a/init_project.yml b/init_project.yml index e35b99a28..937dbb082 100644 --- a/init_project.yml +++ b/init_project.yml @@ -6,4 +6,5 @@ - import_playbook: create_acme.yml - import_playbook: create_redirect.yml - import_playbook: create_routes.yml +- import_playbook: create_services.yml - import_playbook: create_image_streams.yml diff --git a/rollback.yml b/rollback.yml index 67787d399..268d8a637 100644 --- a/rollback.yml +++ b/rollback.yml @@ -22,7 +22,7 @@ vars: tasks: - get_objects_for_app - - rollback_routes + - rollback_static_services tags: - route - rollback diff --git a/switch.yml b/switch.yml index dc885f2e0..c7c016dce 100644 --- a/switch.yml +++ b/switch.yml @@ -1,9 +1,9 @@ --- -# This playbook switch all routes: -# 1. point the "previous" route to the stack that was pointed by the "current" route, -# 2. point the "current" route to the stack that was pointed by the "next" route, -# 3. delete the stack that was pointed by the "previous" route, -# 4. patch the next route to the init stamp +# This playbook switch all static services: +# 1. point the "previous" static service to the stack that was pointed by the "current" static service, +# 2. point the "current" static service to the stack that was pointed by the "next" static service, +# 3. delete the stack that was pointed by the "previous" static service, +# 4. patch the next static service to the init stamp - hosts: local gather_facts: False @@ -23,7 +23,7 @@ vars: tasks: - get_objects_for_app - - switch_routes + - switch_static_services tags: - - route + - static_service - switch diff --git a/tasks/clean_app_orphans.yml b/tasks/clean_app_orphans.yml index 26dc27da6..65aaece5a 100644 --- a/tasks/clean_app_orphans.yml +++ b/tasks/clean_app_orphans.yml @@ -1,7 +1,7 @@ --- # Remove orphan application stacks (i.e. outdated, unused objects) -- include_tasks: deploy_get_stamp_from_route.yml +- include_tasks: deploy_get_stamp_from_static_service.yml vars: prefix: "{{ item }}" loop: ["previous", "current", "next"] diff --git a/tasks/create_static_services.yml b/tasks/create_static_services.yml new file mode 100644 index 000000000..f4510f42e --- /dev/null +++ b/tasks/create_static_services.yml @@ -0,0 +1,10 @@ +--- +# Create static routes for services of an app + +- name: "Make sure static service exists for the '{{ app.name }}' app with all prefixes" + include_tasks: tasks/deploy_patch_static_service.yml + loop: "{{ blue_green_prefixes }}" + loop_control: + loop_var: prefix + when: static_services | length > 0 and app.settings.is_blue_green_compatible | default(True) + tags: static_service diff --git a/tasks/create_static_services_routes.yml b/tasks/create_static_services_routes.yml index 5b12649bf..4591fc37f 100644 --- a/tasks/create_static_services_routes.yml +++ b/tasks/create_static_services_routes.yml @@ -3,7 +3,7 @@ - name: "Make sure static route exists for the '{{ app.name }}' app with all prefixes" include_tasks: tasks/deploy_patch_route.yml - loop: "{{ blue_green_route_prefixes }}" + loop: "{{ blue_green_prefixes }}" loop_control: loop_var: prefix when: routes | length > 0 and app.settings.is_blue_green_compatible | default(True) diff --git a/tasks/delete_app_objects_kind.yml b/tasks/delete_app_objects_kind.yml index 5acd4c795..c25077241 100644 --- a/tasks/delete_app_objects_kind.yml +++ b/tasks/delete_app_objects_kind.yml @@ -7,6 +7,7 @@ label_selectors: - app={{ app.name }} - deployment_stamp={{ targeted_deployment_stamp }} + - removable!=no register: selected_objects tags: deploy @@ -28,6 +29,7 @@ label_selectors: - app={{ app.name }} - deployment_stamp={{ targeted_deployment_stamp }} + - removable!=no register: remaining_objects until: ( remaining_objects.resources | length ) == 0 retries: 120 diff --git a/tasks/deploy_get_stamp_from_route.yml b/tasks/deploy_get_stamp_from_route.yml deleted file mode 100644 index 67c66fa90..000000000 --- a/tasks/deploy_get_stamp_from_route.yml +++ /dev/null @@ -1,46 +0,0 @@ ---- -# Get deployment_stamp from a route - -# An application can define several routes (e.g. two services with two -# different routes). Our goal here is to get the deployment_stamp of a -# deployed stack by getting a route object. We first retrieve a route and -# then the service targeted by this route. TThis service will be labelled with the -# deploy_stamp we are looking for. -- name: Get route for application {{ app.name }} with prefix {{ prefix }} - k8s_facts: - api_version: "v1" - namespace: "{{ project_name }}" - kind: "Route" - label_selectors: - - app={{ app.name }} - - route_prefix={{ prefix }} - register: app_route - when: routes | length > 0 and app.settings.is_blue_green_compatible | default(True) - -- name: Get targeted service - k8s_facts: - api_version: "v1" - namespace: "{{ project_name }}" - kind: "Service" - name: "{{ ( app_route.resources | first ).spec.to.name }}" - register: targeted_service - when: app_route.resources is defined - -# app_deployment_stamp must be defined otherwise all script dependending on this one will fail -- name: Initialize app_deployment_stamp - set_fact: - app_deployment_stamp: "" - -- name: Set app_deployment_stamp - set_fact: - app_deployment_stamp: "{{ (targeted_service.resources | first ).metadata.labels.deployment_stamp | default(none) }}" - when: targeted_service.resources is defined and targeted_service.resources | length == 1 - -- name: "Set {{ prefix }}_app_deployment_stamp" - set_fact: - "{{ prefix }}_app_deployment_stamp": "{{ app_deployment_stamp }}" - -- name: Print app_deployment_stamp - debug: - msg: "[{{ app.name }}] app_deployment_stamp[{{ app_deployment_stamp }}]" - when: app_deployment_stamp is defined diff --git a/tasks/deploy_get_stamp_from_static_service.yml b/tasks/deploy_get_stamp_from_static_service.yml new file mode 100644 index 000000000..875cc1d1f --- /dev/null +++ b/tasks/deploy_get_stamp_from_static_service.yml @@ -0,0 +1,37 @@ +--- +# Get deployment_stamp from a static service + +# An application can define several static services. (e.g. two static services with +# two different routes). Our goal here is to get the deployment_stamp of a +# deployed stack by getting a service object. We retrieve the service and it will +# be labelled with the deploy_stamp we are looking for. +- name: Get static service for application {{ app.name }} with prefix {{ prefix }} + k8s_facts: + api_version: "v1" + namespace: "{{ project_name }}" + kind: "Service" + label_selectors: + - type=static-service + - app={{ app.name }} + - service_prefix={{ prefix }} + register: app_service + when: static_services | length > 0 and app.settings.is_blue_green_compatible | default(True) + +# app_deployment_stamp must be defined otherwise all script dependending on this one will fail +- name: Initialize app_deployment_stamp + set_fact: + app_deployment_stamp: "" + +- name: Set app_deployment_stamp + set_fact: + app_deployment_stamp: "{{ (app_service.resources | first ).metadata.labels.deployment_stamp | default(none) }}" + when: app_service.resources is defined and app_service.resources | length == 1 + +- name: "Set {{ prefix }}_app_deployment_stamp" + set_fact: + "{{ prefix }}_app_deployment_stamp": "{{ app_deployment_stamp }}" + +- name: Print app_deployment_stamp + debug: + msg: "[{{ app.name }}] app_deployment_stamp[{{ app_deployment_stamp }}]" + when: app_deployment_stamp is defined diff --git a/tasks/deploy_patch_static_service.yml b/tasks/deploy_patch_static_service.yml new file mode 100644 index 000000000..08e5bf4b5 --- /dev/null +++ b/tasks/deploy_patch_static_service.yml @@ -0,0 +1,23 @@ +# Patch services of all services from a single app to the new deployment_stamp + +- name: "Patching services with prefix {{ prefix }} for the {{ app.name }} application with deployment_stamp {{ deployment_stamp }}" + k8s: + force: "{{ force_route | bool }}" + definition: "{{ lookup('template', service_template) | from_yaml }}" + state: present + loop: "{{ static_services }}" + loop_control: + loop_var: service_template + when: static_services | length > 0 and app.settings.is_blue_green_compatible | default(True) == True + tags: static_service + +- name: "Patching services for the {{ app.name }} application" + k8s: + force: "{{ force_route | bool }}" + definition: "{{ lookup('template', service_template) | from_yaml }}" + state: present + loop: "{{ static_services }}" + loop_control: + loop_var: service_template + when: static_services | length > 0 and app.settings.is_blue_green_compatible | default(True) == False + tags: static_service diff --git a/tasks/get_objects_for_app.yml b/tasks/get_objects_for_app.yml index b2da37442..a2d46dd35 100644 --- a/tasks/get_objects_for_app.yml +++ b/tasks/get_objects_for_app.yml @@ -18,6 +18,7 @@ deployments: "{{ templates | map('regex_search', '.*/dc.*\\.yml\\.j2$') | select('string') | list }}" endpoints: "{{ templates | map('regex_search', '.*/ep.*\\.yml\\.j2$') | select('string') | list }}" services: "{{ templates | map('regex_search', '.*/svc.*\\.yml\\.j2$') | select('string') | list }}" + static_services: "{{ templates | map('regex_search', '.*/static-svc.*\\.yml\\.j2$') | select('string') | list }}" streams: "{{ templates | map('regex_search', '.*/is.*\\.yml\\.j2$') | select('string') | list }}" jobs: "{{ templates | map('regex_search', '.*/job_.*\\.yml\\.j2$') | select('string') | list }}" routes: "{{ templates | map('regex_search', '.*/route.*\\.yml\\.j2$') | select('string') | list }}" diff --git a/tasks/rollback_routes.yml b/tasks/rollback_static_services.yml similarity index 55% rename from tasks/rollback_routes.yml rename to tasks/rollback_static_services.yml index e76161690..b0208f8d6 100644 --- a/tasks/rollback_routes.yml +++ b/tasks/rollback_static_services.yml @@ -1,15 +1,15 @@ --- -# Patch app dest routes with src stack +# Patch app dest static service with src stack -- include_tasks: deploy_get_stamp_from_route.yml +- include_tasks: deploy_get_stamp_from_static_service.yml vars: prefix: next tags: switch -- include_tasks: switch_route.yml +- include_tasks: switch_static_service.yml vars: - prefix_route_src: "{{ prefix_route.src }}" - prefix_route_dest: "{{ prefix_route.dest }}" + prefix_service_src: "{{ prefix_service.src }}" + prefix_service_dest: "{{ prefix_service.dest }}" update_src: "{{ prefix_route.update_src | default(True)}}" with_items: - src: current @@ -18,7 +18,7 @@ - src: previous dest: current loop_control: - loop_var: prefix_route + loop_var: prefix_service - include_tasks: delete_app.yml vars: diff --git a/tasks/switch_route.yml b/tasks/switch_route.yml deleted file mode 100644 index 22ef0e4d5..000000000 --- a/tasks/switch_route.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Patch app dest route with src stack - -- name: Print switch details - debug: msg="[{{ app.name }}] Switch routes from {{ prefix_route_src }} to {{ prefix_route_dest }}" - tags: switch - -- include_tasks: deploy_get_stamp_from_route.yml - vars: - prefix: "{{ prefix_route_src }}" - tags: switch - -- include_tasks: deploy_patch_route.yml - vars: - prefix: "{{ prefix_route_dest }}" - deployment_stamp: "{{ app_deployment_stamp }}" - tags: switch - -- include_tasks: deploy_patch_route.yml - vars: - prefix: "{{ prefix_route_src }}" - tags: switch - when: update_src is defined and update_src == True - diff --git a/tasks/switch_static_service.yml b/tasks/switch_static_service.yml new file mode 100644 index 000000000..c46d77bd2 --- /dev/null +++ b/tasks/switch_static_service.yml @@ -0,0 +1,23 @@ +--- +# Patch app dest static service with src stack + +- name: Print switch details + debug: msg="[{{ app.name }}] Switch static service from {{ prefix_service_src }} to {{ prefix_service_dest }}" + tags: switch + +- include_tasks: deploy_get_stamp_from_static_service.yml + vars: + prefix: "{{ prefix_service_src }}" + tags: switch + +- include_tasks: deploy_patch_static_service.yml + vars: + prefix: "{{ prefix_service_dest }}" + deployment_stamp: "{{ app_deployment_stamp }}" + tags: switch + +- include_tasks: deploy_patch_static_service.yml + vars: + prefix: "{{ prefix_service_src }}" + tags: switch + when: update_src is defined and update_src == True diff --git a/tasks/switch_routes.yml b/tasks/switch_static_services.yml similarity index 55% rename from tasks/switch_routes.yml rename to tasks/switch_static_services.yml index d5064e714..13c876bd6 100644 --- a/tasks/switch_routes.yml +++ b/tasks/switch_static_services.yml @@ -1,15 +1,15 @@ --- -# Patch app dest routes with src stack +# Patch app dest static services with src stack -- include_tasks: deploy_get_stamp_from_route.yml +- include_tasks: deploy_get_stamp_from_static_service.yml vars: prefix: "previous" tags: switch -- include_tasks: switch_route.yml +- include_tasks: switch_static_service.yml vars: - prefix_route_src: "{{ prefix_route.src }}" - prefix_route_dest: "{{ prefix_route.dest }}" + prefix_service_src: "{{ prefix_service.src }}" + prefix_service_dest: "{{ prefix_service.dest }}" update_src: "{{ prefix_route.update_src | default(True)}}" with_items: - src: current @@ -18,7 +18,7 @@ - src: next dest: current loop_control: - loop_var: prefix_route + loop_var: prefix_service - include_tasks: delete_app.yml vars: