Skip to content

Commit 853238e

Browse files
[Backport release/2.0.x] fix(dataplane): fix DataPlane's volume and volume mounts patching when specified by user (#2425) (#2460)
Co-authored-by: Patryk Małek <patryk.malek@konghq.com>
1 parent b5cb82b commit 853238e

File tree

16 files changed

+1552
-214
lines changed

16 files changed

+1552
-214
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ jobs:
588588
KONG_CONTROLLER_OUT: stdout
589589
GOTESTSUM_JUNITFILE: integration-tests-bluegreen.xml
590590
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
591+
KONG_TEST_KONNECT_ACCESS_TOKEN: ${{ secrets.KONG_TEST_KONNECT_ACCESS_TOKEN }}
592+
KONG_TEST_KONNECT_SERVER_URL: us.api.konghq.tech
591593

592594
- name: upload diagnostics
593595
if: always()

CHANGELOG.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
- [v0.1.1](#v011)
3535
- [v0.1.0](#v010)
3636

37+
## Unreleased
38+
39+
### Fixes
40+
41+
- Fix `DataPlane`'s volumes and volume mounts patching when specified by user
42+
[#2425](https://github.com/Kong/kong-operator/pull/2425)
43+
3744
## [v2.0.4]
3845

3946
> Release date: 2025-10-03
@@ -78,7 +85,7 @@
7885

7986
> Release date: 2025-09-17
8087
81-
## Fixes
88+
### Fixes
8289

8390
- Fix incorrect error handling during cluster CA secret creation.
8491
[#2250](https://github.com/Kong/kong-operator/pull/2250)
@@ -238,7 +245,7 @@
238245
- `kong/kong-gateway` v3.11 is the default proxy image.
239246
[#2212](https://github.com/Kong/kong-operator/pull/2212)
240247

241-
### Fixed
248+
### Fixes
242249

243250
- Do not check "Programmed" condition in status of `Gateway` listeners in
244251
extracting certificates in controlplane's translation of Kong configuration.
@@ -270,7 +277,7 @@
270277

271278
> Release date: 2025-07-11
272279
273-
### Fixed
280+
### Fixes
274281

275282
- Ignore the `ForbiddenError` in `sdk-konnect-go` returned from running CRUD
276283
operations against Konnect APIs. This prevents endless reconciliation when an
@@ -696,7 +703,7 @@
696703
flag or the `GATEWAY_OPERATOR_ENABLE_CONTROLLER_KONNECT` env var is set.
697704
[#738](https://github.com/kong/kong-operator/pull/738)
698705

699-
### Fixed
706+
### Fixes
700707

701708
- Fixed `ControlPlane` cluster wide resources not migrating to new ownership labels
702709
(introduced in 1.3.0) when upgrading the operator from 1.2 (or older) to 1.3.0.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Builder
33
# ------------------------------------------------------------------------------
44

5-
FROM --platform=$BUILDPLATFORM golang:1.25.1@sha256:8305f5fa8ea63c7b5bc85bd223ccc62941f852318ebfbd22f53bbd0b358c07e1 AS builder
5+
FROM --platform=$BUILDPLATFORM golang:1.25.3@sha256:7d73c4c57127279b23f3f70cbb368bf0fe08f7ab32af5daf5764173d25e78b74 AS builder
66

77
WORKDIR /workspace
88
ARG GOPATH

controller/dataplane/controller_reconciler_utils_test.go

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ func TestDeploymentBuilder(t *testing.T) {
108108
Spec: corev1.PodSpec{
109109
Volumes: []corev1.Volume{
110110
{
111-
// NOTE: we need to provide the existing entry in the slice
111+
// NOTE: we can provide the existing entry in the slice
112112
// to prevent merging the provided new entry with existing entries.
113+
// Next test case shows that we can also not provide it and it will
114+
// still work as expected (although the order may change).
113115
Name: consts.ClusterCertificateVolume,
114116
},
115117
{
@@ -207,6 +209,111 @@ func TestDeploymentBuilder(t *testing.T) {
207209
)
208210
},
209211
},
212+
{
213+
name: "new DataPlane with custom secret (without specifying the base certificate volume or volume mount)",
214+
dataPlane: &operatorv1beta1.DataPlane{
215+
ObjectMeta: metav1.ObjectMeta{
216+
Name: "test-secret-volume",
217+
Namespace: "default",
218+
},
219+
Spec: operatorv1beta1.DataPlaneSpec{
220+
DataPlaneOptions: operatorv1beta1.DataPlaneOptions{
221+
Deployment: operatorv1beta1.DataPlaneDeploymentOptions{
222+
DeploymentOptions: operatorv1beta1.DeploymentOptions{
223+
PodTemplateSpec: &corev1.PodTemplateSpec{
224+
Spec: corev1.PodSpec{
225+
Volumes: []corev1.Volume{
226+
{
227+
Name: "test-volume",
228+
VolumeSource: corev1.VolumeSource{
229+
Secret: &corev1.SecretVolumeSource{
230+
SecretName: "test-secret",
231+
},
232+
},
233+
},
234+
},
235+
Containers: []corev1.Container{
236+
{
237+
Name: consts.DataPlaneProxyContainerName,
238+
VolumeMounts: []corev1.VolumeMount{
239+
{
240+
Name: "test-volume",
241+
MountPath: "/var/test/",
242+
ReadOnly: true,
243+
},
244+
},
245+
},
246+
},
247+
},
248+
},
249+
},
250+
},
251+
},
252+
},
253+
},
254+
certSecretName: "certificate",
255+
testBody: func(t *testing.T, reconciler Reconciler, dataPlane *operatorv1beta1.DataPlane, certSecretName string) {
256+
ctx := t.Context()
257+
258+
deploymentBuilder := NewDeploymentBuilder(logr.Discard(), reconciler.Client).
259+
WithClusterCertificate(certSecretName).
260+
WithAdditionalLabels(deploymentLiveLabels)
261+
262+
deployment, res, err := deploymentBuilder.BuildAndDeploy(ctx, dataPlane, enforceConfig, validateDataPlaneImage)
263+
require.NoError(t, err)
264+
require.Equal(t, op.Created, res)
265+
require.Len(t, deployment.Spec.Template.Spec.Volumes, 2)
266+
require.Len(t, deployment.Spec.Template.Spec.Containers, 1)
267+
require.Len(t, deployment.Spec.Template.Spec.Containers[0].VolumeMounts, 2)
268+
269+
certificateVolume := corev1.Volume{}
270+
certificateVolume.Secret = &corev1.SecretVolumeSource{}
271+
// Fill in the defaults for the volume after setting the secret volume source
272+
// field. This prevents setting the empty dir volume source field which
273+
// would conflict with the secret volume source field.
274+
k8sresources.SetDefaultsVolume(&certificateVolume)
275+
certificateVolume.Name = consts.ClusterCertificateVolume
276+
certificateVolume.Secret.SecretName = "certificate"
277+
certificateVolume.Secret.Items = []corev1.KeyToPath{
278+
{
279+
Key: "tls.crt",
280+
Path: "tls.crt",
281+
},
282+
{
283+
Key: "tls.key",
284+
Path: "tls.key",
285+
},
286+
{
287+
Key: "ca.crt",
288+
Path: "ca.crt",
289+
},
290+
}
291+
292+
testVolume := corev1.Volume{}
293+
testVolume.Secret = &corev1.SecretVolumeSource{}
294+
// Fill in the defaults for the volume after setting the secret volume source
295+
// field. This prevents setting the empty dir volume source field which
296+
// would conflict with the secret volume source field.
297+
k8sresources.SetDefaultsVolume(&testVolume)
298+
testVolume.Name = "test-volume"
299+
testVolume.Secret.SecretName = "test-secret"
300+
301+
require.Equal(t, []corev1.VolumeMount{
302+
{
303+
Name: "test-volume",
304+
MountPath: "/var/test/",
305+
ReadOnly: true,
306+
},
307+
{
308+
Name: consts.ClusterCertificateVolume,
309+
MountPath: consts.ClusterCertificateVolumeMountPath,
310+
ReadOnly: true,
311+
},
312+
},
313+
deployment.Spec.Template.Spec.Containers[0].VolumeMounts,
314+
)
315+
},
316+
},
210317
{
211318
name: "existing DataPlane deployment gets updated with expected spec.Strategy",
212319
dataPlane: &operatorv1beta1.DataPlane{

0 commit comments

Comments
 (0)