-
Notifications
You must be signed in to change notification settings - Fork 484
[FLINK-37515] Basic support for Blue/Green deployments #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schongloo
wants to merge
12
commits into
apache:main
Choose a base branch
from
schongloo:release-1.11-bluegreen-flip503
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f6349bf
[FLINK-37515] FLIP-503: Basic support for Blue/Green deployments
schongloo ebab279
Fixing configOption default value management and log message formatting
schongloo 3d91ba4
Optimized/simplified the reconciliation logic for first deployments. …
schongloo 9f099ae
Added Blue/Green Deployments E2E test
schongloo 853547f
- Refactoring (splitting) the Blue/Green controller logic from the Co…
schongloo ee47067
Refactoring for clarity (added BlueGreenTransitionContext)
schongloo 05e9425
Introducing a Blue/Green State Machine
schongloo 79d75bb
Optimizing the State Handling
schongloo d1098bb
Triggering a full transition only when needed, otherwise just patch t…
schongloo 5a3b802
Optimized the B/G unit tests
schongloo c178eae
Adding support for Savepointing before transItion in the case of Upgr…
schongloo a3ab6d6
Updated unit test to assert Savepointing. Checkstyle fixes
schongloo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
################################################################################ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
################################################################################ | ||
|
||
apiVersion: flink.apache.org/v1beta1 | ||
kind: FlinkBlueGreenDeployment | ||
metadata: | ||
name: basic-bluegreen-example | ||
spec: | ||
template: | ||
configuration: | ||
kubernetes.operator.bluegreen.deployment-deletion.delay: "1s" | ||
spec: | ||
image: flink:1.20 | ||
flinkVersion: v1_20 | ||
flinkConfiguration: | ||
rest.port: "8081" | ||
execution.checkpointing.interval: "1 min" | ||
execution.checkpointing.storage: "filesystem" | ||
state.backend.incremental: "true" | ||
state.checkpoints.dir: "file:///flink-data/checkpoints" | ||
state.checkpoints.num-retained: "50" | ||
taskmanager.numberOfTaskSlots: "1" | ||
serviceAccount: flink | ||
jobManager: | ||
resource: | ||
memory: "2048m" | ||
cpu: 1 | ||
podTemplate: | ||
spec: | ||
containers: | ||
- name: flink-main-container | ||
volumeMounts: | ||
- mountPath: /flink-data | ||
name: flink-volume | ||
volumes: | ||
- name: flink-volume | ||
hostPath: | ||
path: /tmp/flink | ||
type: Directory | ||
taskManager: | ||
resource: | ||
memory: "2048m" | ||
cpu: 1 | ||
job: | ||
jarURI: local:///opt/flink/examples/streaming/StateMachineExample.jar | ||
parallelism: 1 | ||
upgradeMode: stateless |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env bash | ||
################################################################################ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
################################################################################ | ||
|
||
# This script tests the Flink Blue/Green Deployments support as follows: | ||
# - Create a FlinkBlueGreenDeployment which automatically starts a "Blue" FlinkDeployment | ||
# - Once this setup is stable, we trigger a transition which will create the "Green" FlinkDeployment | ||
# - Once it's stable, verify the "Blue" FlinkDeployment is torn down | ||
# - Perform additional validation(s) before exiting | ||
|
||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")") | ||
source "${SCRIPT_DIR}/utils.sh" | ||
|
||
CLUSTER_ID="basic-bluegreen-example" | ||
BG_CLUSTER_ID=$CLUSTER_ID | ||
BLUE_CLUSTER_ID="basic-bluegreen-example-blue" | ||
GREEN_CLUSTER_ID="basic-bluegreen-example-green" | ||
|
||
APPLICATION_YAML="${SCRIPT_DIR}/data/bluegreen.yaml" | ||
APPLICATION_IDENTIFIER="flinkbgdep/$CLUSTER_ID" | ||
BLUE_APPLICATION_IDENTIFIER="flinkdep/$BLUE_CLUSTER_ID" | ||
GREEN_APPLICATION_IDENTIFIER="flinkdep/$GREEN_CLUSTER_ID" | ||
TIMEOUT=300 | ||
|
||
#echo "BG_CLUSTER_ID " $BG_CLUSTER_ID | ||
#echo "BLUE_CLUSTER_ID " $BLUE_CLUSTER_ID | ||
#echo "APPLICATION_IDENTIFIER " $APPLICATION_IDENTIFIER | ||
#echo "BLUE_APPLICATION_IDENTIFIER " $BLUE_APPLICATION_IDENTIFIER | ||
|
||
on_exit cleanup_and_exit "$APPLICATION_YAML" $TIMEOUT $BG_CLUSTER_ID | ||
|
||
retry_times 5 30 "kubectl apply -f $APPLICATION_YAML" || exit 1 | ||
|
||
wait_for_jobmanager_running $BLUE_CLUSTER_ID $TIMEOUT | ||
wait_for_status $BLUE_APPLICATION_IDENTIFIER '.status.lifecycleState' STABLE ${TIMEOUT} || exit 1 | ||
wait_for_status $APPLICATION_IDENTIFIER '.status.jobStatus.state' RUNNING ${TIMEOUT} || exit 1 | ||
wait_for_status $APPLICATION_IDENTIFIER '.status.blueGreenState' ACTIVE_BLUE ${TIMEOUT} || exit 1 | ||
|
||
blue_job_id=$(kubectl get -oyaml flinkdep/basic-bluegreen-example-blue | yq '.status.jobStatus.jobId') | ||
|
||
echo "Giving a chance for checkpoints to be generated..." | ||
sleep 5 | ||
kubectl patch flinkbgdep ${BG_CLUSTER_ID} --type merge --patch '{"spec":{"template":{"spec":{"flinkConfiguration":{"rest.port":"8082","state.checkpoints.num-retained":"51"}}}}}' | ||
|
||
wait_for_status $GREEN_APPLICATION_IDENTIFIER '.status.lifecycleState' STABLE ${TIMEOUT} || exit 1 | ||
kubectl wait --for=delete deployment --timeout=${TIMEOUT}s --selector="app=${BLUE_CLUSTER_ID}" | ||
wait_for_status $APPLICATION_IDENTIFIER '.status.jobStatus.state' RUNNING ${TIMEOUT} || exit 1 | ||
wait_for_status $APPLICATION_IDENTIFIER '.status.blueGreenState' ACTIVE_GREEN ${TIMEOUT} || exit 1 | ||
|
||
green_initialSavepointPath=$(kubectl get -oyaml $GREEN_APPLICATION_IDENTIFIER | yq '.spec.job.initialSavepointPath') | ||
|
||
if [[ $green_initialSavepointPath == '/flink-data/checkpoints/'$blue_job_id* ]]; then | ||
echo 'Green deployment started from the expected initialSavepointPath: ' $green_initialSavepointPath | ||
else | ||
echo 'Unexpected initialSavepointPath: ' $green_initialSavepointPath | ||
exit 1 | ||
fi; | ||
|
||
echo "Successfully run the Flink Blue/Green Deployments test" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...-api/src/main/java/org/apache/flink/kubernetes/operator/api/FlinkBlueGreenDeployment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.kubernetes.operator.api; | ||
|
||
import org.apache.flink.annotation.Experimental; | ||
import org.apache.flink.kubernetes.operator.api.spec.FlinkBlueGreenDeploymentSpec; | ||
import org.apache.flink.kubernetes.operator.api.status.FlinkBlueGreenDeploymentStatus; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import io.fabric8.kubernetes.api.model.Namespaced; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.ShortNames; | ||
import io.fabric8.kubernetes.model.annotation.Version; | ||
|
||
/** Custom resource definition that represents a deployments with Blue/Green rollout capability. */ | ||
@Experimental | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonDeserialize() | ||
@Group(CrdConstants.API_GROUP) | ||
@Version(CrdConstants.API_VERSION) | ||
@ShortNames({"flinkbgdep"}) | ||
public class FlinkBlueGreenDeployment | ||
extends CustomResource<FlinkBlueGreenDeploymentSpec, FlinkBlueGreenDeploymentStatus> | ||
implements Namespaced {} |
38 changes: 38 additions & 0 deletions
38
...i/src/main/java/org/apache/flink/kubernetes/operator/api/bluegreen/BlueGreenDiffType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.kubernetes.operator.api.bluegreen; | ||
|
||
/** | ||
* Enum representing different types of differences found in Blue/Green deployment specifications. | ||
*/ | ||
public enum BlueGreenDiffType { | ||
/** No differences found between specifications. */ | ||
IGNORE, | ||
|
||
/** Only top-level properties (metadata, configuration) have differences. */ | ||
PATCH_TOP_LEVEL, | ||
|
||
/** Only the nested FlinkDeploymentSpec has differences. */ | ||
PATCH_CHILD, | ||
|
||
/** Both top-level and nested specifications have differences. */ | ||
PATCH_BOTH, | ||
|
||
/** The nested spec has SCALE or UPGRADE differences, requiring a blue/green transition. */ | ||
TRANSITION | ||
} |
39 changes: 39 additions & 0 deletions
39
...-api/src/main/java/org/apache/flink/kubernetes/operator/api/bluegreen/DeploymentType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.kubernetes.operator.api.bluegreen; | ||
|
||
import org.apache.flink.kubernetes.operator.api.FlinkDeployment; | ||
|
||
/** | ||
* Enumeration of the two possible Flink Blue/Green deployment types. Only one of each type will be | ||
* present at all times for a particular job. | ||
*/ | ||
public enum DeploymentType { | ||
/** Identifier for the first or "Blue" deployment type. */ | ||
BLUE, | ||
schongloo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Identifier for the second or "Green" deployment type. */ | ||
GREEN; | ||
|
||
public static final String LABEL_KEY = "flink/blue-green-deployment-type"; | ||
|
||
public static DeploymentType fromDeployment(FlinkDeployment flinkDeployment) { | ||
String typeAnnotation = flinkDeployment.getMetadata().getLabels().get(LABEL_KEY); | ||
return DeploymentType.valueOf(typeAnnotation); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the functional difference between IGNORE the different PATCH diffs and TRANSITION? Feels like we should have only 3:
NO_CHANGE
OPERATOR_CONFIG_ONLY -> Non-upgrade/scale deployment changes
UPGRADE