Skip to content

Commit 9d25399

Browse files
committed
Allow for provisioning NGINX as DaemonSet
Problem: With the initial provisioner implementation, the NGINX gateway could only be installed as a Deployment. Users may want to install NGINX as a DaemonSet. Solution: Allow for provisioning the NGINX gateway as a DaemonSet.
1 parent 4ccceb9 commit 9d25399

File tree

21 files changed

+7231
-74
lines changed

21 files changed

+7231
-74
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,22 @@ const (
359359
)
360360

361361
// KubernetesSpec contains the configuration for the NGINX Deployment and Service Kubernetes objects.
362+
//
363+
// +kubebuilder:validation:XValidation:message="only one of deployment or daemonSet can be set",rule="(!has(self.deployment) && !has(self.daemonSet)) || ((has(self.deployment) && !has(self.daemonSet)) || (!has(self.deployment) && has(self.daemonSet)))"
364+
//
365+
//nolint:lll
362366
type KubernetesSpec struct {
363367
// Deployment is the configuration for the NGINX Deployment.
364368
// This is the default deployment option.
365369
//
366370
// +optional
367371
Deployment *DeploymentSpec `json:"deployment,omitempty"`
368372

373+
// DaemonSet is the configuration for the NGINX DaemonSet.
374+
//
375+
// +optional
376+
DaemonSet *DaemonSetSpec `json:"daemonSet,omitempty"`
377+
369378
// Service is the configuration for the NGINX Service.
370379
//
371380
// +optional
@@ -382,12 +391,25 @@ type DeploymentSpec struct {
382391
// Pod defines Pod-specific fields.
383392
//
384393
// +optional
385-
Pod PodSpec `json:"pod,omitempty"`
394+
Pod PodSpec `json:"pod"`
395+
396+
// Container defines container fields for the NGINX container.
397+
//
398+
// +optional
399+
Container ContainerSpec `json:"container"`
400+
}
401+
402+
// DaemonSet is the configuration for the NGINX DaemonSet.
403+
type DaemonSetSpec struct {
404+
// Pod defines Pod-specific fields.
405+
//
406+
// +optional
407+
Pod PodSpec `json:"pod"`
386408

387409
// Container defines container fields for the NGINX container.
388410
//
389411
// +optional
390-
Container ContainerSpec `json:"container,omitempty"`
412+
Container ContainerSpec `json:"container"`
391413
}
392414

393415
// PodSpec defines Pod-specific fields.

apis/v1alpha2/zz_generated.deepcopy.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/nginx-gateway-fabric/templates/clusterrole.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rules:
1414
- serviceaccounts
1515
- services
1616
- deployments
17+
- daemonsets
1718
verbs:
1819
- create
1920
- update

charts/nginx-gateway-fabric/templates/nginxproxy.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ spec:
2727
debug: {{ .Values.nginx.debug }}
2828
{{- end }}
2929
{{- end }}
30+
{{- if eq .Values.nginx.kind "daemonSet" }}
31+
daemonSet:
32+
{{- if .Values.nginx.pod }}
33+
pod:
34+
{{- toYaml .Values.nginx.pod | nindent 8 }}
35+
{{- end }}
36+
container:
37+
{{- if .Values.nginx.container }}
38+
{{- toYaml .Values.nginx.container | nindent 8 }}
39+
{{- end }}
40+
image:
41+
{{- toYaml .Values.nginx.image | nindent 10 }}
42+
{{- if .Values.nginx.debug }}
43+
debug: {{ .Values.nginx.debug }}
44+
{{- end }}
45+
{{- end }}
3046
{{- if .Values.nginx.service }}
3147
service:
3248
{{- with .Values.nginx.service }}

charts/nginx-gateway-fabric/values.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@
328328
"default": "deployment",
329329
"description": "The kind of NGINX deployment.",
330330
"enum": [
331-
"deployment"
331+
"deployment",
332+
"daemonSet"
332333
],
333334
"required": [],
334335
"title": "kind"

charts/nginx-gateway-fabric/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ nginx:
185185
# @schema
186186
# enum:
187187
# - deployment
188+
# - daemonSet
188189
# @schema
189190
# -- The kind of NGINX deployment.
190191
kind: deployment

config/crd/bases/gateway.nginx.org_nginxproxies.yaml

Lines changed: 3388 additions & 0 deletions
Large diffs are not rendered by default.

deploy/crds.yaml

Lines changed: 3388 additions & 0 deletions
Large diffs are not rendered by default.

internal/mode/static/nginx/agent/command.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,15 @@ func (cs *commandService) getPodOwner(podName string) (types.NamespacedName, err
447447
return types.NamespacedName{}, fmt.Errorf("expected one owner reference of the nginx Pod, got %d", len(podOwnerRefs))
448448
}
449449

450-
if podOwnerRefs[0].Kind != "ReplicaSet" {
451-
err := fmt.Errorf("expected pod owner reference to be ReplicaSet, got %s", podOwnerRefs[0].Kind)
450+
if podOwnerRefs[0].Kind != "ReplicaSet" && podOwnerRefs[0].Kind != "DaemonSet" {
451+
err := fmt.Errorf("expected pod owner reference to be ReplicaSet or DaemonSet, got %s", podOwnerRefs[0].Kind)
452452
return types.NamespacedName{}, err
453453
}
454454

455+
if podOwnerRefs[0].Kind == "DaemonSet" {
456+
return types.NamespacedName{Namespace: pod.Namespace, Name: podOwnerRefs[0].Name}, nil
457+
}
458+
455459
var replicaSet appsv1.ReplicaSet
456460
var replicaSetErr error
457461
if err := wait.PollUntilContextCancel(

internal/mode/static/nginx/agent/command_test.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ func TestGetPodOwner(t *testing.T) {
690690
expected types.NamespacedName
691691
}{
692692
{
693-
name: "successfully gets pod owner",
693+
name: "successfully gets pod owner; ReplicaSet",
694694
podName: "nginx-pod",
695695
podList: &v1.PodList{
696696
Items: []v1.Pod{
@@ -725,6 +725,31 @@ func TestGetPodOwner(t *testing.T) {
725725
Name: "nginx-deployment",
726726
},
727727
},
728+
{
729+
name: "successfully gets pod owner; DaemonSet",
730+
podName: "nginx-pod",
731+
podList: &v1.PodList{
732+
Items: []v1.Pod{
733+
{
734+
ObjectMeta: metav1.ObjectMeta{
735+
Name: "nginx-pod",
736+
Namespace: "test",
737+
OwnerReferences: []metav1.OwnerReference{
738+
{
739+
Kind: "DaemonSet",
740+
Name: "nginx-daemonset",
741+
},
742+
},
743+
},
744+
},
745+
},
746+
},
747+
replicaSet: &appsv1.ReplicaSet{},
748+
expected: types.NamespacedName{
749+
Namespace: "test",
750+
Name: "nginx-daemonset",
751+
},
752+
},
728753
{
729754
name: "error listing pods",
730755
podName: "nginx-pod",
@@ -745,7 +770,7 @@ func TestGetPodOwner(t *testing.T) {
745770
errString: "should only be one pod with name",
746771
},
747772
{
748-
name: "pod owner reference is not ReplicaSet",
773+
name: "pod owner reference is not ReplicaSet or DaemonSet",
749774
podName: "nginx-pod",
750775
podList: &v1.PodList{
751776
Items: []v1.Pod{
@@ -763,7 +788,7 @@ func TestGetPodOwner(t *testing.T) {
763788
},
764789
},
765790
replicaSet: &appsv1.ReplicaSet{},
766-
errString: "expected pod owner reference to be ReplicaSet",
791+
errString: "expected pod owner reference to be ReplicaSet or DaemonSet",
767792
},
768793
{
769794
name: "pod has multiple owners",

0 commit comments

Comments
 (0)