forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-16194][k8s] Introduce Factories that chain the decorators toge…
…ther to construct all the client/cluster-side Kubernetes resources
- Loading branch information
1 parent
d29628c
commit 10f5329
Showing
12 changed files
with
514 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
47 changes: 47 additions & 0 deletions
47
...c/main/java/org/apache/flink/kubernetes/kubeclient/KubernetesJobManagerSpecification.java
This file contains 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,47 @@ | ||
/* | ||
* 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:https://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.kubeclient; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Composition of the created Kubernetes components that represents a Flink application. | ||
*/ | ||
public class KubernetesJobManagerSpecification { | ||
|
||
private Deployment deployment; | ||
|
||
private List<HasMetadata> accompanyingResources; | ||
|
||
public KubernetesJobManagerSpecification(Deployment deployment, List<HasMetadata> accompanyingResources) { | ||
this.deployment = deployment; | ||
this.accompanyingResources = accompanyingResources; | ||
} | ||
|
||
public Deployment getDeployment() { | ||
return deployment; | ||
} | ||
|
||
public List<HasMetadata> getAccompanyingResources() { | ||
return accompanyingResources; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...main/java/org/apache/flink/kubernetes/kubeclient/factory/KubernetesJobManagerFactory.java
This file contains 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,106 @@ | ||
/* | ||
* 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:https://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.kubeclient.factory; | ||
|
||
import org.apache.flink.kubernetes.kubeclient.FlinkPod; | ||
import org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.InitJobManagerDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.InternalServiceDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.JavaCmdJobManagerDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters; | ||
import org.apache.flink.kubernetes.utils.Constants; | ||
import org.apache.flink.kubernetes.utils.KubernetesUtils; | ||
|
||
import io.fabric8.kubernetes.api.model.Container; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodBuilder; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Utility class for constructing all the Kubernetes components on the client-side. This can | ||
* include the Deployment, the ConfigMap(s), and the Service(s). | ||
*/ | ||
public class KubernetesJobManagerFactory { | ||
|
||
public static KubernetesJobManagerSpecification createJobManagerComponent( | ||
KubernetesJobManagerParameters kubernetesJobManagerParameters) throws IOException { | ||
FlinkPod flinkPod = new FlinkPod.Builder().build(); | ||
List<HasMetadata> accompanyingResources = new ArrayList<>(); | ||
|
||
final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { | ||
new InitJobManagerDecorator(kubernetesJobManagerParameters), | ||
new JavaCmdJobManagerDecorator(kubernetesJobManagerParameters), | ||
new InternalServiceDecorator(kubernetesJobManagerParameters), | ||
new ExternalServiceDecorator(kubernetesJobManagerParameters), | ||
new FlinkConfMountDecorator(kubernetesJobManagerParameters)}; | ||
|
||
for (KubernetesStepDecorator stepDecorator: stepDecorators) { | ||
flinkPod = stepDecorator.decorateFlinkPod(flinkPod); | ||
accompanyingResources.addAll(stepDecorator.buildAccompanyingKubernetesResources()); | ||
} | ||
|
||
final Deployment deployment = createJobManagerDeployment(flinkPod, kubernetesJobManagerParameters); | ||
|
||
return new KubernetesJobManagerSpecification(deployment, accompanyingResources); | ||
} | ||
|
||
private static Deployment createJobManagerDeployment( | ||
FlinkPod flinkPod, | ||
KubernetesJobManagerParameters kubernetesJobManagerParameters) { | ||
final Container resolvedMainContainer = flinkPod.getMainContainer(); | ||
|
||
final Pod resolvedPod = new PodBuilder(flinkPod.getPod()) | ||
.editOrNewSpec() | ||
.addToContainers(resolvedMainContainer) | ||
.endSpec() | ||
.build(); | ||
|
||
final Map<String, String> labels = resolvedPod.getMetadata().getLabels(); | ||
|
||
return new DeploymentBuilder() | ||
.withApiVersion(Constants.APPS_API_VERSION) | ||
.editOrNewMetadata() | ||
.withName(KubernetesUtils.getDeploymentName(kubernetesJobManagerParameters.getClusterId())) | ||
.withLabels(kubernetesJobManagerParameters.getLabels()) | ||
.endMetadata() | ||
.editOrNewSpec() | ||
.withReplicas(1) | ||
.editOrNewTemplate() | ||
.editOrNewMetadata() | ||
.withLabels(labels) | ||
.endMetadata() | ||
.withSpec(resolvedPod.getSpec()) | ||
.endTemplate() | ||
.editOrNewSelector() | ||
.addToMatchLabels(labels) | ||
.endSelector() | ||
.endSpec() | ||
.build(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ain/java/org/apache/flink/kubernetes/kubeclient/factory/KubernetesTaskManagerFactory.java
This file contains 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,57 @@ | ||
/* | ||
* 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:https://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.kubeclient.factory; | ||
|
||
import org.apache.flink.kubernetes.kubeclient.FlinkPod; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.InitTaskManagerDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.JavaCmdTaskManagerDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator; | ||
import org.apache.flink.kubernetes.kubeclient.parameters.KubernetesTaskManagerParameters; | ||
import org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodBuilder; | ||
|
||
/** | ||
* Utility class for constructing the TaskManager Pod on the JobManager. | ||
*/ | ||
public class KubernetesTaskManagerFactory { | ||
|
||
public static KubernetesPod buildTaskManagerComponent(KubernetesTaskManagerParameters kubernetesTaskManagerParameters) { | ||
FlinkPod flinkPod = new FlinkPod.Builder().build(); | ||
|
||
final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { | ||
new InitTaskManagerDecorator(kubernetesTaskManagerParameters), | ||
new JavaCmdTaskManagerDecorator(kubernetesTaskManagerParameters), | ||
new FlinkConfMountDecorator(kubernetesTaskManagerParameters)}; | ||
|
||
for (KubernetesStepDecorator stepDecorator: stepDecorators) { | ||
flinkPod = stepDecorator.decorateFlinkPod(flinkPod); | ||
} | ||
|
||
final Pod resolvedPod = new PodBuilder(flinkPod.getPod()) | ||
.editOrNewSpec() | ||
.addToContainers(flinkPod.getMainContainer()) | ||
.endSpec() | ||
.build(); | ||
|
||
return new KubernetesPod(resolvedPod); | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.