Loading .gitlab-ci.yml +42 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,48 @@ test-get-replicas: exit 1 fi test-get-replicas-multiple: <<: *test-job variables: GIT_STRATEGY: none CI_ENVIRONMENT_SLUG: production REPLICAS: "2" script: - replicas=$(auto-deploy get_replicas "stable" "100") - | if [[ $replicas != 2 ]]; then echo "$replicas should equal 2" exit 1 fi test-get-replicas-fraction: <<: *test-job variables: GIT_STRATEGY: none CI_ENVIRONMENT_SLUG: production REPLICAS: "2" script: - replicas=$(auto-deploy get_replicas "stable" "25") - | if [[ $replicas != 1 ]]; then echo "$replicas should 1, (25% of 2 is 0.5, so set a floor of 1)" exit 1 fi test-get-replicas-zero: <<: *test-job variables: GIT_STRATEGY: none CI_ENVIRONMENT_SLUG: production REPLICAS: "0" script: - replicas=$(auto-deploy get_replicas "stable" "100") - | if [[ $replicas != 0 ]]; then echo "$replicas should equal 0, as requested" exit 1 fi test-ensure-namespace: <<: *test-job variables: Loading src/bin/auto-deploy +7 −4 Original line number Diff line number Diff line Loading @@ -330,7 +330,6 @@ function deploy_name() { echo $name } # shellcheck disable=SC2004 # $/${} is unnecessary on arithmetic variables. # shellcheck disable=SC2086 # double quote to prevent globbing # shellcheck disable=SC2153 # incorrectly thinks replicas vs REPLICAS is a misspelling function get_replicas() { Loading Loading @@ -359,12 +358,16 @@ function get_replicas() { fi local replicas="${new_replicas:-1}" replicas="$(($replicas * $percentage / 100))" replicas="$((replicas * percentage / 100))" # always return at least one replicas if [[ $replicas -gt 0 ]]; then if [[ $new_replicas == 0 ]]; then # If zero replicas requested, then return 0 echo "$new_replicas" elif [[ $replicas -gt 0 ]]; then echo "$replicas" else # Return one if calculated replicas is zero # E.g. 25% of 2 replicas is 0 (integer division) echo 1 fi } Loading Loading
.gitlab-ci.yml +42 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,48 @@ test-get-replicas: exit 1 fi test-get-replicas-multiple: <<: *test-job variables: GIT_STRATEGY: none CI_ENVIRONMENT_SLUG: production REPLICAS: "2" script: - replicas=$(auto-deploy get_replicas "stable" "100") - | if [[ $replicas != 2 ]]; then echo "$replicas should equal 2" exit 1 fi test-get-replicas-fraction: <<: *test-job variables: GIT_STRATEGY: none CI_ENVIRONMENT_SLUG: production REPLICAS: "2" script: - replicas=$(auto-deploy get_replicas "stable" "25") - | if [[ $replicas != 1 ]]; then echo "$replicas should 1, (25% of 2 is 0.5, so set a floor of 1)" exit 1 fi test-get-replicas-zero: <<: *test-job variables: GIT_STRATEGY: none CI_ENVIRONMENT_SLUG: production REPLICAS: "0" script: - replicas=$(auto-deploy get_replicas "stable" "100") - | if [[ $replicas != 0 ]]; then echo "$replicas should equal 0, as requested" exit 1 fi test-ensure-namespace: <<: *test-job variables: Loading
src/bin/auto-deploy +7 −4 Original line number Diff line number Diff line Loading @@ -330,7 +330,6 @@ function deploy_name() { echo $name } # shellcheck disable=SC2004 # $/${} is unnecessary on arithmetic variables. # shellcheck disable=SC2086 # double quote to prevent globbing # shellcheck disable=SC2153 # incorrectly thinks replicas vs REPLICAS is a misspelling function get_replicas() { Loading Loading @@ -359,12 +358,16 @@ function get_replicas() { fi local replicas="${new_replicas:-1}" replicas="$(($replicas * $percentage / 100))" replicas="$((replicas * percentage / 100))" # always return at least one replicas if [[ $replicas -gt 0 ]]; then if [[ $new_replicas == 0 ]]; then # If zero replicas requested, then return 0 echo "$new_replicas" elif [[ $replicas -gt 0 ]]; then echo "$replicas" else # Return one if calculated replicas is zero # E.g. 25% of 2 replicas is 0 (integer division) echo 1 fi } Loading