Skip to content

Commit 6d9f902

Browse files
authored
feat: Add ability to patch dataplane Service, Deployment, and DaemonSet in NginxProxy (#3630)
* Add ability to patch dataplane Service, Deployment, and DaemonSet in NginxProxy
1 parent 5f86938 commit 6d9f902

File tree

7 files changed

+625
-25
lines changed

7 files changed

+625
-25
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alpha2
22

33
import (
44
corev1 "k8s.io/api/core/v1"
5+
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
56
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
67

78
"github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
@@ -388,6 +389,36 @@ type KubernetesSpec struct {
388389
Service *ServiceSpec `json:"service,omitempty"`
389390
}
390391

392+
// Patch defines a patch to apply to a Kubernetes object.
393+
type Patch struct {
394+
// Type is the type of patch. Defaults to StrategicMerge.
395+
//
396+
// +optional
397+
// +kubebuilder:default:=StrategicMerge
398+
Type *PatchType `json:"type,omitempty"`
399+
400+
// Value is the patch data as raw JSON.
401+
// For StrategicMerge and Merge patches, this should be a JSON object.
402+
// For JSONPatch patches, this should be a JSON array of patch operations.
403+
//
404+
// +optional
405+
// +kubebuilder:validation:XPreserveUnknownFields
406+
Value *apiextv1.JSON `json:"value,omitempty"`
407+
}
408+
409+
// PatchType specifies the type of patch.
410+
// +kubebuilder:validation:Enum=StrategicMerge;Merge;JSONPatch
411+
type PatchType string
412+
413+
const (
414+
// PatchTypeStrategicMerge uses strategic merge patch.
415+
PatchTypeStrategicMerge PatchType = "StrategicMerge"
416+
// PatchTypeMerge uses merge patch (RFC 7386).
417+
PatchTypeMerge PatchType = "Merge"
418+
// PatchTypeJSONPatch uses JSON patch (RFC 6902).
419+
PatchTypeJSONPatch PatchType = "JSONPatch"
420+
)
421+
391422
// Deployment is the configuration for the NGINX Deployment.
392423
type DeploymentSpec struct {
393424
// Container defines container fields for the NGINX container.
@@ -404,6 +435,11 @@ type DeploymentSpec struct {
404435
//
405436
// +optional
406437
Pod PodSpec `json:"pod"`
438+
439+
// Patches are custom patches to apply to the NGINX Deployment.
440+
//
441+
// +optional
442+
Patches []Patch `json:"patches,omitempty"`
407443
}
408444

409445
// DaemonSet is the configuration for the NGINX DaemonSet.
@@ -417,6 +453,11 @@ type DaemonSetSpec struct {
417453
//
418454
// +optional
419455
Pod PodSpec `json:"pod"`
456+
457+
// Patches are custom patches to apply to the NGINX DaemonSet.
458+
//
459+
// +optional
460+
Patches []Patch `json:"patches,omitempty"`
420461
}
421462

422463
// PodSpec defines Pod-specific fields.
@@ -594,6 +635,11 @@ type ServiceSpec struct {
594635
//
595636
// +optional
596637
NodePorts []NodePort `json:"nodePorts,omitempty"`
638+
639+
// Patches are custom patches to apply to the NGINX Service.
640+
//
641+
// +optional
642+
Patches []Patch `json:"patches,omitempty"`
597643
}
598644

599645
// ServiceType describes ingress method for the Service.

apis/v1alpha2/zz_generated.deepcopy.go

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

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,30 @@ spec:
511511
type: object
512512
type: array
513513
type: object
514+
patches:
515+
description: Patches are custom patches to apply to the NGINX
516+
DaemonSet.
517+
items:
518+
description: Patch defines a patch to apply to a Kubernetes
519+
object.
520+
properties:
521+
type:
522+
default: StrategicMerge
523+
description: Type is the type of patch. Defaults to
524+
StrategicMerge.
525+
enum:
526+
- StrategicMerge
527+
- Merge
528+
- JSONPatch
529+
type: string
530+
value:
531+
description: |-
532+
Value is the patch data as raw JSON.
533+
For StrategicMerge and Merge patches, this should be a JSON object.
534+
For JSONPatch patches, this should be a JSON array of patch operations.
535+
x-kubernetes-preserve-unknown-fields: true
536+
type: object
537+
type: array
514538
pod:
515539
description: Pod defines Pod-specific fields.
516540
properties:
@@ -3944,6 +3968,30 @@ spec:
39443968
type: object
39453969
type: array
39463970
type: object
3971+
patches:
3972+
description: Patches are custom patches to apply to the NGINX
3973+
Deployment.
3974+
items:
3975+
description: Patch defines a patch to apply to a Kubernetes
3976+
object.
3977+
properties:
3978+
type:
3979+
default: StrategicMerge
3980+
description: Type is the type of patch. Defaults to
3981+
StrategicMerge.
3982+
enum:
3983+
- StrategicMerge
3984+
- Merge
3985+
- JSONPatch
3986+
type: string
3987+
value:
3988+
description: |-
3989+
Value is the patch data as raw JSON.
3990+
For StrategicMerge and Merge patches, this should be a JSON object.
3991+
For JSONPatch patches, this should be a JSON array of patch operations.
3992+
x-kubernetes-preserve-unknown-fields: true
3993+
type: object
3994+
type: array
39473995
pod:
39483996
description: Pod defines Pod-specific fields.
39493997
properties:
@@ -6996,6 +7044,30 @@ spec:
69967044
- port
69977045
type: object
69987046
type: array
7047+
patches:
7048+
description: Patches are custom patches to apply to the NGINX
7049+
Service.
7050+
items:
7051+
description: Patch defines a patch to apply to a Kubernetes
7052+
object.
7053+
properties:
7054+
type:
7055+
default: StrategicMerge
7056+
description: Type is the type of patch. Defaults to
7057+
StrategicMerge.
7058+
enum:
7059+
- StrategicMerge
7060+
- Merge
7061+
- JSONPatch
7062+
type: string
7063+
value:
7064+
description: |-
7065+
Value is the patch data as raw JSON.
7066+
For StrategicMerge and Merge patches, this should be a JSON object.
7067+
For JSONPatch patches, this should be a JSON array of patch operations.
7068+
x-kubernetes-preserve-unknown-fields: true
7069+
type: object
7070+
type: array
69997071
type:
70007072
default: LoadBalancer
70017073
description: ServiceType describes ingress method for the

0 commit comments

Comments
 (0)