Myracle commented on code in PR #27523:
URL: https://github.com/apache/flink/pull/27523#discussion_r2944288485


##########
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/PersistentVolumeClaimMountDecorator.java:
##########
@@ -0,0 +1,492 @@
+/*
+ * 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 org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
+import org.apache.flink.kubernetes.kubeclient.FlinkPod;
+import 
org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters;
+
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.ContainerBuilder;
+import 
io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSourceBuilder;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Decorator for mounting Kubernetes PersistentVolumeClaims (PVCs) to 
JobManager and TaskManager
+ * pods.
+ *
+ * <p>This decorator allows users to attach pre-existing PVCs to Flink pods, 
enabling persistent
+ * storage for checkpoints, savepoints, or other data that needs to survive 
pod restarts.
+ *
+ * <h2>Configuration</h2>
+ *
+ * <p>Users can configure PVC mounting through the following configuration 
options:
+ *
+ * <ul>
+ *   <li>{@link KubernetesConfigOptions#KUBERNETES_PERSISTENT_VOLUME_CLAIMS} - 
Specifies PVCs and
+ *       their mount paths in the format {@code 
pvc-name:/mount/path,pvc-name2:/mount/path2}
+ *   <li>{@link 
KubernetesConfigOptions#KUBERNETES_PERSISTENT_VOLUME_CLAIM_READ_ONLY} - When 
set to
+ *       true, mounts all PVCs as read-only (default: false)
+ * </ul>
+ *
+ * <h2>Usage Example</h2>
+ *
+ * <pre>{@code
+ * # Mount a single PVC for checkpoint storage
+ * kubernetes.persistent-volume-claims: checkpoint-pvc:/opt/flink/checkpoints
+ *
+ * # Mount multiple PVCs
+ * kubernetes.persistent-volume-claims: 
checkpoint-pvc:/opt/flink/checkpoints,data-pvc:/opt/flink/data
+ *
+ * # Mount PVCs as read-only
+ * kubernetes.persistent-volume-claim-read-only: true
+ * }</pre>
+ *
+ * <h2>Validation</h2>
+ *
+ * <p>This decorator validates that:
+ *
+ * <ul>
+ *   <li>PVC names conform to DNS-1123 subdomain standard (lowercase 
alphanumeric, '-' and '.', max
+ *       253 chars)
+ *   <li>Mount paths are non-empty and absolute (start with '/')
+ *   <li>No duplicate mount paths are specified
+ *   <li>Generated volume names do not conflict with existing volumes
+ * </ul>
+ *
+ * <h2>Volume Name Generation</h2>
+ *
+ * <p>Volume names are generated from PVC names by:
+ *
+ * <ol>
+ *   <li>Replacing '.' with '-' (DNS-1123 label requirement)
+ *   <li>Adding '-pvc' suffix
+ *   <li>Truncating to 63 characters if necessary (with hash suffix for 
uniqueness)
+ * </ol>
+ *
+ * <h2>Important Notes</h2>
+ *
+ * <ul>
+ *   <li>The PVC must exist in the same namespace as the Flink cluster
+ *   <li>The PVC must have an appropriate access mode (ReadWriteOnce, 
ReadWriteMany, etc.)
+ *   <li>For HA setups with multiple JobManagers, use ReadWriteMany or 
ReadOnlyMany access modes
+ *   <li>If you need different read/write modes for different PVCs, use Pod 
Templates instead
+ * </ul>
+ *
+ * @see KubernetesConfigOptions#KUBERNETES_PERSISTENT_VOLUME_CLAIMS
+ * @see KubernetesConfigOptions#KUBERNETES_PERSISTENT_VOLUME_CLAIM_READ_ONLY
+ */
+@Internal
+public class PersistentVolumeClaimMountDecorator extends 
AbstractKubernetesStepDecorator {
+
+    private static final Logger LOG =
+            LoggerFactory.getLogger(PersistentVolumeClaimMountDecorator.class);
+
+    /** Suffix appended to sanitized PVC names to generate volume names. */
+    @VisibleForTesting static final String VOLUME_NAME_SUFFIX = "-pvc";

Review Comment:
   Right — these are well-known Kubernetes spec constants (DNS-1123 
label/subdomain limits and patterns), not implementation details we're leaking 
for tests. Made all five public static final. Thanks for the nudge.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to