wangyang0918 commented on a change in pull request #12899:
URL: https://github.com/apache/flink/pull/12899#discussion_r471422158



##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/configuration/KubernetesConfigOptions.java
##########
@@ -221,6 +221,21 @@
        /** Defines the configuration key of that external resource in 
Kubernetes. This is used as a suffix in an actual config. */
        public static final String 
EXTERNAL_RESOURCE_KUBERNETES_CONFIG_KEY_SUFFIX = "kubernetes.config-key";
 
+       public static final ConfigOption<Map<String, String>> 
KUBERNETES_SECRETS =
+               key("kubernetes.secrets")
+                       .mapType()
+                       .noDefaultValue()
+                       .withDescription("The user-specified secrets that will 
be mounted into Flink container. The value should be in " +
+                               "the form of 
foo:/opt/secrets-foo,bar:/opt/secrets-bar. Users could also specify this config 
option via -D cli option.");

Review comment:
       ```suggestion
                                "the form of 
foo:/opt/secrets-foo,bar:/opt/secrets-bar.");
   ```

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/EnvSecretsDecorator.java
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.kubernetes.kubeclient.FlinkPod;
+import 
org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters;
+import org.apache.flink.kubernetes.kubeclient.resources.KubernetesSecretEnvVar;
+
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.ContainerBuilder;
+import io.fabric8.kubernetes.api.model.EnvVar;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * support setting environment variables via Secrets.
+ */
+public class EnvSecretsDecorator extends AbstractKubernetesStepDecorator {
+
+       private final AbstractKubernetesParameters kubernetesComponentConf;
+
+       public EnvSecretsDecorator(AbstractKubernetesParameters 
kubernetesComponentConf) {
+               this.kubernetesComponentConf = 
checkNotNull(kubernetesComponentConf);
+       }
+
+       @Override
+       public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
+               final Container basicMainContainer = new 
ContainerBuilder(flinkPod.getMainContainer())
+                       .addAllToEnv(getSecretEnvs())
+                       .build();
+
+               return new FlinkPod.Builder(flinkPod)
+                       .withPod(flinkPod.getPod())

Review comment:
       Maybe we remove this line since we do not decorate the existing pod.

##########
File path: 
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/VolumeTestUtils.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.Pod;
+
+/**
+ * Utilities for the Kubernetes tests.
+ */
+public class VolumeTestUtils {
+
+       public static boolean podHasVolume(Pod pod, String volumeName){
+               return pod.getSpec()

Review comment:
       Same as above about how to break the long line.

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/MountSecretsDecorator.java
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.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.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 static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * support mounting Secrets on the JobManager or TaskManager pod..
+ */
+public class MountSecretsDecorator extends AbstractKubernetesStepDecorator {
+
+       private final AbstractKubernetesParameters kubernetesComponentConf;
+
+       public MountSecretsDecorator(AbstractKubernetesParameters 
kubernetesComponentConf) {
+               this.kubernetesComponentConf = 
checkNotNull(kubernetesComponentConf);
+       }
+
+       @Override
+       public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
+               final Pod podWithMount = decoratePod(flinkPod.getPod());
+               final Container containerWithMount = 
decorateMainContainer(flinkPod.getMainContainer());
+
+               return new FlinkPod.Builder(flinkPod)
+                       .withPod(podWithMount)
+                       .withMainContainer(containerWithMount)
+                       .build();
+       }
+
+       private Container decorateMainContainer(Container container) {
+               final VolumeMount[] volumeMounts = kubernetesComponentConf

Review comment:
       ```
   final VolumeMount[] volumeMounts = 
kubernetesComponentConf.getSecretNamesToMountPaths().entrySet().stream()
                        .map(secretNameToPath -> new VolumeMountBuilder()
                                
.withName(secretVolumeName(secretNameToPath.getKey()))
                                .withMountPath(secretNameToPath.getValue())
                                .build()
                        )
                        .toArray(VolumeMount[]::new);
   ```
   
   Maybe this format is better. Please check the code style for more 
information.
   
https://flink.apache.org/contributing/code-style-and-quality-formatting.html#breaking-the-lines-of-too-long-statements

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/MountSecretsDecorator.java
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.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.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 static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * support mounting Secrets on the JobManager or TaskManager pod..
+ */
+public class MountSecretsDecorator extends AbstractKubernetesStepDecorator {
+
+       private final AbstractKubernetesParameters kubernetesComponentConf;
+
+       public MountSecretsDecorator(AbstractKubernetesParameters 
kubernetesComponentConf) {
+               this.kubernetesComponentConf = 
checkNotNull(kubernetesComponentConf);
+       }
+
+       @Override
+       public FlinkPod decorateFlinkPod(FlinkPod flinkPod) {
+               final Pod podWithMount = decoratePod(flinkPod.getPod());
+               final Container containerWithMount = 
decorateMainContainer(flinkPod.getMainContainer());
+
+               return new FlinkPod.Builder(flinkPod)
+                       .withPod(podWithMount)
+                       .withMainContainer(containerWithMount)
+                       .build();
+       }
+
+       private Container decorateMainContainer(Container container) {
+               final VolumeMount[] volumeMounts = kubernetesComponentConf
+                       .getSecretNamesToMountPaths()
+                       .entrySet()
+                       .stream()
+                       .map(secretNameToPath ->
+                               new VolumeMountBuilder()
+                                       
.withName(secretVolumeName(secretNameToPath.getKey()))
+                                       
.withMountPath(secretNameToPath.getValue())
+                                       .build()
+                       ).toArray(VolumeMount[]::new);
+
+               return new ContainerBuilder(container)
+                       .addToVolumeMounts(volumeMounts)
+                       .build();
+       }
+
+       private Pod decoratePod(Pod pod) {
+               final Volume[] volumes = 
kubernetesComponentConf.getSecretNamesToMountPaths()

Review comment:
       Same as above.




----------------------------------------------------------------
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.

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


Reply via email to