Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion k8s/deployment/build_context
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ SWITCH_TRAFFIC=$(echo "$CONTEXT" | jq -r ".deployment.strategy_data.desired_swit
MIN_REPLICAS=$(echo "scale=10; $REPLICAS / 10" | bc)
MIN_REPLICAS=$(echo "$MIN_REPLICAS" | awk '{printf "%d", ($1 == int($1) ? $1 : int($1)+1)}')

if [ "$DEPLOY_STRATEGY" = "rolling" ]; then
DEPLOYMENT_STATUS=$(echo $CONTEXT | jq -r ".deployment.status")

if [ "$DEPLOY_STRATEGY" = "rolling" ] && [ "$DEPLOYMENT_STATUS" = "running" ]; then
GREEN_REPLICAS=$(echo "scale=10; ($GREEN_REPLICAS * $SWITCH_TRAFFIC) / 100" | bc)
GREEN_REPLICAS=$(echo "$GREEN_REPLICAS" | awk '{printf "%d", ($1 == int($1) ? $1 : int($1)+1)}')

Expand Down
17 changes: 17 additions & 0 deletions k8s/deployment/scale_deployments
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

GREEN_REPLICAS=$(echo "$CONTEXT" | jq -r .green_replicas)
GREEN_DEPLOYMENT_ID=$DEPLOYMENT_ID

BLUE_REPLICAS=$(echo "$CONTEXT" | jq -r .blue_replicas)
BLUE_DEPLOYMENT_ID=$(echo "$CONTEXT" | jq .scope.current_active_deployment -r)

if [ "$DEPLOY_STRATEGY" = "rolling" ]; then
GREEN_DEPLOYMENT_NAME="d-$SCOPE_ID-$GREEN_DEPLOYMENT_ID"

kubectl scale deployment "$GREEN_DEPLOYMENT_NAME" -n "$K8S_NAMESPACE" --replicas="$GREEN_REPLICAS"

BLUE_DEPLOYMENT_NAME="d-$SCOPE_ID-$BLUE_DEPLOYMENT_ID"

kubectl scale deployment "$BLUE_DEPLOYMENT_NAME" -n "$K8S_NAMESPACE" --replicas="$BLUE_REPLICAS"
fi
22 changes: 8 additions & 14 deletions k8s/deployment/workflows/blue_green.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ configuration:
steps:
- name: update blue deployment
type: script
file: "$SERVICE_PATH/deployment/build_blue_deployment"
file: "$SERVICE_PATH/deployment/scale_deployments"
after: create deployment
output:
- name: DEPLOYMENT_PATH
type: file
file: "$OUTPUT_DIR/deployment-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SECRET_PATH
type: file
file: "$OUTPUT_DIR/secret-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SCALING_PATH
type: file
file: "$OUTPUT_DIR/scaling-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SERVICE_TEMPLATE_PATH
type: file
file: "$OUTPUT_DIR/service-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
post:
name: wait deployment active
type: script
file: "$SERVICE_PATH/deployment/wait_blue_deployment_active"
configuration:
TIMEOUT: DEPLOYMENT_MAX_WAIT_IN_SECONDS
SKIP_DEPLOYMENT_STATUS_CHECK: true
23 changes: 1 addition & 22 deletions k8s/deployment/workflows/finalize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,14 @@ steps:
type: environment
- name: build green deployment
type: script
file: "$SERVICE_PATH/deployment/build_deployment"
configuration:
DESIRED_TRAFFIC: 100
output:
- name: DEPLOYMENT_PATH
type: file
file: "$OUTPUT_DIR/deployment-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: SECRET_PATH
type: file
file: "$OUTPUT_DIR/secret-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: SCALING_PATH
type: file
file: "$OUTPUT_DIR/scaling-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: SERVICE_TEMPLATE_PATH
type: file
file: "$OUTPUT_DIR/service-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: create green deployment
type: script
file: "$SERVICE_PATH/apply_templates"
file: "$SERVICE_PATH/deployment/scale_deployments"
post:
name: wait deployment active
type: script
file: "$SERVICE_PATH/deployment/wait_deployment_active"
configuration:
TIMEOUT: DEPLOYMENT_MAX_WAIT_IN_SECONDS
SKIP_DEPLOYMENT_STATUS_CHECK: true
configuration:
ACTION: apply
DRY_RUN: false
- name: route traffic
type: script
file: "$SERVICE_PATH/deployment/networking/gateway/route_traffic"
Expand Down
23 changes: 1 addition & 22 deletions k8s/deployment/workflows/rollback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,14 @@ steps:
type: environment
- name: update blue deployment
type: script
file: "$SERVICE_PATH/deployment/build_blue_deployment"
configuration:
DESIRED_TRAFFIC: 100
output:
- name: DEPLOYMENT_PATH
type: file
file: "$OUTPUT_DIR/deployment-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SECRET_PATH
type: file
file: "$OUTPUT_DIR/secret-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SCALING_PATH
type: file
file: "$OUTPUT_DIR/scaling-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SERVICE_TEMPLATE_PATH
type: file
file: "$OUTPUT_DIR/service-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: create blue deployment
type: script
file: "$SERVICE_PATH/apply_templates"
file: "$SERVICE_PATH/deployment/scale_deployments"
post:
name: wait deployment active
type: script
file: "$SERVICE_PATH/deployment/wait_blue_deployment_active"
configuration:
TIMEOUT: DEPLOYMENT_MAX_WAIT_IN_SECONDS
SKIP_DEPLOYMENT_STATUS_CHECK: true
configuration:
ACTION: apply
DRY_RUN: false
- name: rollback traffic
type: script
file: "$SERVICE_PATH/deployment/networking/gateway/rollback_traffic"
Expand Down
43 changes: 9 additions & 34 deletions k8s/deployment/workflows/switch_traffic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,7 @@ steps:
type: environment
- name: create deployment
type: script
file: "$SERVICE_PATH/deployment/build_deployment"
output:
- name: DEPLOYMENT_PATH
type: file
file: "$OUTPUT_DIR/deployment-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: SECRET_PATH
type: file
file: "$OUTPUT_DIR/secret-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: SCALING_PATH
type: file
file: "$OUTPUT_DIR/scaling-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: SERVICE_TEMPLATE_PATH
type: file
file: "$OUTPUT_DIR/service-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: apply
type: script
file: "$SERVICE_PATH/apply_templates"
configuration:
ACTION: apply
DRY_RUN: false
file: "$SERVICE_PATH/deployment/scale_deployments"
post:
name: wait deployment active
type: script
Expand All @@ -59,20 +40,14 @@ steps:
file: "$OUTPUT_DIR/ingress-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
- name: update blue deployment
type: script
file: "$SERVICE_PATH/deployment/build_blue_deployment"
output:
- name: DEPLOYMENT_PATH
type: file
file: "$OUTPUT_DIR/deployment-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SECRET_PATH
type: file
file: "$OUTPUT_DIR/secret-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SCALING_PATH
type: file
file: "$OUTPUT_DIR/scaling-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
- name: SERVICE_TEMPLATE_PATH
type: file
file: "$OUTPUT_DIR/service-$SCOPE_ID-$BLUE_DEPLOYMENT_ID.yaml"
file: "$SERVICE_PATH/deployment/scale_deployments"
post:
name: wait deployment active
type: script
file: "$SERVICE_PATH/deployment/wait_blue_deployment_active"
configuration:
TIMEOUT: DEPLOYMENT_MAX_WAIT_IN_SECONDS
SKIP_DEPLOYMENT_STATUS_CHECK: true
- name: apply traffic
type: script
file: "$SERVICE_PATH/apply_templates"
Expand Down