1+ #! /usr/bin/env bash
2+ # ###############################################################################
3+ # Licensed to the Apache Software Foundation (ASF) under one
4+ # or more contributor license agreements. See the NOTICE file
5+ # distributed with this work for additional information
6+ # regarding copyright ownership. The ASF licenses this file
7+ # to you under the Apache License, Version 2.0 (the
8+ # "License"); you may not use this file except in compliance
9+ # with the License. You may obtain a copy of the License at
10+ #
11+ # http://www.apache.org/licenses/LICENSE-2.0
12+ #
13+ # Unless required by applicable law or agreed to in writing, software
14+ # distributed under the License is distributed on an "AS IS" BASIS,
15+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+ # See the License for the specific language governing permissions and
17+ # limitations under the License.
18+ # ###############################################################################
19+
20+ # This script tests the Flink Blue/Green Deployments support as follows:
21+ # - Create a FlinkBlueGreenDeployment which automatically starts a "Blue" FlinkDeployment
22+ # - Once this setup is stable, we trigger a transition which will create the "Green" FlinkDeployment
23+ # - Once it's stable, verify the "Blue" FlinkDeployment is torn down
24+ # - Perform additional validation(s) before exiting
25+
26+ SCRIPT_DIR=$( dirname " $( readlink -f " $0 " ) " )
27+ source " ${SCRIPT_DIR} /utils.sh"
28+
29+ CLUSTER_ID=" basic-bg-laststate-example"
30+ BG_CLUSTER_ID=$CLUSTER_ID
31+ BLUE_CLUSTER_ID=$CLUSTER_ID " -blue"
32+ GREEN_CLUSTER_ID=$CLUSTER_ID " -green"
33+
34+ APPLICATION_YAML=" ${SCRIPT_DIR} /data/bluegreen-laststate.yaml"
35+ APPLICATION_IDENTIFIER=" flinkbgdep/$CLUSTER_ID "
36+ BLUE_APPLICATION_IDENTIFIER=" flinkdep/$BLUE_CLUSTER_ID "
37+ GREEN_APPLICATION_IDENTIFIER=" flinkdep/$GREEN_CLUSTER_ID "
38+ TIMEOUT=300
39+
40+ # echo "BG_CLUSTER_ID " $BG_CLUSTER_ID
41+ # echo "BLUE_CLUSTER_ID " $BLUE_CLUSTER_ID
42+ # echo "APPLICATION_IDENTIFIER " $APPLICATION_IDENTIFIER
43+ # echo "BLUE_APPLICATION_IDENTIFIER " $BLUE_APPLICATION_IDENTIFIER
44+
45+ retry_times 5 30 " kubectl apply -f $APPLICATION_YAML " || exit 1
46+
47+ sleep 1
48+ wait_for_jobmanager_running $BLUE_CLUSTER_ID $TIMEOUT
49+ wait_for_status $BLUE_APPLICATION_IDENTIFIER ' .status.lifecycleState' STABLE ${TIMEOUT} || exit 1
50+ wait_for_status $APPLICATION_IDENTIFIER ' .status.jobStatus.state' RUNNING ${TIMEOUT} || exit 1
51+ wait_for_status $APPLICATION_IDENTIFIER ' .status.blueGreenState' ACTIVE_BLUE ${TIMEOUT} || exit 1
52+
53+ # blue_job_id=$(kubectl get -oyaml flinkdep/basic-bluegreen-example-blue | yq '.status.jobStatus.jobId')
54+
55+ # kubectl patch flinkbgdep ${BG_CLUSTER_ID} --type merge --patch '{"spec":{"template":{"spec":{"flinkConfiguration":{"rest.port":"8082","state.checkpoints.num-retained":"6"}}}}}'
56+ kubectl patch flinkbgdep ${BG_CLUSTER_ID} --type merge --patch ' {"spec":{"template":{"spec":{"flinkConfiguration":{"state.checkpoints.num-retained":"6"}}}}}'
57+ echo " Resource patched, giving a chance for the savepoint to be taken..."
58+ sleep 10
59+
60+ jm_pod_name=$( get_jm_pod_name $BLUE_CLUSTER_ID )
61+ echo " Inspecting savepoint directory..."
62+ kubectl exec -it $jm_pod_name -- bash -c " ls -lt /opt/flink/volume/flink-sp/"
63+
64+ wait_for_status $GREEN_APPLICATION_IDENTIFIER ' .status.lifecycleState' STABLE ${TIMEOUT} || exit 1
65+ kubectl wait --for=delete deployment --timeout=${TIMEOUT} s --selector=" app=${BLUE_CLUSTER_ID} "
66+ wait_for_status $APPLICATION_IDENTIFIER ' .status.jobStatus.state' RUNNING ${TIMEOUT} || exit 1
67+ wait_for_status $APPLICATION_IDENTIFIER ' .status.blueGreenState' ACTIVE_GREEN ${TIMEOUT} || exit 1
68+
69+ green_initialSavepointPath=$( kubectl get -oyaml $GREEN_APPLICATION_IDENTIFIER | yq ' .spec.job.initialSavepointPath' )
70+
71+ echo " Deleting test B/G resources" $BG_CLUSTER_ID
72+ kubectl delete flinkbluegreendeployments/$BG_CLUSTER_ID &
73+ echo " Waiting for deployment to be deleted..."
74+ kubectl wait --for=delete flinkbluegreendeployments/$BG_CLUSTER_ID
75+
76+ if [[ $green_initialSavepointPath == ' /opt/flink/volume/flink-sp/savepoint-' * ]]; then
77+ echo ' Green deployment started from the expected initialSavepointPath:' $green_initialSavepointPath
78+ else
79+ echo ' Unexpected initialSavepointPath:' $green_initialSavepointPath
80+ exit 1
81+ fi ;
82+
83+ echo " Successfully run the Flink Blue/Green Deployments test"
0 commit comments