Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions apis/v1alpha1/snippetsfilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type SnippetsFilterSpec struct {
// Snippets is a list of NGINX configuration snippets.
// There can only be one snippet per context.
// Allowed contexts: main, http, http.server, http.server.location.
// +kubebuilder:validation:MaxItems=4
// +kubebuilder:validation:XValidation:message="Only one snippet allowed per context",rule="self.all(s1, self.exists_one(s2, s1.context == s2.context))"
//nolint:lll
Snippets []Snippet `json:"snippets"`
}

Expand Down Expand Up @@ -104,7 +107,7 @@ const (
// the condition is true.
SnippetsFilterConditionReasonAccepted SnippetsFilterConditionReason = "Accepted"

// SnippetsFilterConditionTypeInvalid is used with the Accepted condition type when
// SnippetsFilterConditionReasonInvalid is used with the Accepted condition type when
// SnippetsFilter is invalid.
SnippetsFilterConditionTypeInvalid SnippetsFilterConditionType = "Invalid"
SnippetsFilterConditionReasonInvalid SnippetsFilterConditionReason = "Invalid"
)
1 change: 1 addition & 0 deletions charts/nginx-gateway-fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
| `nginxGateway.replicaCount` | The number of replicas of the NGINX Gateway Fabric Deployment. | int | `1` |
| `nginxGateway.resources` | The resource requests and/or limits of the nginx-gateway container. | object | `{}` |
| `nginxGateway.securityContext.allowPrivilegeEscalation` | Some environments may need this set to true in order for the control plane to successfully reload NGINX. | bool | `false` |
| `nginxGateway.snippetsFilters.enable` | Enable SnippetsFilters feature. SnippetsFilters allow inserting NGINX configuration into the generated NGINX config for HTTPRoute and GRPCRoute resources. | bool | `false` |
| `nodeSelector` | The nodeSelector of the NGINX Gateway Fabric pod. | object | `{}` |
| `service.annotations` | The annotations of the NGINX Gateway Fabric service. | object | `{}` |
| `service.create` | Creates a service to expose the NGINX Gateway Fabric pods. | bool | `true` |
Expand Down
6 changes: 6 additions & 0 deletions charts/nginx-gateway-fabric/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ rules:
- nginxproxies
- clientsettingspolicies
- observabilitypolicies
{{- if .Values.nginxGateway.snippetsFilters.enable }}
- snippetsfilters
{{- end }}
verbs:
- list
- watch
Expand All @@ -113,6 +116,9 @@ rules:
- nginxgateways/status
- clientsettingspolicies/status
- observabilitypolicies/status
{{- if .Values.nginxGateway.snippetsFilters.enable }}
- snippetsfilters/status
{{- end }}
verbs:
- update
{{- if .Values.nginxGateway.leaderElection.enable }}
Expand Down
3 changes: 3 additions & 0 deletions charts/nginx-gateway-fabric/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spec:
{{- if .Values.nginx.usage.insecureSkipVerify }}
- --usage-report-skip-verify
{{- end }}
{{- if .Values.nginxGateway.snippetsFilters.enable }}
- --snippets-filters
{{- end }}
env:
- name: POD_IP
valueFrom:
Expand Down
5 changes: 5 additions & 0 deletions charts/nginx-gateway-fabric/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ nginxGateway:
# APIs installed from the experimental channel.
enable: false

snippetsFilters:
# -- Enable SnippetsFilters feature. SnippetsFilters allow inserting NGINX configuration into the generated NGINX
# config for HTTPRoute and GRPCRoute resources.
enable: false

nginx:
image:
# -- The NGINX image to use.
Expand Down
12 changes: 12 additions & 0 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
usageReportServerURLFlag = "usage-report-server-url"
usageReportSkipVerifyFlag = "usage-report-skip-verify"
usageReportClusterNameFlag = "usage-report-cluster-name"
snippetsFiltersFlag = "snippets-filters"
)

// flag values
Expand Down Expand Up @@ -116,6 +117,8 @@
usageReportServerURL = stringValidatingValue{
validator: validateURL,
}

snippetsFilters bool
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -239,6 +242,7 @@
Names: flagKeys,
Values: flagValues,
},
SnippetsFilters: snippetsFilters,

Check warning on line 245 in cmd/gateway/commands.go

View check run for this annotation

Codecov / codecov/patch

cmd/gateway/commands.go#L245

Added line #L245 was not covered by tests
}

if err := static.StartManager(conf); err != nil {
Expand Down Expand Up @@ -394,6 +398,14 @@
"Disable client verification of the NGINX Plus usage reporting server certificate.",
)

cmd.Flags().BoolVar(
&snippetsFilters,
snippetsFiltersFlag,
false,
"Enable SnippetsFilters feature. SnippetsFilters allow inserting NGINX configuration into the "+
"generated NGINX config for HTTPRoute and GRPCRoute resources.",
)

return cmd
}

Expand Down
10 changes: 10 additions & 0 deletions cmd/gateway/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func TestStaticModeCmdFlagValidation(t *testing.T) {
"--usage-report-secret=default/my-secret",
"--usage-report-server-url=https://my-api.com",
"--usage-report-cluster-name=my-cluster",
"--snippets-filters",
},
wantErr: false,
},
Expand Down Expand Up @@ -381,6 +382,15 @@ func TestStaticModeCmdFlagValidation(t *testing.T) {
wantErr: true,
expectedErrPrefix: `invalid argument "$invalid*(#)" for "--usage-report-cluster-name" flag: invalid format`,
},
{
name: "snippets-filters is not a bool",
expectedErrPrefix: `invalid argument "not-a-bool" for "--snippets-filters" flag: strconv.ParseBool:` +
` parsing "not-a-bool": invalid syntax`,
args: []string{
"--snippets-filters=not-a-bool",
},
wantErr: true,
},
}

// common flags validation is tested separately
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/gateway.nginx.org_snippetsfilters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ spec:
- context
- value
type: object
maxItems: 4
type: array
x-kubernetes-validations:
- message: Only one snippet allowed per context
rule: self.all(s1, self.exists_one(s2, s1.context == s2.context))
required:
- snippets
type: object
Expand Down
Loading
Loading