-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22953][K8S] Avoids adding duplicated secret volumes when init-container is used #20148
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -28,20 +28,26 @@ private[spark] class MountSecretsBootstrap(secretNamesToMountPaths: Map[String, | |
| * | ||
| * @param pod the pod into which the secret volumes are being added. | ||
| * @param container the container into which the secret volumes are being mounted. | ||
| * @param addNewVolumes whether to add new secret volumes for the secrets. | ||
| * @return the updated pod and container with the secrets mounted. | ||
| */ | ||
| def mountSecrets(pod: Pod, container: Container): (Pod, Container) = { | ||
| def mountSecrets( | ||
|
||
| pod: Pod, | ||
| container: Container, | ||
| addNewVolumes: Boolean): (Pod, Container) = { | ||
| var podBuilder = new PodBuilder(pod) | ||
| secretNamesToMountPaths.keys.foreach { name => | ||
| podBuilder = podBuilder | ||
| .editOrNewSpec() | ||
| if (addNewVolumes) { | ||
| secretNamesToMountPaths.keys.foreach { name => | ||
| podBuilder = podBuilder | ||
| .editOrNewSpec() | ||
| .addNewVolume() | ||
| .withName(secretVolumeName(name)) | ||
| .withNewSecret() | ||
| .withSecretName(name) | ||
| .endSecret() | ||
| .endVolume() | ||
| .withName(secretVolumeName(name)) | ||
| .withNewSecret() | ||
| .withSecretName(name) | ||
| .endSecret() | ||
| .endVolume() | ||
| .endSpec() | ||
| } | ||
| } | ||
|
|
||
| var containerBuilder = new ContainerBuilder(container) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,23 +14,20 @@ | |
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.spark.deploy.k8s.submit | ||
| package org.apache.spark.deploy.k8s | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import io.fabric8.kubernetes.api.model.{Container, Pod} | ||
|
|
||
| private[spark] object SecretVolumeUtils { | ||
|
|
||
| def podHasVolume(driverPod: Pod, volumeName: String): Boolean = { | ||
| driverPod.getSpec.getVolumes.asScala.exists(volume => volume.getName == volumeName) | ||
| def podHasVolume(pod: Pod, volumeName: String): Boolean = { | ||
| pod.getSpec.getVolumes.asScala.exists(volume => volume.getName == volumeName) | ||
|
||
| } | ||
|
|
||
| def containerHasVolume( | ||
| driverContainer: Container, | ||
| volumeName: String, | ||
| mountPath: String): Boolean = { | ||
| driverContainer.getVolumeMounts.asScala.exists(volumeMount => | ||
| def containerHasVolume(container: Container, volumeName: String, mountPath: String): Boolean = { | ||
| container.getVolumeMounts.asScala.exists(volumeMount => | ||
|
||
| volumeMount.getName == volumeName && volumeMount.getMountPath == mountPath) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ import org.mockito.Mockito._ | |
| import org.scalatest.{BeforeAndAfter, BeforeAndAfterEach} | ||
|
|
||
| import org.apache.spark.{SparkConf, SparkFunSuite} | ||
| import org.apache.spark.deploy.k8s.{InitContainerBootstrap, MountSecretsBootstrap, PodWithDetachedInitContainer} | ||
| import org.apache.spark.deploy.k8s.{InitContainerBootstrap, MountSecretsBootstrap, PodWithDetachedInitContainer, SecretVolumeUtils} | ||
| import org.apache.spark.deploy.k8s.Config._ | ||
| import org.apache.spark.deploy.k8s.Constants._ | ||
|
|
||
|
|
@@ -172,10 +172,8 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef | |
| "1", "dummy", "dummy", Seq[(String, String)](), driverPod, Map[String, Int]()) | ||
|
|
||
| assert(executor.getSpec.getInitContainers.size() === 1) | ||
| assert(executor.getSpec.getInitContainers.get(0).getVolumeMounts.get(0).getName | ||
| === "secret1-volume") | ||
| assert(executor.getSpec.getInitContainers.get(0).getVolumeMounts.get(0) | ||
| .getMountPath === "/var/secret1") | ||
| assert(SecretVolumeUtils.containerHasVolume( | ||
|
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 might be better to change
Contributor
Author
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. Done. 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. Thanks! We also need check volumes' num in pod spec.
Contributor
Author
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. Done. 93e1d64. |
||
| executor.getSpec.getInitContainers.get(0), "secret1-volume", "/var/secret1")) | ||
|
|
||
| checkOwnerReferences(executor, driverPodUid) | ||
| } | ||
|
|
||
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 think this problem arose because we're conflating two things here - adding secret volumes (which are pod-scoped) and adding volume-mounts (which are container-scoped). I think we should separate these out. The branching may work for now, but we should have a future work item to separate these out.
cc/ @mccheah
Uh oh!
There was an error while loading. Please reload this page.
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.
Agreed. I didn't separate it out because we will touch this code as part of refactoring the steps code anyway as planned in https://issues.apache.org/jira/browse/SPARK-22839.