@@ -444,6 +444,8 @@ func constructDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config
444444
445445 labels := constructAppLabels (app )
446446
447+ serviceAccountName := getServiceAccountName (ctx , app )
448+
447449 var container corev1.Container
448450 if config .RuntimeClassName != nil {
449451 container = corev1.Container {
@@ -508,10 +510,11 @@ func constructDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config
508510 Annotations : templateAnnotations ,
509511 },
510512 Spec : corev1.PodSpec {
511- RuntimeClassName : config .RuntimeClassName ,
512- Containers : []corev1.Container {container },
513- ImagePullSecrets : app .Spec .ImagePullSecrets ,
514- Volumes : volumes ,
513+ RuntimeClassName : config .RuntimeClassName ,
514+ ServiceAccountName : serviceAccountName ,
515+ Containers : []corev1.Container {container },
516+ ImagePullSecrets : app .Spec .ImagePullSecrets ,
517+ Volumes : volumes ,
515518 },
516519 },
517520 },
@@ -530,6 +533,25 @@ func constructDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config
530533 return dep , nil
531534}
532535
536+ // getServiceAccountName returns the service account name to use for the deployment.
537+ // If serviceAccountName is specified on the SpinApp, it returns that value.
538+ // Otherwise, it returns "default" which is the Kubernetes default.
539+ func getServiceAccountName (ctx context.Context , app * spinv1alpha1.SpinApp ) string {
540+ log := logging .FromContext (ctx ).WithValues ("component" , "getServiceAccountName" )
541+
542+ log .Debug ("Determining service account name" ,
543+ "app" , app .Name ,
544+ "namespace" , app .Namespace ,
545+ "serviceAccountNameInSpec" , app .Spec .ServiceAccountName )
546+
547+ if app .Spec .ServiceAccountName != "" {
548+ log .Debug ("Using service account from SpinApp" , "serviceAccountName" , app .Spec .ServiceAccountName )
549+ return app .Spec .ServiceAccountName
550+ }
551+
552+ return "default"
553+ }
554+
533555// findDeploymentForApp finds the deployment for a SpinApp.
534556func (r * SpinAppReconciler ) findDeploymentForApp (ctx context.Context , app * spinv1alpha1.SpinApp ) (* appsv1.Deployment , error ) {
535557 var deployment appsv1.Deployment
0 commit comments