Skip to content

Commit 2c644ea

Browse files
authored
Use "default" for the StatefulSet serviceAccountName if none specified (#763)
1 parent 52e0c8a commit 2c644ea

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

api/v1/coherenceresourcespec_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,12 @@ func (in *CoherenceResourceSpec) GetImagePullSecrets() []corev1.LocalObjectRefer
824824
// GetServiceAccountName returns the service account name for the cluster.
825825
func (in *CoherenceResourceSpec) GetServiceAccountName() string {
826826
if in != nil {
827+
if in.ServiceAccountName == "" {
828+
return DefaultServiceAccount
829+
}
827830
return in.ServiceAccountName
828831
}
829-
return ""
832+
return DefaultServiceAccount
830833
}
831834

832835
// CreateCoherenceContainer creates the Coherence container spec.

api/v1/common_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ func createMinimalExpectedPodSpec(deployment coh.CoherenceResource) corev1.PodTe
505505
},
506506
TopologySpreadConstraints: spec.EnsureTopologySpreadConstraints(deployment),
507507
Affinity: spec.CreateDefaultPodAffinity(deployment),
508+
ServiceAccountName: spec.GetServiceAccountName(),
508509
},
509510
}
510511

api/v1/create_job_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestCreateJobWithoutServiceAccount(t *testing.T) {
207207
deployment := createTestCoherenceJob(spec)
208208
// Create expected Job
209209
jobExpected := createMinimalExpectedJob(deployment)
210-
jobExpected.Spec.Template.Spec.ServiceAccountName = ""
210+
jobExpected.Spec.Template.Spec.ServiceAccountName = coh.DefaultServiceAccount
211211

212212
// assert that the Job is as expected
213213
assertJobCreation(t, deployment, jobExpected)

api/v1/create_statefulset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ func TestCreateStatefulSetWithoutServiceAccount(t *testing.T) {
865865
deployment := createTestDeployment(spec)
866866
// Create expected StatefulSet
867867
stsExpected := createMinimalExpectedStatefulSet(deployment)
868-
stsExpected.Spec.Template.Spec.ServiceAccountName = ""
868+
stsExpected.Spec.Template.Spec.ServiceAccountName = coh.DefaultServiceAccount
869869

870870
// assert that the StatefulSet is as expected
871871
assertStatefulSetCreation(t, deployment, stsExpected)

controllers/statefulset/statefulset_controller.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,6 @@ func (in *ReconcileStatefulSet) maybePatchStatefulSet(ctx context.Context, deplo
522522
// fix the CreationTimestamp so that it is not in the patch
523523
desired.SetCreationTimestamp(current.GetCreationTimestamp())
524524

525-
sa1 := current.Spec.Template.Spec.ServiceAccountName
526-
sa2 := original.Spec.Template.Spec.ServiceAccountName
527-
sa3 := desired.Spec.Template.Spec.ServiceAccountName
528-
logger.Info("**** About to create patch for StatefulSet", "CurrentSA", sa1, "OriginalSA", sa2, "DesiredSA", sa3)
529-
530525
// create the patch to see whether there is anything to update
531526
patch, data, err := in.CreateThreeWayPatch(current.GetName(), original, desired, current, patching.PatchIgnore)
532527
if err != nil {

0 commit comments

Comments
 (0)