-
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 3 commits
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 |
|---|---|---|
|
|
@@ -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._ | ||
|
|
||
|
|
@@ -165,17 +165,19 @@ class ExecutorPodFactorySuite extends SparkFunSuite with BeforeAndAfter with Bef | |
|
|
||
| val factory = new ExecutorPodFactory( | ||
| conf, | ||
| None, | ||
| Some(secretsBootstrap), | ||
| Some(initContainerBootstrap), | ||
| Some(secretsBootstrap)) | ||
| val executor = factory.createExecutorPod( | ||
| "1", "dummy", "dummy", Seq[(String, String)](), driverPod, Map[String, Int]()) | ||
|
|
||
| assert(executor.getSpec.getVolumes.size() === 1) | ||
| assert(SecretVolumeUtils.podHasVolume(executor, "secret1-volume")) | ||
| assert(SecretVolumeUtils.containerHasVolume( | ||
| executor.getSpec.getContainers.get(0), "secret1-volume", "/var/secret1")) | ||
| 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.
Since you're touching this, the style is always
.exists { foo => ... }.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.
Done.