XComp commented on a change in pull request #17819: URL: https://github.com/apache/flink/pull/17819#discussion_r777569648
########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/parameters/AbstractKubernetesParameters.java ########## @@ -63,6 +64,36 @@ public String getConfigDirectory() { return configDir; } + public static String createAffixedClusterId( + String clusterId, KubernetesLabelAffix.KubernetesLabelPrefix prefix) { + final String affixedClusterId = prefix + clusterId; + checkAffixedClusterId(affixedClusterId); + return affixedClusterId; + } + + public static String createAffixedClusterId( + String clusterId, KubernetesLabelAffix.KubernetesLabelSuffix suffix) { + final String affixedClusterId = clusterId + suffix; + checkAffixedClusterId(affixedClusterId); + return affixedClusterId; + } + + private static void checkAffixedClusterId(String affixedClusterId) { + if (StringUtils.isBlank(affixedClusterId)) { + throw new IllegalArgumentException( + KubernetesConfigOptions.CLUSTER_ID.key() + " must not be blank."); Review comment: ```suggestion Preconditions.checkArgument( isNullOrWhitespaceOnly(affixedClusterId), "%s must not be blank.", KubernetesConfigOptions.CLUSTER_ID.key()); ``` nit: `Preconditions` are easier to read than an if block (just a personal opinion). Additionally, I guess it's better to use the utility methods provided by Flink instead of relying on external libraries (this applies to the `Preconditions` and the `isNullOrWhitespaceOnly` - which is a substitute for `StringUtils.isBlank` - imports. ########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/KubernetesLabelAffix.java ########## @@ -0,0 +1,78 @@ +/* + * 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.utils; + +import java.util.Arrays; + +/** Collection of affixes for Kubernetes labels. */ +public class KubernetesLabelAffix { Review comment: I think we could merge both enums into a single enum being called `KubernetesLabel`. Each enum value can be get either two parameters (prefix and suffix) or a single parameter (format string with `%s`). Additionally, a method generateLabel(String clusterId) can be provided that handles the actual label generation. There's no need to do the label generation in `AbstractKubernetesParameters`. WDYT? ########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/parameters/AbstractKubernetesParameters.java ########## @@ -63,6 +64,36 @@ public String getConfigDirectory() { return configDir; } + public static String createAffixedClusterId( + String clusterId, KubernetesLabelAffix.KubernetesLabelPrefix prefix) { + final String affixedClusterId = prefix + clusterId; + checkAffixedClusterId(affixedClusterId); + return affixedClusterId; + } + + public static String createAffixedClusterId( + String clusterId, KubernetesLabelAffix.KubernetesLabelSuffix suffix) { + final String affixedClusterId = clusterId + suffix; + checkAffixedClusterId(affixedClusterId); + return affixedClusterId; + } + + private static void checkAffixedClusterId(String affixedClusterId) { + if (StringUtils.isBlank(affixedClusterId)) { + throw new IllegalArgumentException( + KubernetesConfigOptions.CLUSTER_ID.key() + " must not be blank."); + } else if (affixedClusterId.length() > Constants.KUBERNETES_LABEL_MAX_LENGTH) { Review comment: Same as above applies to the second if condition. ########## File path: flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/parameters/AbstractKubernetesParameters.java ########## @@ -63,6 +64,36 @@ public String getConfigDirectory() { return configDir; } + public static String createAffixedClusterId( + String clusterId, KubernetesLabelAffix.KubernetesLabelPrefix prefix) { + final String affixedClusterId = prefix + clusterId; + checkAffixedClusterId(affixedClusterId); + return affixedClusterId; + } + + public static String createAffixedClusterId( + String clusterId, KubernetesLabelAffix.KubernetesLabelSuffix suffix) { + final String affixedClusterId = clusterId + suffix; + checkAffixedClusterId(affixedClusterId); + return affixedClusterId; + } Review comment: Both method could be moved into the `KubernetesLabel` enum. I think, the label generation logic should be kept in one place. WDYT? -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org