-
Notifications
You must be signed in to change notification settings - Fork 117
Use a secret to mount small files in driver and executors. #437
Changes from all commits
4f8b61f
f4265b6
e59a24e
929adc2
d652baf
c702b5c
83f8feb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * 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.spark.deploy.kubernetes.submit | ||
|
|
||
| import io.fabric8.kubernetes.api.model.{Container, ContainerBuilder, Pod, PodBuilder} | ||
|
|
||
| import org.apache.spark.deploy.kubernetes.constants._ | ||
|
|
||
| private[spark] trait MountSmallFilesBootstrap { | ||
| def mountSmallFilesSecret(pod: Pod, container: Container): (Pod, Container) | ||
| } | ||
|
|
||
| private[spark] class MountSmallFilesBootstrapImpl( | ||
| secretName: String, secretMountPath: String) extends MountSmallFilesBootstrap { | ||
| def mountSmallFilesSecret(pod: Pod, container: Container): (Pod, Container) = { | ||
| val resolvedPod = new PodBuilder(pod) | ||
| .editOrNewSpec() | ||
| .addNewVolume() | ||
| .withName("submitted-files") | ||
| .withNewSecret() | ||
| .withSecretName(secretName) | ||
| .endSecret() | ||
| .endVolume() | ||
| .endSpec() | ||
| .build() | ||
| val resolvedContainer = new ContainerBuilder(container) | ||
| .addNewEnv() | ||
| .withName(ENV_MOUNTED_FILES_FROM_SECRET_DIR) | ||
| .withValue(secretMountPath) | ||
| .endEnv() | ||
| .addNewVolumeMount() | ||
| .withName("submitted-files") | ||
| .withMountPath(secretMountPath) | ||
| .endVolumeMount() | ||
| .build() | ||
| (resolvedPod, resolvedContainer) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * 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.spark.deploy.kubernetes.submit.submitsteps | ||
|
|
||
| import java.io.File | ||
|
|
||
| import com.google.common.io.{BaseEncoding, Files} | ||
| import io.fabric8.kubernetes.api.model.SecretBuilder | ||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.spark.deploy.kubernetes.config._ | ||
| import org.apache.spark.deploy.kubernetes.submit.{KubernetesFileUtils, MountSmallFilesBootstrap} | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| private[spark] class MountSmallLocalFilesStep( | ||
| sparkFiles: Seq[String], | ||
| smallFilesSecretName: String, | ||
| smallFilesSecretMountPath: String, | ||
| mountSmallFilesBootstrap: MountSmallFilesBootstrap) extends DriverConfigurationStep { | ||
|
|
||
| import MountSmallLocalFilesStep._ | ||
| override def configureDriver(driverSpec: KubernetesDriverSpec): KubernetesDriverSpec = { | ||
| val localFiles = KubernetesFileUtils.getOnlySubmitterLocalFiles(sparkFiles).map(new File(_)) | ||
| val totalSizeBytes = localFiles.map(_.length()).sum | ||
| val totalSizeBytesString = Utils.bytesToString(totalSizeBytes) | ||
| require(totalSizeBytes < MAX_SECRET_BUNDLE_SIZE_BYTES, | ||
| s"Total size of all files submitted must be less than $MAX_SECRET_BUNDLE_SIZE_BYTES_STRING" + | ||
| s" if you do not use a resource staging server. The total size of all submitted local" + | ||
| s" files is $totalSizeBytesString. Please install a resource staging server and configure" + | ||
| s" your application to use it via ${RESOURCE_STAGING_SERVER_URI.key}") | ||
| val localFileBase64Contents = localFiles.map { file => | ||
| val fileBase64 = BaseEncoding.base64().encode(Files.toByteArray(file)) | ||
| (file.getName, fileBase64) | ||
| }.toMap | ||
| val localFilesSecret = new SecretBuilder() | ||
| .withNewMetadata() | ||
| .withName(smallFilesSecretName) | ||
| .endMetadata() | ||
| .withData(localFileBase64Contents.asJava) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's returned out of this method as a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. |
||
| .build() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we haven't added that as an ID label to other secrets created in the submission process (I'm looking at the Do you think it should be there? My first inclination is to match existing practice in this PR, and then if we decide to add labels to secrets to do that in a separate PR
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM. |
||
| val (resolvedDriverPod, resolvedDriverContainer) = | ||
| mountSmallFilesBootstrap.mountSmallFilesSecret( | ||
| driverSpec.driverPod, driverSpec.driverContainer) | ||
| val resolvedSparkConf = driverSpec.driverSparkConf.clone() | ||
| .set(EXECUTOR_SUBMITTED_SMALL_FILES_SECRET, smallFilesSecretName) | ||
| .set(EXECUTOR_SUBMITTED_SMALL_FILES_SECRET_MOUNT_PATH, smallFilesSecretMountPath) | ||
| driverSpec.copy( | ||
| driverPod = resolvedDriverPod, | ||
| driverContainer = resolvedDriverContainer, | ||
| driverSparkConf = resolvedSparkConf, | ||
| otherKubernetesResources = driverSpec.otherKubernetesResources ++ Seq(localFilesSecret)) | ||
| } | ||
| } | ||
|
|
||
| private[spark] object MountSmallLocalFilesStep { | ||
| val MAX_SECRET_BUNDLE_SIZE_BYTES = 10240 | ||
| val MAX_SECRET_BUNDLE_SIZE_BYTES_STRING = | ||
| Utils.bytesToString(MAX_SECRET_BUNDLE_SIZE_BYTES) | ||
| } | ||
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.
aren't there helper methods somewhere for this?
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.
This might belong in
KubernetesFileUtilsbut it has no use other than in here, so I just made it a private method for this.