Skip to content

feat: Add ability to patch dataplane Service, Deployment, and DaemonSet in NginxProxy #3630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions apis/v1alpha2/nginxproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha2

import (
corev1 "k8s.io/api/core/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
Expand Down Expand Up @@ -388,6 +389,35 @@ type KubernetesSpec struct {
Service *ServiceSpec `json:"service,omitempty"`
}

// Patch defines a patch to apply to a Kubernetes object.
type Patch struct {
// Type is the type of patch. Defaults to StrategicMerge.
//
// +optional
// +kubebuilder:default:=StrategicMerge
Type *PatchType `json:"type,omitempty"`

// Value is the patch data as raw JSON.
// For StrategicMerge and Merge patches, this should be a JSON object.
// For JSONPatch patches, this should be a JSON array of patch operations.
//
// +kubebuilder:validation:XPreserveUnknownFields
Value *apiextv1.JSON `json:"value"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this field be marked as optional?

}

// PatchType specifies the type of patch.
// +kubebuilder:validation:Enum=StrategicMerge;Merge;JSONPatch
type PatchType string

const (
// PatchTypeStrategicMerge uses strategic merge patch.
PatchTypeStrategicMerge PatchType = "StrategicMerge"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does k8s define these types at all? If so, it'd be nice to alias our types to theirs, instead of using the string literal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// PatchTypeMerge uses merge patch (RFC 7386).
PatchTypeMerge PatchType = "Merge"
// PatchTypeJSONPatch uses JSON patch (RFC 6902).
PatchTypeJSONPatch PatchType = "JSONPatch"
)

// Deployment is the configuration for the NGINX Deployment.
type DeploymentSpec struct {
// Number of desired Pods.
Expand All @@ -404,6 +434,11 @@ type DeploymentSpec struct {
//
// +optional
Container ContainerSpec `json:"container"`

// Patches are custom patches to apply to the NGINX Deployment.
//
// +optional
Patches []Patch `json:"patches,omitempty"`
}

// DaemonSet is the configuration for the NGINX DaemonSet.
Expand All @@ -417,6 +452,11 @@ type DaemonSetSpec struct {
//
// +optional
Container ContainerSpec `json:"container"`

// Patches are custom patches to apply to the NGINX DaemonSet.
//
// +optional
Patches []Patch `json:"patches,omitempty"`
}

// PodSpec defines Pod-specific fields.
Expand Down Expand Up @@ -569,6 +609,11 @@ type ServiceSpec struct {
//
// +optional
NodePorts []NodePort `json:"nodePorts,omitempty"`

// Patches are custom patches to apply to the NGINX Service.
//
// +optional
Patches []Patch `json:"patches,omitempty"`
}

// ServiceType describes ingress method for the Service.
Expand Down
63 changes: 55 additions & 8 deletions apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions config/crd/bases/gateway.nginx.org_nginxproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,32 @@ spec:
type: object
type: array
type: object
patches:
description: Patches are custom patches to apply to the NGINX
DaemonSet.
items:
description: Patch defines a patch to apply to a Kubernetes
object.
properties:
type:
default: StrategicMerge
description: Type is the type of patch. Defaults to
StrategicMerge.
enum:
- StrategicMerge
- Merge
- JSONPatch
type: string
value:
description: |-
Value is the patch data as raw JSON.
For StrategicMerge and Merge patches, this should be a JSON object.
For JSONPatch patches, this should be a JSON array of patch operations.
x-kubernetes-preserve-unknown-fields: true
required:
- value
type: object
type: array
pod:
description: Pod defines Pod-specific fields.
properties:
Expand Down Expand Up @@ -3900,6 +3926,32 @@ spec:
type: object
type: array
type: object
patches:
description: Patches are custom patches to apply to the NGINX
Deployment.
items:
description: Patch defines a patch to apply to a Kubernetes
object.
properties:
type:
default: StrategicMerge
description: Type is the type of patch. Defaults to
StrategicMerge.
enum:
- StrategicMerge
- Merge
- JSONPatch
type: string
value:
description: |-
Value is the patch data as raw JSON.
For StrategicMerge and Merge patches, this should be a JSON object.
For JSONPatch patches, this should be a JSON array of patch operations.
x-kubernetes-preserve-unknown-fields: true
required:
- value
type: object
type: array
pod:
description: Pod defines Pod-specific fields.
properties:
Expand Down Expand Up @@ -6952,6 +7004,32 @@ spec:
- port
type: object
type: array
patches:
description: Patches are custom patches to apply to the NGINX
Service.
items:
description: Patch defines a patch to apply to a Kubernetes
object.
properties:
type:
default: StrategicMerge
description: Type is the type of patch. Defaults to
StrategicMerge.
enum:
- StrategicMerge
- Merge
- JSONPatch
type: string
value:
description: |-
Value is the patch data as raw JSON.
For StrategicMerge and Merge patches, this should be a JSON object.
For JSONPatch patches, this should be a JSON array of patch operations.
x-kubernetes-preserve-unknown-fields: true
required:
- value
type: object
type: array
type:
default: LoadBalancer
description: ServiceType describes ingress method for the
Expand Down
Loading
Loading