-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
[FLINK-37088][k8s]support flink applicaton taskmanager log mounting #25944
Open
baimafeima-yf
wants to merge
4
commits into
apache:master
Choose a base branch
from
baimafeima-yf:master
base: master
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
4 commits
Select commit
Hold shift + click to select a range
e575a7e
[FLINK-37088][k8s]support flink applicaton taskmanager log mounting
0f8879f
Merge branch 'master' of https://github.com/apache/flink
c1f2d94
[FLINK-37088][k8s]support flink applicaton taskmanager log mounting
1d09ce3
[FLINK-37088][k8s]support flink applicaton taskmanager log mounting
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 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
77 changes: 77 additions & 0 deletions
77
...es/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/FlinkLogDecorator.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,77 @@ | ||
/* | ||
* 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.kubeclient.decorators; | ||
|
||
import static org.apache.flink.kubernetes.utils.Constants.FLINK_LOG; | ||
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
import io.fabric8.kubernetes.api.model.Container; | ||
import io.fabric8.kubernetes.api.model.ContainerBuilder; | ||
import io.fabric8.kubernetes.api.model.HostPathVolumeSourceBuilder; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodBuilder; | ||
import io.fabric8.kubernetes.api.model.Volume; | ||
import io.fabric8.kubernetes.api.model.VolumeBuilder; | ||
import io.fabric8.kubernetes.api.model.VolumeMount; | ||
import io.fabric8.kubernetes.api.model.VolumeMountBuilder; | ||
import org.apache.flink.kubernetes.kubeclient.FlinkPod; | ||
import org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters; | ||
|
||
/** Support mounting logs on the JobManager or TaskManager pod.. */ | ||
public class FlinkLogDecorator extends AbstractKubernetesStepDecorator { | ||
|
||
private final AbstractKubernetesParameters kubernetesComponentConf; | ||
|
||
public FlinkLogDecorator(AbstractKubernetesParameters kubernetesComponentConf) { | ||
this.kubernetesComponentConf = checkNotNull(kubernetesComponentConf); | ||
} | ||
|
||
@Override | ||
public FlinkPod decorateFlinkPod(FlinkPod flinkPod) { | ||
final Pod podWithMount = decoratePod(flinkPod.getPodWithoutMainContainer()); | ||
final Container containerWithMount = decorateMainContainer(flinkPod.getMainContainer()); | ||
|
||
return new FlinkPod.Builder(flinkPod) | ||
.withPod(podWithMount) | ||
.withMainContainer(containerWithMount) | ||
.build(); | ||
|
||
|
||
} | ||
|
||
private Container decorateMainContainer(Container container) { | ||
|
||
VolumeMount volumeMount = new VolumeMountBuilder().withName(FLINK_LOG) | ||
.withMountPath(kubernetesComponentConf.getVolumeMountPath()).build(); | ||
|
||
return new ContainerBuilder(container).addToVolumeMounts(volumeMount).build(); | ||
} | ||
|
||
private Pod decoratePod(Pod pod) { | ||
|
||
Volume volume = new VolumeBuilder().withName(FLINK_LOG).withHostPath( | ||
new HostPathVolumeSourceBuilder().withPath(kubernetesComponentConf.getVolumeLogs()) | ||
.withType("DirectoryOrCreate").build()).build(); | ||
|
||
|
||
|
||
return new PodBuilder(pod).editOrNewSpec().addToVolumes(volume).endSpec().build(); | ||
} | ||
|
||
} |
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
63 changes: 63 additions & 0 deletions
63
...rc/test/java/org/apache/flink/kubernetes/kubeclient/decorators/FlinkLogDecoratorTest.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,63 @@ | ||
package org.apache.flink.kubernetes.kubeclient.decorators; | ||
|
||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.fabric8.kubernetes.api.model.Container; | ||
import io.fabric8.kubernetes.api.model.ContainerBuilder; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodBuilder; | ||
import io.fabric8.kubernetes.api.model.Volume; | ||
import io.fabric8.kubernetes.api.model.VolumeMount; | ||
import org.apache.flink.kubernetes.kubeclient.FlinkPod; | ||
import org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class FlinkLogDecoratorTest { | ||
|
||
private static final String VOLUME_MOUNT_PATH = "/apps/log/flink"; | ||
private static final String VOLUME_LOGS = "/opt/flink/log"; | ||
|
||
@Mock | ||
private AbstractKubernetesParameters kubernetesComponentConf; | ||
|
||
@InjectMocks | ||
private FlinkLogDecorator flinkLogDecorator; | ||
|
||
@Before | ||
public void setUp() { | ||
when(kubernetesComponentConf.getVolumeMountPath()).thenReturn(VOLUME_MOUNT_PATH); | ||
when(kubernetesComponentConf.getVolumeLogs()).thenReturn(VOLUME_LOGS); | ||
} | ||
|
||
@Test | ||
public void decorateFlinkPod_ShouldAddVolumeAndVolumeMount() { | ||
FlinkPod originalFlinkPod = new FlinkPod.Builder() | ||
.withPod(new PodBuilder().build()) | ||
.withMainContainer(new ContainerBuilder().build()) | ||
.build(); | ||
|
||
FlinkPod decoratedFlinkPod = flinkLogDecorator.decorateFlinkPod(originalFlinkPod); | ||
|
||
Pod decoratedPod = decoratedFlinkPod.getPodWithoutMainContainer(); | ||
Container decoratedContainer = decoratedFlinkPod.getMainContainer(); | ||
|
||
assertEquals(1, decoratedPod.getSpec().getVolumes().size()); | ||
Volume volume = decoratedPod.getSpec().getVolumes().get(0); | ||
assertEquals("flink-log", volume.getName()); | ||
assertEquals(VOLUME_LOGS, volume.getHostPath().getPath()); | ||
assertEquals("DirectoryOrCreate", volume.getHostPath().getType()); | ||
|
||
assertEquals(1, decoratedContainer.getVolumeMounts().size()); | ||
VolumeMount volumeMount = decoratedContainer.getVolumeMounts().get(0); | ||
assertEquals("flink-log", volumeMount.getName()); | ||
assertEquals(VOLUME_MOUNT_PATH, volumeMount.getMountPath()); | ||
} | ||
} |
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.
I am not a k8s expert. I have some basic questions:
logs that would have disappeared with the container, in storage associated with the pod and we would
lose the logs if the pods die.
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.
Thank you very much for your review. Yes, we can configure a container's PersistentVolume (PV) and PersistentVolumeClaim (PVC) to achieve log mounting.
However, when starting a Flink application via code invocation, we found that the log mounting was not effective. Therefore, we modified this section of the code to implement log mounting and added a toggle kubernetes.decorator.log-mount.enabled. If users encounter the same situation as us, they only need to enable this toggle to achieve log mounting; it is disabled by default.