diff --git a/api/v1/coherenceresourcespec_types.go b/api/v1/coherenceresourcespec_types.go index 2686dacc..6e9001f2 100644 --- a/api/v1/coherenceresourcespec_types.go +++ b/api/v1/coherenceresourcespec_types.go @@ -824,9 +824,12 @@ func (in *CoherenceResourceSpec) GetImagePullSecrets() []corev1.LocalObjectRefer // GetServiceAccountName returns the service account name for the cluster. func (in *CoherenceResourceSpec) GetServiceAccountName() string { if in != nil { + if in.ServiceAccountName == "" { + return DefaultServiceAccount + } return in.ServiceAccountName } - return "" + return DefaultServiceAccount } // CreateCoherenceContainer creates the Coherence container spec. diff --git a/api/v1/common_test.go b/api/v1/common_test.go index b05e7f4e..e8bf465c 100644 --- a/api/v1/common_test.go +++ b/api/v1/common_test.go @@ -505,6 +505,7 @@ func createMinimalExpectedPodSpec(deployment coh.CoherenceResource) corev1.PodTe }, TopologySpreadConstraints: spec.EnsureTopologySpreadConstraints(deployment), Affinity: spec.CreateDefaultPodAffinity(deployment), + ServiceAccountName: spec.GetServiceAccountName(), }, } diff --git a/api/v1/create_job_test.go b/api/v1/create_job_test.go index 4fbd332d..9d004be5 100644 --- a/api/v1/create_job_test.go +++ b/api/v1/create_job_test.go @@ -207,7 +207,7 @@ func TestCreateJobWithoutServiceAccount(t *testing.T) { deployment := createTestCoherenceJob(spec) // Create expected Job jobExpected := createMinimalExpectedJob(deployment) - jobExpected.Spec.Template.Spec.ServiceAccountName = "" + jobExpected.Spec.Template.Spec.ServiceAccountName = coh.DefaultServiceAccount // assert that the Job is as expected assertJobCreation(t, deployment, jobExpected) diff --git a/api/v1/create_statefulset_test.go b/api/v1/create_statefulset_test.go index 579d26ca..920fcb1a 100644 --- a/api/v1/create_statefulset_test.go +++ b/api/v1/create_statefulset_test.go @@ -865,7 +865,7 @@ func TestCreateStatefulSetWithoutServiceAccount(t *testing.T) { deployment := createTestDeployment(spec) // Create expected StatefulSet stsExpected := createMinimalExpectedStatefulSet(deployment) - stsExpected.Spec.Template.Spec.ServiceAccountName = "" + stsExpected.Spec.Template.Spec.ServiceAccountName = coh.DefaultServiceAccount // assert that the StatefulSet is as expected assertStatefulSetCreation(t, deployment, stsExpected) diff --git a/controllers/statefulset/statefulset_controller.go b/controllers/statefulset/statefulset_controller.go index 82641098..3dcc6ef9 100644 --- a/controllers/statefulset/statefulset_controller.go +++ b/controllers/statefulset/statefulset_controller.go @@ -522,11 +522,6 @@ func (in *ReconcileStatefulSet) maybePatchStatefulSet(ctx context.Context, deplo // fix the CreationTimestamp so that it is not in the patch desired.SetCreationTimestamp(current.GetCreationTimestamp()) - sa1 := current.Spec.Template.Spec.ServiceAccountName - sa2 := original.Spec.Template.Spec.ServiceAccountName - sa3 := desired.Spec.Template.Spec.ServiceAccountName - logger.Info("**** About to create patch for StatefulSet", "CurrentSA", sa1, "OriginalSA", sa2, "DesiredSA", sa3) - // create the patch to see whether there is anything to update patch, data, err := in.CreateThreeWayPatch(current.GetName(), original, desired, current, patching.PatchIgnore) if err != nil {