Skip to content

Commit a51d8ea

Browse files
committed
add flink k8s code
1 parent ec78e15 commit a51d8ea

File tree

79 files changed

+8966
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+8966
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Flink-K8s
2+
3+
基于开源 1.12.0 版本添加一些自己改造的 feature

flink-learning-k8s/flink-k8s/pom.xml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>flink-learning-k8s</artifactId>
5+
<groupId>com.zhisheng.flink</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>flink-k8s</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<name>flink-k8s</name>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<kubernetes.client.version>4.9.2</kubernetes.client.version>
18+
</properties>
19+
20+
<!-- Set dependency version for transitive dependencies -->
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.squareup.okhttp3</groupId>
25+
<artifactId>okhttp</artifactId>
26+
<version>3.12.1</version>
27+
</dependency>
28+
</dependencies>
29+
</dependencyManagement>
30+
31+
<dependencies>
32+
33+
<!-- core dependencies -->
34+
35+
<dependency>
36+
<groupId>org.apache.flink</groupId>
37+
<artifactId>flink-clients_${scala.binary.version}</artifactId>
38+
<version>1.12.0</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.apache.flink</groupId>
44+
<artifactId>flink-runtime_${scala.binary.version}</artifactId>
45+
<version>1.12.0</version>
46+
<scope>provided</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>io.fabric8</groupId>
51+
<artifactId>kubernetes-client</artifactId>
52+
<version>${kubernetes.client.version}</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.apache.flink</groupId>
57+
<artifactId>flink-shaded-jackson</artifactId>
58+
<scope>provided</scope>
59+
</dependency>
60+
61+
</dependencies>
62+
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-shade-plugin</artifactId>
68+
<executions>
69+
<execution>
70+
<id>shade-flink</id>
71+
<phase>package</phase>
72+
<goals>
73+
<goal>shade</goal>
74+
</goals>
75+
<configuration combine.children="append">
76+
<artifactSet>
77+
<includes combine.children="append">
78+
<include>io.fabric8:kubernetes-client</include>
79+
<include>io.fabric8:kubernetes-model</include>
80+
<include>io.fabric8:kubernetes-model-common</include>
81+
<include>io.fabric8:zjsonpatch</include>
82+
83+
<!-- Shade all the dependencies of kubernetes client -->
84+
<include>com.fasterxml.jackson.core:jackson-core</include>
85+
<include>com.fasterxml.jackson.core:jackson-annotations</include>
86+
<include>com.fasterxml.jackson.core:jackson-databind</include>
87+
<include>com.fasterxml.jackson.dataformat:jackson-dataformat-yaml</include>
88+
<include>com.fasterxml.jackson.datatype:jackson-datatype-jsr310</include>
89+
<include>com.squareup.okhttp3:*</include>
90+
<include>com.squareup.okio:okio</include>
91+
<include>org.yaml:*</include>
92+
<include>dk.brics.automaton:*</include>
93+
94+
<include>META-INF/services/org.apache.flink.*</include>
95+
</includes>
96+
</artifactSet>
97+
<filters combine.children="append">
98+
<filter>
99+
<artifact>*:*</artifact>
100+
<excludes>
101+
<exclude>*.aut</exclude>
102+
<exclude>META-INF/maven/**</exclude>
103+
<exclude>META-INF/services/*com.fasterxml*</exclude>
104+
<exclude>META-INF/proguard/**</exclude>
105+
<exclude>OSGI-INF/**</exclude>
106+
<exclude>schema/**</exclude>
107+
<exclude>*.vm</exclude>
108+
<exclude>*.properties</exclude>
109+
<exclude>*.xml</exclude>
110+
<exclude>META-INF/jandex.idx</exclude>
111+
<exclude>license.header</exclude>
112+
</excludes>
113+
</filter>
114+
</filters>
115+
<relocations>
116+
<relocation>
117+
<pattern>com.fasterxml.jackson</pattern>
118+
<shadedPattern>org.apache.flink.kubernetes.shaded.com.fasterxml.jackson
119+
</shadedPattern>
120+
</relocation>
121+
<relocation>
122+
<pattern>okhttp3</pattern>
123+
<shadedPattern>org.apache.flink.kubernetes.shaded.okhttp3</shadedPattern>
124+
</relocation>
125+
<relocation>
126+
<pattern>okio</pattern>
127+
<shadedPattern>org.apache.flink.kubernetes.shaded.okio</shadedPattern>
128+
</relocation>
129+
<relocation>
130+
<pattern>org.yaml</pattern>
131+
<shadedPattern>org.apache.flink.kubernetes.shaded.org.yaml</shadedPattern>
132+
</relocation>
133+
<relocation>
134+
<pattern>dk.brics.automaton</pattern>
135+
<shadedPattern>org.apache.flink.kubernetes.shaded.dk.brics.automaton</shadedPattern>
136+
</relocation>
137+
</relocations>
138+
</configuration>
139+
</execution>
140+
</executions>
141+
</plugin>
142+
</plugins>
143+
</build>
144+
145+
146+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.flink.kubernetes;
20+
21+
import org.apache.flink.annotation.Internal;
22+
import org.apache.flink.client.deployment.AbstractContainerizedClusterClientFactory;
23+
import org.apache.flink.client.deployment.ClusterClientFactory;
24+
import org.apache.flink.configuration.Configuration;
25+
import org.apache.flink.configuration.DeploymentOptions;
26+
import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
27+
import org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget;
28+
import org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory;
29+
import org.apache.flink.kubernetes.utils.Constants;
30+
import org.apache.flink.util.AbstractID;
31+
32+
import javax.annotation.Nullable;
33+
34+
import java.util.Optional;
35+
36+
import static org.apache.flink.util.Preconditions.checkNotNull;
37+
38+
/**
39+
* A {@link ClusterClientFactory} for a Kubernetes cluster.
40+
*/
41+
@Internal
42+
public class KubernetesClusterClientFactory extends AbstractContainerizedClusterClientFactory<String> {
43+
44+
private static final String CLUSTER_ID_PREFIX = "flink-cluster-";
45+
46+
@Override
47+
public boolean isCompatibleWith(Configuration configuration) {
48+
checkNotNull(configuration);
49+
final String deploymentTarget = configuration.getString(DeploymentOptions.TARGET);
50+
return KubernetesDeploymentTarget.isValidKubernetesTarget(deploymentTarget);
51+
}
52+
53+
@Override
54+
public KubernetesClusterDescriptor createClusterDescriptor(Configuration configuration) {
55+
checkNotNull(configuration);
56+
if (!configuration.contains(KubernetesConfigOptions.CLUSTER_ID)) {
57+
final String clusterId = generateClusterId();
58+
configuration.setString(KubernetesConfigOptions.CLUSTER_ID, clusterId);
59+
}
60+
return new KubernetesClusterDescriptor(
61+
configuration,
62+
FlinkKubeClientFactory.getInstance().fromConfiguration(configuration, "client"));
63+
}
64+
65+
@Nullable
66+
@Override
67+
public String getClusterId(Configuration configuration) {
68+
checkNotNull(configuration);
69+
return configuration.getString(KubernetesConfigOptions.CLUSTER_ID);
70+
}
71+
72+
@Override
73+
public Optional<String> getApplicationTargetName() {
74+
return Optional.of(KubernetesDeploymentTarget.APPLICATION.getName());
75+
}
76+
77+
private String generateClusterId() {
78+
final String randomID = new AbstractID().toString();
79+
return (CLUSTER_ID_PREFIX + randomID).substring(0, Constants.MAXIMUM_CHARACTERS_OF_CLUSTER_ID);
80+
}
81+
}

0 commit comments

Comments
 (0)