Skip to content

Use "default" for the serviceAccountName if none specified #763

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

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/v1/coherenceresourcespec_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions api/v1/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ func createMinimalExpectedPodSpec(deployment coh.CoherenceResource) corev1.PodTe
},
TopologySpreadConstraints: spec.EnsureTopologySpreadConstraints(deployment),
Affinity: spec.CreateDefaultPodAffinity(deployment),
ServiceAccountName: spec.GetServiceAccountName(),
},
}

Expand Down
2 changes: 1 addition & 1 deletion api/v1/create_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/v1/create_statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions controllers/statefulset/statefulset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down