Skip to content

Commit

Permalink
fix(dataplane): properly default deprecated service account name (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Nov 14, 2024
1 parent d817213 commit f974562
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
- [v0.1.1](#v011)
- [v0.1.0](#v010)

## Unreleased

### Fixes

- Fix setting the `ServiceAccountName` for `DataPlane`'s `Deployment`.
[#856](https://github.com/Kong/gateway-operator/pull/856)

## [v1.4.0]

> Release date: 2024-10-31
Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/kubernetes/resources/strategicmerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func SetDefaultsPodTemplateSpec(pts *corev1.PodTemplateSpec) {
return
}

// NOTE: copy the service account name to the deprecated field as the
// API server does that itself.
pts.Spec.DeprecatedServiceAccount = pts.Spec.ServiceAccountName

pkgapiscorev1.SetDefaults_PodSpec(&pts.Spec)
for i := range pts.Spec.Volumes {
SetDefaultsVolume(&pts.Spec.Volumes[i])
Expand Down
37 changes: 37 additions & 0 deletions pkg/utils/kubernetes/resources/strategicmerge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,40 @@ func TestStrategicMergePatchPodTemplateSpec(t *testing.T) {
})
}
}

func TestSetDefaultsPodTemplateSpec(t *testing.T) {
testcases := []struct {
Name string
Patch *corev1.PodTemplateSpec
Expected corev1.PodTemplateSpec
}{
{
Name: "serivce account name is copied to deprecated field",
Patch: &corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
ServiceAccountName: "account",
},
},
Expected: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
ServiceAccountName: "account",
DeprecatedServiceAccount: "account",
// NOTE: below set fields are irrelevant for the test
// but are set by SetDefaultsPodTemplateSpec regardless.
RestartPolicy: corev1.RestartPolicyAlways,
DNSPolicy: corev1.DNSClusterFirst,
SchedulerName: corev1.DefaultSchedulerName,
TerminationGracePeriodSeconds: lo.ToPtr(int64(30)),
SecurityContext: &corev1.PodSecurityContext{},
},
},
},
}

for _, tc := range testcases {
t.Run(tc.Name, func(t *testing.T) {
SetDefaultsPodTemplateSpec(tc.Patch)
assert.Equal(t, tc.Expected, *tc.Patch)
})
}
}

0 comments on commit f974562

Please sign in to comment.