From 96f02eb1f426c16c631598c80bec4bc0e60f75c1 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Fri, 19 Jun 2020 15:39:22 +0200 Subject: Add support for scalability configuration Closes #52 --- README.md | 15 +++++++++++++++ dhall/Config.dhall | 25 ++++++++++++++++++++++++- files/clever-set-scalability.sh | 19 +++++++++++++++++++ tasks/deploy.yml | 14 ++++++++++++++ tasks/setup.yml | 1 + 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100755 files/clever-set-scalability.sh diff --git a/README.md b/README.md index c0f7959..348f36d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Variables for the application - `clever_disable_metrics`: a boolean to disable metrics support. Optional, default to `false`. - `clever_env_output_file`: as a post deploy task you might need to retrieve the full Clever environment configuration (i.e. with addon env variables). If this variable is set to a filename then the env will be retrieved after a successful deploy inside this file. Optional. - `clever_build_flavor`: an optional text value used to configure the size of the dedicated build instance (for instance `S` or `XL`). If not defined, it delegates to clever cloud default behaviour. Setting `disabled` disables the dedicated build instance altogether. +- `clever_scaling`: an optional object used to configure the runtime instances flavours and numbers. If not defined, it delegates to clever cloud default behaviour. Variables specific to deployment, default should be fine: - `clever_cli_version`: Version of clever cli tools, default to `2.6.1`. @@ -44,6 +45,20 @@ Variables specific to deployment, default should be fine: - `clever_app_confdir`: Path where to store clever cloud data specific to this application, default to `"{{ clever_app_root }}/.clever_cloud"` - `clever_login_file`: Path to store login information. Default to `"{{ clever_app_confdir }}/login"`. +Scaling configuration +--------------------- + +```yaml +clever_scaling: + # instances and flavors are optional and can be configured as + # either a fixed value (with `fixed`) or a range # (with `min` and `max`) + flavors: + fixed: XS + instances: + min: 2 + max: 5 +``` + Dependencies ------------ diff --git a/dhall/Config.dhall b/dhall/Config.dhall index e092e2c..12371f5 100644 --- a/dhall/Config.dhall +++ b/dhall/Config.dhall @@ -2,6 +2,20 @@ let Addon = (./Addon.dhall).Type let Vault = ./Vault.dhall +let FixedOrRange = + λ(t : Type) → < Fixed : { fixed : t } | Range : { min : t, max : t } > + +let fixed = λ(t : Type) → λ(f : t) → (FixedOrRange t).Fixed { fixed = f } + +let range = λ(t : Type) → λ(r : { min : t, max : t }) → (FixedOrRange t).Range r + +let InstancesConfig = FixedOrRange Natural + +let FlavorsConfig = FixedOrRange Text + +let ScalingParameters = + { flavor : Optional FlavorsConfig, instances : Optional InstancesConfig } + let Config = λ(Environment : Type) → { clever_app : Text @@ -16,6 +30,7 @@ let Config = , clever_addons : List Addon , clever_env : Environment , clever_build_flavor : Optional Text + , clever_scaling : Optional ScalingParameters } let mkConfig = @@ -34,7 +49,15 @@ let mkConfig = , clever_addons = [] : List Addon , clever_env = {=} , clever_build_flavor = None Text + , clever_scaling = None ScalingParameters } : Config {} -in { Type = Config, mkConfig = mkConfig } +in { Type = Config + , mkConfig = mkConfig + , ScalingParameters = ScalingParameters + , InstancesConfig = InstancesConfig + , FlavorsConfig = FlavorsConfig + , fixed = fixed + , range = range + } diff --git a/files/clever-set-scalability.sh b/files/clever-set-scalability.sh new file mode 100755 index 0000000..34a5a24 --- /dev/null +++ b/files/clever-set-scalability.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -eo pipefail +params=() +if [ -n "$INSTANCES" ]; then + params+=("--instances" "${INSTANCES}") +elif [ -n "$MIN_INSTANCES" ] && [ -n "$MAX_INSTANCES" ]; then + params+=("--min-instances" "${MIN_INSTANCES}") + params+=("--max-instances" "${MAX_INSTANCES}") + +fi +if [ -n "$FLAVOR" ]; then + params+=("--flavor" "${FLAVOR}") +elif [ -n "$MIN_FLAVOR" ] && [ -n "$MAX_FLAVOR" ]; then + params+=("--min-flavor" "${MIN_FLAVOR}") + params+=("--max-flavor" "${MAX_FLAVOR}") +fi + +clever scale "${params[@]}" diff --git a/tasks/deploy.yml b/tasks/deploy.yml index ca1e54a..c567981 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml @@ -24,6 +24,20 @@ environment: CONFIGURATION_FILE: "{{ clever_login_file }}" +- name: Configure Scalability + when: clever_scaling is defined + command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-set-scalability.sh" + args: + chdir: "{{ clever_app_root }}" + environment: + CONFIGURATION_FILE: "{{ clever_login_file }}" + INSTANCES: "{{ clever_scaling.instances.fixed | default ('') }}" + MIN_INSTANCES: "{{ clever_scaling.instances.min | default('') }}" + MAX_INSTANCES: "{{ clever_scaling.instances.max | default('') }}" + FLAVOR: "{{ clever_scaling.flavor.fixed | default('') }}" + MIN_FLAVOR: "{{ clever_scaling.flavor.min | default('') }}" + MAX_FLAVOR: "{{ clever_scaling.flavor.max | default('') }}" + - name: Push Environment shell: "clever env import --json < {{ clever_app_confdir }}/env" args: diff --git a/tasks/setup.yml b/tasks/setup.yml index a2d5b90..8a11772 100644 --- a/tasks/setup.yml +++ b/tasks/setup.yml @@ -29,3 +29,4 @@ with_items: - clever-set-domain.sh - clever-set-drain.sh + - clever-set-scalability.sh -- cgit v1.2.3 From 791d2dcbcb3d90ea66ce9b6b519eeb576f5f601b Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Mon, 22 Jun 2020 11:30:43 +0200 Subject: add tests for scalability settings They make sure that ansible does not crash while calling `clever scale` --- .travis.yml | 1 + tests/test-scalability.yml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/test-scalability.yml diff --git a/.travis.yml b/.travis.yml index 752366f..d287c26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ script: - ansible-playbook tests/test-simple-app.yml -i tests/inventory - ansible-playbook tests/test-haskell-app.yml -i tests/inventory - ansible-playbook tests/test-configure-app.yml -i tests/inventory + - ansible-playbook tests/test-scalability.yml -i tests/inventory notifications: slack: fretlink:pTIylIN7zkwRFuL3aHERmsbB diff --git a/tests/test-scalability.yml b/tests/test-scalability.yml new file mode 100644 index 0000000..fefc86c --- /dev/null +++ b/tests/test-scalability.yml @@ -0,0 +1,37 @@ +--- +- name: Configure scalability (fixed instances and ranged flavors) + hosts: localhost + remote_user: root + roles: + - role: clever + vars: + clever_token: 123abc + clever_secret: cba321 + clever_app: app_00000000-0000-0000-0000-000000000000 + clever_scaling: + instances: { fixed: 1 } + flavors: { min: "nano", max: "XS" } + +- name: Configure scalability (no instances and ranged flavors) + hosts: localhost + remote_user: root + roles: + - role: clever + vars: + clever_token: 123abc + clever_secret: cba321 + clever_app: app_00000000-0000-0000-0000-000000000000 + clever_scaling: + flavors: { min: "nano", max: "XS" } + +- name: Configure scalability (incomplete flavors) + hosts: localhost + remote_user: root + roles: + - role: clever + vars: + clever_token: 123abc + clever_secret: cba321 + clever_app: app_00000000-0000-0000-0000-000000000000 + clever_scaling: + flavors: { min: "nano" } -- cgit v1.2.3