Skip to content

Commit a736dd6

Browse files
committed
Add support for volume mounts in daemonsets
1 parent 6981901 commit a736dd6

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

internal/controller/handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ func (h *eventHandlerImpl) sendNginxConfig(ctx context.Context, logger logr.Logg
248248
vm = gw.EffectiveNginxProxy.Kubernetes.Deployment.Container.VolumeMounts
249249
}
250250

251+
if gw.EffectiveNginxProxy != nil &&
252+
gw.EffectiveNginxProxy.Kubernetes != nil &&
253+
gw.EffectiveNginxProxy.Kubernetes.DaemonSet != nil {
254+
vm = gw.EffectiveNginxProxy.Kubernetes.DaemonSet.Container.VolumeMounts
255+
}
256+
251257
deployment.FileLock.Lock()
252258
h.updateNginxConf(deployment, cfg, vm)
253259
deployment.FileLock.Unlock()

internal/controller/handler_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2323

2424
ngfAPI "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
25+
"github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2"
2526
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/config"
2627
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/licensing/licensingfakes"
2728
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/metrics/collectors"
@@ -642,6 +643,104 @@ var _ = Describe("eventHandler", func() {
642643

643644
Expect(handler.GetLatestConfiguration()).To(BeEmpty())
644645
})
646+
647+
It("should process events with volume mounts from Deployment", func() {
648+
// Create a gateway with EffectiveNginxProxy containing Deployment VolumeMounts
649+
gatewayWithVolumeMounts := &graph.Graph{
650+
Gateways: map[types.NamespacedName]*graph.Gateway{
651+
{Namespace: "test", Name: "gateway"}: {
652+
Valid: true,
653+
Source: &gatewayv1.Gateway{
654+
ObjectMeta: metav1.ObjectMeta{
655+
Name: "gateway",
656+
Namespace: "test",
657+
},
658+
},
659+
DeploymentName: types.NamespacedName{
660+
Namespace: "test",
661+
Name: controller.CreateNginxResourceName("gateway", "nginx"),
662+
},
663+
EffectiveNginxProxy: &graph.EffectiveNginxProxy{
664+
Kubernetes: &v1alpha2.KubernetesSpec{
665+
Deployment: &v1alpha2.DeploymentSpec{
666+
Container: v1alpha2.ContainerSpec{
667+
VolumeMounts: []v1.VolumeMount{
668+
{
669+
Name: "test-volume",
670+
MountPath: "/etc/test",
671+
},
672+
},
673+
},
674+
},
675+
},
676+
},
677+
},
678+
},
679+
}
680+
681+
fakeProcessor.ProcessReturns(gatewayWithVolumeMounts)
682+
683+
e := &events.UpsertEvent{Resource: &gatewayv1.HTTPRoute{}}
684+
batch := []interface{}{e}
685+
686+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
687+
688+
// Verify that UpdateConfig was called with the volume mounts
689+
Expect(fakeNginxUpdater.UpdateConfigCallCount()).Should(Equal(1))
690+
_, _, volumeMounts := fakeNginxUpdater.UpdateConfigArgsForCall(0)
691+
Expect(volumeMounts).To(HaveLen(1))
692+
Expect(volumeMounts[0].Name).To(Equal("test-volume"))
693+
Expect(volumeMounts[0].MountPath).To(Equal("/etc/test"))
694+
})
695+
696+
It("should process events with volume mounts from DaemonSet", func() {
697+
// Create a gateway with EffectiveNginxProxy containing DaemonSet VolumeMounts
698+
gatewayWithVolumeMounts := &graph.Graph{
699+
Gateways: map[types.NamespacedName]*graph.Gateway{
700+
{Namespace: "test", Name: "gateway"}: {
701+
Valid: true,
702+
Source: &gatewayv1.Gateway{
703+
ObjectMeta: metav1.ObjectMeta{
704+
Name: "gateway",
705+
Namespace: "test",
706+
},
707+
},
708+
DeploymentName: types.NamespacedName{
709+
Namespace: "test",
710+
Name: controller.CreateNginxResourceName("gateway", "nginx"),
711+
},
712+
EffectiveNginxProxy: &graph.EffectiveNginxProxy{
713+
Kubernetes: &v1alpha2.KubernetesSpec{
714+
DaemonSet: &v1alpha2.DaemonSetSpec{
715+
Container: v1alpha2.ContainerSpec{
716+
VolumeMounts: []v1.VolumeMount{
717+
{
718+
Name: "daemon-volume",
719+
MountPath: "/var/daemon",
720+
},
721+
},
722+
},
723+
},
724+
},
725+
},
726+
},
727+
},
728+
}
729+
730+
fakeProcessor.ProcessReturns(gatewayWithVolumeMounts)
731+
732+
e := &events.UpsertEvent{Resource: &gatewayv1.HTTPRoute{}}
733+
batch := []interface{}{e}
734+
735+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
736+
737+
// Verify that UpdateConfig was called with the volume mounts
738+
Expect(fakeNginxUpdater.UpdateConfigCallCount()).Should(Equal(1))
739+
_, _, volumeMounts := fakeNginxUpdater.UpdateConfigArgsForCall(0)
740+
Expect(volumeMounts).To(HaveLen(1))
741+
Expect(volumeMounts[0].Name).To(Equal("daemon-volume"))
742+
Expect(volumeMounts[0].MountPath).To(Equal("/var/daemon"))
743+
})
645744
})
646745

647746
var _ = Describe("getGatewayAddresses", func() {

0 commit comments

Comments
 (0)