Skip to content

Commit 2955979

Browse files
committed
First batch for FLIP-504
1 parent eb99c5a commit 2955979

28 files changed

Lines changed: 7133 additions & 5144 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api.bluegreen;
19+
20+
import lombok.AllArgsConstructor;
21+
import lombok.Data;
22+
23+
import java.io.Serializable;
24+
import java.util.Map;
25+
26+
import static org.apache.flink.kubernetes.operator.api.bluegreen.GateContextOptions.ACTIVE_DEPLOYMENT_TYPE;
27+
import static org.apache.flink.kubernetes.operator.api.bluegreen.GateContextOptions.DEPLOYMENT_DELETION_DELAY;
28+
import static org.apache.flink.kubernetes.operator.api.bluegreen.GateContextOptions.IS_FIRST_DEPLOYMENT;
29+
import static org.apache.flink.kubernetes.operator.api.bluegreen.GateContextOptions.TRANSITION_STAGE;
30+
31+
/** Base functionality of the Context used for Gate implementations. */
32+
@Data
33+
@AllArgsConstructor
34+
public class GateContext implements Serializable {
35+
36+
/** GateContext enum. */
37+
private final BlueGreenDeploymentType activeBlueGreenDeploymentType;
38+
39+
private final GateOutputMode outputMode;
40+
private final int deploymentTeardownDelayMs;
41+
private final TransitionStage gateStage;
42+
private final boolean isFirstDeployment;
43+
44+
public static GateContext create(
45+
Map<String, String> data, BlueGreenDeploymentType currentBlueGreenDeploymentType) {
46+
var nextActiveDeploymentType =
47+
BlueGreenDeploymentType.valueOf(data.get(ACTIVE_DEPLOYMENT_TYPE.getLabel()));
48+
49+
var deploymentDeletionDelaySec =
50+
Integer.parseInt(data.get(DEPLOYMENT_DELETION_DELAY.getLabel()));
51+
52+
var outputMode =
53+
currentBlueGreenDeploymentType == nextActiveDeploymentType
54+
? GateOutputMode.ACTIVE
55+
: GateOutputMode.STANDBY;
56+
57+
var isFirstDeployment = Boolean.parseBoolean(data.get(IS_FIRST_DEPLOYMENT.getLabel()));
58+
59+
return new GateContext(
60+
nextActiveDeploymentType,
61+
outputMode,
62+
deploymentDeletionDelaySec,
63+
TransitionStage.valueOf(data.get(TRANSITION_STAGE.getLabel())),
64+
isFirstDeployment);
65+
}
66+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api.bluegreen;
19+
20+
import lombok.Getter;
21+
22+
/** Options values for the GateContext. */
23+
public enum GateContextOptions {
24+
IS_FIRST_DEPLOYMENT("is-first-deployment"),
25+
ACTIVE_DEPLOYMENT_TYPE("active-deployment-type"),
26+
DEPLOYMENT_DELETION_DELAY("deployment-deletion-delay-ms"),
27+
TRANSITION_STAGE("stage");
28+
29+
@Getter private final String label;
30+
31+
private GateContextOptions(String label) {
32+
this.label = label;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api.bluegreen;
19+
20+
import org.apache.flink.util.Preconditions;
21+
22+
import io.fabric8.kubernetes.api.model.ConfigMap;
23+
import io.fabric8.kubernetes.client.KubernetesClient;
24+
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
25+
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
26+
import lombok.Getter;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
import java.io.Serializable;
31+
import java.util.Map;
32+
33+
/** Simple Kubernetes service proxy for Gate operations. */
34+
public class GateKubernetesService implements Serializable {
35+
36+
private static final Logger logger = LoggerFactory.getLogger(GateKubernetesService.class);
37+
38+
@Getter private final KubernetesClient kubernetesClient;
39+
40+
private final String namespace;
41+
private final String configMapName;
42+
43+
public GateKubernetesService(String namespace, String configMapName) {
44+
Preconditions.checkNotNull(namespace);
45+
Preconditions.checkNotNull(configMapName);
46+
47+
try {
48+
kubernetesClient = new KubernetesClientBuilder().build();
49+
} catch (Exception e) {
50+
logger.error("Error instantiating Kubernetes Client", e);
51+
throw e;
52+
}
53+
54+
this.namespace = namespace;
55+
this.configMapName = configMapName;
56+
}
57+
58+
public void setInformers(ResourceEventHandler<ConfigMap> resourceEventHandler) {
59+
kubernetesClient
60+
.configMaps()
61+
.inNamespace(namespace)
62+
.withName(configMapName)
63+
.inform(resourceEventHandler, 0);
64+
}
65+
66+
public void updateConfigMapEntries(Map<String, String> kvps) {
67+
var configMap = parseConfigMap();
68+
69+
kvps.forEach((key, value) -> configMap.getData().put(key, value));
70+
71+
try {
72+
kubernetesClient.configMaps().inNamespace(namespace).resource(configMap).update();
73+
} catch (Exception e) {
74+
logger.error("Failed to UPDATE the ConfigMap", e);
75+
throw e;
76+
}
77+
}
78+
79+
public ConfigMap parseConfigMap() {
80+
try {
81+
return kubernetesClient
82+
.configMaps()
83+
.inNamespace(namespace)
84+
.withName(configMapName)
85+
.get();
86+
} catch (Exception e) {
87+
logger.error("Failed to GET the ConfigMap", e);
88+
throw e;
89+
}
90+
}
91+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api.bluegreen;
19+
20+
/** Gate output enum values. */
21+
public enum GateOutputMode {
22+
ACTIVE,
23+
STANDBY
24+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api.bluegreen;
19+
20+
/** Possible transition modes supported by the `FlinkBlueGreenDeploymentController`. */
21+
public enum TransitionMode {
22+
/**
23+
* FLIP-503: simple transition that deletes the previous deployment as soon as the new one is
24+
* RUNNING/STABLE.
25+
*/
26+
BASIC,
27+
28+
/**
29+
* FLIP-504: advanced coordination between deployment stages during transition. Not supported
30+
* until FLIP-504 is implemented.
31+
*/
32+
ADVANCED;
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.kubernetes.operator.api.bluegreen;
19+
20+
/** Enumeration of the various stages for _ALL_ Blue/Green deployments. */
21+
public enum TransitionStage {
22+
CLEAR_TO_TEARDOWN,
23+
FAILING,
24+
INITIALIZING,
25+
RUNNING,
26+
TRANSITIONING;
27+
}

flink-kubernetes-operator-api/src/main/java/org/apache/flink/kubernetes/operator/api/spec/FlinkDeploymentTemplateSpec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.flink.kubernetes.operator.api.spec;
1919

20+
import org.apache.flink.kubernetes.operator.api.bluegreen.TransitionMode;
21+
2022
import com.fasterxml.jackson.annotation.JsonIgnore;
2123
import com.fasterxml.jackson.annotation.JsonProperty;
2224
import io.fabric8.kubernetes.api.model.ObjectMeta;
@@ -38,6 +40,9 @@ public class FlinkDeploymentTemplateSpec {
3840
@JsonProperty("metadata")
3941
private ObjectMeta metadata;
4042

43+
@JsonProperty("transitionMode")
44+
private TransitionMode transitionMode;
45+
4146
@JsonProperty("spec")
4247
private FlinkDeploymentSpec spec;
4348

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Flink Kubernetes Client Code Client
21+
22+
TBD

0 commit comments

Comments
 (0)