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-bluegreen-example"
30+ BG_CLUSTER_ID=$CLUSTER_ID
31+ BLUE_CLUSTER_ID=" basic-bluegreen-example-blue"
32+ GREEN_CLUSTER_ID=" basic-bluegreen-example-green"
33+
34+ APPLICATION_YAML=" ${SCRIPT_DIR} /data/bluegreen.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+ on_exit cleanup_and_exit " $APPLICATION_YAML " $TIMEOUT $BG_CLUSTER_ID
46+
47+ retry_times 5 30 " kubectl apply -f $APPLICATION_YAML " || exit 1
48+
49+ wait_for_jobmanager_running $BLUE_CLUSTER_ID $TIMEOUT
50+ wait_for_status $BLUE_APPLICATION_IDENTIFIER ' .status.lifecycleState' STABLE ${TIMEOUT} || exit 1
51+ wait_for_status $APPLICATION_IDENTIFIER ' .status.jobStatus.state' RUNNING ${TIMEOUT} || exit 1
52+ wait_for_status $APPLICATION_IDENTIFIER ' .status.blueGreenState' ACTIVE_BLUE ${TIMEOUT} || exit 1
53+
54+ blue_job_id=$( kubectl get -oyaml flinkdep/basic-bluegreen-example-blue | yq ' .status.jobStatus.jobId' )
55+
56+ echo " Giving a chance for checkpoints to be generated..."
57+ sleep 5
58+ kubectl patch flinkbgdep ${BG_CLUSTER_ID} --type merge --patch ' {"spec":{"template":{"spec":{"flinkConfiguration":{"rest.port":"8082","state.checkpoints.num-retained":"51"}}}}}'
59+
60+ wait_for_status $GREEN_APPLICATION_IDENTIFIER ' .status.lifecycleState' STABLE ${TIMEOUT} || exit 1
61+ kubectl wait --for=delete deployment --timeout=${TIMEOUT} s --selector=" app=${BLUE_CLUSTER_ID} "
62+ wait_for_status $APPLICATION_IDENTIFIER ' .status.jobStatus.state' RUNNING ${TIMEOUT} || exit 1
63+ wait_for_status $APPLICATION_IDENTIFIER ' .status.blueGreenState' ACTIVE_GREEN ${TIMEOUT} || exit 1
64+
65+ green_initialSavepointPath=$( kubectl get -oyaml $GREEN_APPLICATION_IDENTIFIER | yq ' .spec.job.initialSavepointPath' )
66+
67+ if [[ $green_initialSavepointPath == ' /flink-data/checkpoints/' $blue_job_id * ]]; then
68+ echo ' Green deployment started from the expected initialSavepointPath: ' $green_initialSavepointPath
69+ else
70+ echo ' Unexpected initialSavepointPath: ' $green_initialSavepointPath
71+ exit 1
72+ fi ;
73+
74+ echo " Successfully run the Flink Blue/Green Deployments test"
0 commit comments