Skip to content

Commit

Permalink
Creating service account where approriate for MPI Job (#1917)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpemsel authored Sep 20, 2023
1 parent 3d46a36 commit 288d680
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/controller.v1/mpi/mpijob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,14 @@ func (jc *MPIJobReconciler) getOrCreateConfigMap(mpiJob *kubeflowv1.MPIJob, work
// getOrCreateLauncherServiceAccount gets the launcher ServiceAccount controlled
// by this MPIJob, or creates one if it doesn't exist.
func (jc *MPIJobReconciler) getOrCreateLauncherServiceAccount(mpiJob *kubeflowv1.MPIJob) (*corev1.ServiceAccount, error) {
saName := mpiJob.Spec.MPIReplicaSpecs[kubeflowv1.MPIJobReplicaTypeLauncher].Template.Spec.ServiceAccountName

if len(saName) == 0 {
saName = mpiJob.Name + launcherSuffix
}

sa := &corev1.ServiceAccount{}
NamespacedName := types.NamespacedName{Namespace: mpiJob.Namespace, Name: mpiJob.Name + launcherSuffix}
NamespacedName := types.NamespacedName{Namespace: mpiJob.Namespace, Name: saName}
err := jc.Get(context.Background(), NamespacedName, sa)

if err == nil {
Expand Down Expand Up @@ -1035,7 +1040,10 @@ func (jc *MPIJobReconciler) newLauncher(mpiJob *kubeflowv1.MPIJob, kubectlDelive
jc.PodGroupControl.DecoratePodTemplateSpec(podSpec, mpiJob, rt)
}

podSpec.Spec.ServiceAccountName = launcherName
if len(mpiJob.Spec.MPIReplicaSpecs[kubeflowv1.MPIJobReplicaTypeLauncher].Template.Spec.ServiceAccountName) == 0 {
podSpec.Spec.ServiceAccountName = launcherName
}

podSpec.Spec.InitContainers = append(podSpec.Spec.InitContainers, corev1.Container{
Name: kubectlDeliveryName,
Image: kubectlDeliveryImage,
Expand Down Expand Up @@ -1297,9 +1305,15 @@ func updateDiscoverHostsInConfigMap(configMap *corev1.ConfigMap, mpiJob *kubeflo
// resource. It also sets the appropriate OwnerReferences on the resource so
// handleObject can discover the MPIJob resource that 'owns' it.
func newLauncherServiceAccount(mpiJob *kubeflowv1.MPIJob) *corev1.ServiceAccount {
launcherName := mpiJob.Name + launcherSuffix

if len(mpiJob.Spec.MPIReplicaSpecs[kubeflowv1.MPIJobReplicaTypeLauncher].Template.Spec.ServiceAccountName) > 0 {
launcherName = mpiJob.Spec.MPIReplicaSpecs[kubeflowv1.MPIJobReplicaTypeLauncher].Template.Spec.ServiceAccountName
}

return &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: mpiJob.Name + launcherSuffix,
Name: launcherName,
Namespace: mpiJob.Namespace,
Labels: map[string]string{
"app": mpiJob.Name,
Expand Down Expand Up @@ -1351,6 +1365,11 @@ func newLauncherRole(mpiJob *kubeflowv1.MPIJob, workerReplicas int32) *rbacv1.Ro
// handleObject can discover the MPIJob resource that 'owns' it.
func newLauncherRoleBinding(mpiJob *kubeflowv1.MPIJob) *rbacv1.RoleBinding {
launcherName := mpiJob.Name + launcherSuffix

if len(mpiJob.Spec.MPIReplicaSpecs[kubeflowv1.MPIJobReplicaTypeLauncher].Template.Spec.ServiceAccountName) > 0 {
launcherName = mpiJob.Spec.MPIReplicaSpecs[kubeflowv1.MPIJobReplicaTypeLauncher].Template.Spec.ServiceAccountName
}

return &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: launcherName,
Expand Down

0 comments on commit 288d680

Please sign in to comment.