diff --git a/k8s/deployment/build_context b/k8s/deployment/build_context index 8161b752..96b3b0bb 100755 --- a/k8s/deployment/build_context +++ b/k8s/deployment/build_context @@ -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)}') diff --git a/k8s/deployment/scale_deployments b/k8s/deployment/scale_deployments new file mode 100755 index 00000000..095570f7 --- /dev/null +++ b/k8s/deployment/scale_deployments @@ -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 \ No newline at end of file diff --git a/k8s/deployment/workflows/blue_green.yaml b/k8s/deployment/workflows/blue_green.yaml index 970c730b..af2878f1 100644 --- a/k8s/deployment/workflows/blue_green.yaml +++ b/k8s/deployment/workflows/blue_green.yaml @@ -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" \ No newline at end of file + 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 \ No newline at end of file diff --git a/k8s/deployment/workflows/finalize.yaml b/k8s/deployment/workflows/finalize.yaml index 8a1b7096..af4b0cd0 100644 --- a/k8s/deployment/workflows/finalize.yaml +++ b/k8s/deployment/workflows/finalize.yaml @@ -21,25 +21,7 @@ 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 @@ -47,9 +29,6 @@ steps: 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" diff --git a/k8s/deployment/workflows/rollback.yaml b/k8s/deployment/workflows/rollback.yaml index d9671b61..eaa749c9 100644 --- a/k8s/deployment/workflows/rollback.yaml +++ b/k8s/deployment/workflows/rollback.yaml @@ -21,25 +21,7 @@ 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 @@ -47,9 +29,6 @@ steps: 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" diff --git a/k8s/deployment/workflows/switch_traffic.yaml b/k8s/deployment/workflows/switch_traffic.yaml index 38c1d1b0..d6d4cf5b 100644 --- a/k8s/deployment/workflows/switch_traffic.yaml +++ b/k8s/deployment/workflows/switch_traffic.yaml @@ -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 @@ -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"