forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration properties to inject arbitrary secrets into the d…
…river/executors (#479) * Added configuration properties to inject arbitrary secrets into the driver/executors * Addressed comments
- Loading branch information
1 parent
b61f495
commit f28cb17
Showing
12 changed files
with
331 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...core/src/main/scala/org/apache/spark/deploy/kubernetes/submit/MountSecretsBootstrap.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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} | ||
|
||
/** | ||
* Bootstraps a driver or executor pod with needed secrets mounted. | ||
*/ | ||
private[spark] trait MountSecretsBootstrap { | ||
|
||
/** | ||
* Mounts Kubernetes secrets as secret volumes into the given container in the given pod. | ||
* | ||
* @param pod the pod into which the secret volumes are being added. | ||
* @param container the container into which the secret volumes are being mounted. | ||
* @return the updated pod and container with the secrets mounted. | ||
*/ | ||
def mountSecrets(pod: Pod, container: Container): (Pod, Container) | ||
} | ||
|
||
private[spark] class MountSecretsBootstrapImpl( | ||
secretNamesToMountPaths: Map[String, String]) extends MountSecretsBootstrap { | ||
|
||
override def mountSecrets(pod: Pod, container: Container): (Pod, Container) = { | ||
var podBuilder = new PodBuilder(pod) | ||
secretNamesToMountPaths.keys.foreach(name => | ||
podBuilder = podBuilder | ||
.editOrNewSpec() | ||
.addNewVolume() | ||
.withName(secretVolumeName(name)) | ||
.withNewSecret() | ||
.withSecretName(name) | ||
.endSecret() | ||
.endVolume() | ||
.endSpec()) | ||
|
||
var containerBuilder = new ContainerBuilder(container) | ||
secretNamesToMountPaths.foreach(namePath => | ||
containerBuilder = containerBuilder | ||
.addNewVolumeMount() | ||
.withName(secretVolumeName(namePath._1)) | ||
.withMountPath(namePath._2) | ||
.endVolumeMount() | ||
) | ||
|
||
(podBuilder.build(), containerBuilder.build()) | ||
} | ||
|
||
private def secretVolumeName(secretName: String): String = { | ||
secretName + "-volume" | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...c/main/scala/org/apache/spark/deploy/kubernetes/submit/submitsteps/MountSecretsStep.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 org.apache.spark.deploy.kubernetes.submit.MountSecretsBootstrap | ||
|
||
/** | ||
* A driver configuration step for mounting user-specified secrets onto user-specified paths. | ||
* | ||
* @param mountSecretsBootstrap a utility actually handling mounting of the secrets. | ||
*/ | ||
private[spark] class MountSecretsStep( | ||
mountSecretsBootstrap: MountSecretsBootstrap) extends DriverConfigurationStep { | ||
|
||
override def configureDriver(driverSpec: KubernetesDriverSpec): KubernetesDriverSpec = { | ||
val (driverPodWithSecretsMounted, driverContainerWithSecretsMounted) = | ||
mountSecretsBootstrap.mountSecrets(driverSpec.driverPod, driverSpec.driverContainer) | ||
driverSpec.copy( | ||
driverPod = driverPodWithSecretsMounted, | ||
driverContainer = driverContainerWithSecretsMounted | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.