Skip to content
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

Implement ClientSettingsPolicy #1940

Merged
merged 38 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c953477
Implement ClientSettingsPolicy Attachment
kate-osborn Apr 24, 2024
b5a13a4
Change example files
kate-osborn May 7, 2024
294b347
Mark proposal as completed
kate-osborn May 7, 2024
7eeb012
Generate CRDs
kate-osborn May 7, 2024
b9f0c13
Remove PolicyAncestorRef
kate-osborn May 7, 2024
530cf7d
Use v1 ParentRef
kate-osborn May 7, 2024
77fd3ae
Update template formatting
kate-osborn May 8, 2024
cb2cb7f
Move routeKeyForKind
kate-osborn May 8, 2024
23c2465
Fix route type in test
kate-osborn May 8, 2024
41517dc
Add constant for ancestor max
kate-osborn May 8, 2024
ca228aa
Reduce rbac privs
kate-osborn May 8, 2024
da6afda
Add test to the names of test functions
kate-osborn May 8, 2024
a2e42d3
Fix comment for sort.ClientObject
kate-osborn May 8, 2024
65eb514
Remove newline
kate-osborn May 8, 2024
08e53b9
Add comments to RouteKey fields
kate-osborn May 8, 2024
f3938cf
Add space after includes and before locations
kate-osborn May 8, 2024
e6ea1bd
Add CEL validation for target ref kind
kate-osborn May 8, 2024
4b7e914
Add CEL validation for target ref group
kate-osborn May 8, 2024
fadd9e5
Remove content from Include
kate-osborn May 16, 2024
dbebb53
testData -> assertData
kate-osborn May 16, 2024
1a461aa
use real upstream in test
kate-osborn May 16, 2024
24e6507
Remove unnecessary validation
kate-osborn May 16, 2024
5986149
Extract function for adding includes to locations
kate-osborn May 16, 2024
a0d0c5f
Create MustExtractGVK type
kate-osborn May 16, 2024
0a172d1
Small fixes
kate-osborn May 16, 2024
f045cc7
Generate CRDs
kate-osborn May 17, 2024
f71d296
Add fixme
kate-osborn May 17, 2024
4ca2334
Run generate manifests
kate-osborn May 17, 2024
b37f578
Make Includes a list of strings
kate-osborn May 17, 2024
a287332
Refactor change processor to accept MustExtractGVK
kate-osborn May 17, 2024
d37c2da
Panic if addition is nil
kate-osborn May 17, 2024
4412a21
Use MustcastObject helper method
kate-osborn May 17, 2024
2d3c364
Fix condition type
kate-osborn May 17, 2024
f25e9fd
Address issues with sort package and tests
kate-osborn May 17, 2024
c28a52b
Addition does not need to be a pointer
kate-osborn May 17, 2024
c071435
Panic when policy is nil in isrelevant
kate-osborn May 17, 2024
5c41398
Simplify ancestorsFull
kate-osborn May 17, 2024
2842083
Reinstate header/server validation
kate-osborn May 20, 2024
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
9 changes: 8 additions & 1 deletion apis/v1alpha1/clientsettingspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ type ClientSettingsPolicySpec struct {

// TargetRef identifies an API object to apply the policy to.
// Object must be in the same namespace as the policy.
// Support: Gateway, HTTPRoute, GRPCRoute.
//
// Support: Gateway, HTTPRoute
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute",rule="(self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')"
// +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io.",rule="(self.group=='gateway.networking.k8s.io')"
//nolint:lll
TargetRef gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRef"`
}

Expand Down Expand Up @@ -95,7 +98,11 @@ type ClientKeepAlive struct {

// Timeout defines the keep-alive timeouts for clients.
//
// +kubebuilder:validation:XValidation:message="header can only be specified if server is specified",rule="!(has(self.header) && !has(self.server))"
//
//
// +optional
//nolint:lll
Timeout *ClientKeepAliveTimeout `json:"timeout,omitempty"`
}

Expand Down
21 changes: 21 additions & 0 deletions apis/v1alpha1/policy_methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v1alpha1

import (
"sigs.k8s.io/gateway-api/apis/v1alpha2"
)

// FIXME(kate-osborn): https://github.com/nginxinc/nginx-gateway-fabric/issues/1939.
// Figure out a way to generate these methods for all our policies.
// These methods implement the policies.Policy interface which extends client.Object to add the following methods.

func (p *ClientSettingsPolicy) GetTargetRef() v1alpha2.LocalPolicyTargetReference {
return p.Spec.TargetRef
}

func (p *ClientSettingsPolicy) GetPolicyStatus() v1alpha2.PolicyStatus {
return p.Status
}

func (p *ClientSettingsPolicy) SetPolicyStatus(status v1alpha2.PolicyStatus) {
p.Status = status
}
6 changes: 6 additions & 0 deletions charts/nginx-gateway-fabric/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
{{- with .Values.nginxGateway.extraVolumeMounts -}}
{{ toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -161,6 +163,8 @@ spec:
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
{{- with .Values.nginx.extraVolumeMounts -}}
{{ toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -195,6 +199,8 @@ spec:
emptyDir: {}
- name: nginx-lib
emptyDir: {}
- name: nginx-includes
emptyDir: {}
{{- with .Values.extraVolumes -}}
{{ toYaml . | nindent 6 }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions charts/nginx-gateway-fabric/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ rules:
- gateway.nginx.org
resources:
- nginxproxies
- clientsettingspolicies
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- nginxgateways/status
- clientsettingspolicies/status
verbs:
- update
{{- if .Values.nginxGateway.leaderElection.enable }}
Expand Down
13 changes: 10 additions & 3 deletions config/crd/bases/gateway.nginx.org_clientsettingspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ spec:
pattern: ^\d{1,4}(ms|s)?$
type: string
type: object
x-kubernetes-validations:
- message: header can only be specified if server is specified
rule: '!(has(self.header) && !has(self.server))'
type: object
targetRef:
description: |-
TargetRef identifies an API object to apply the policy to.
Object must be in the same namespace as the policy.


Support: Gateway, HTTPRoute
Support: Gateway, HTTPRoute, GRPCRoute.
properties:
group:
description: Group is the group of the target resource.
Expand All @@ -138,6 +139,12 @@ spec:
- kind
- name
type: object
x-kubernetes-validations:
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
GRPCRoute'
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
- message: TargetRef Group must be gateway.networking.k8s.io.
rule: (self.group=='gateway.networking.k8s.io')
required:
- targetRef
type: object
Expand Down
6 changes: 6 additions & 0 deletions conformance/provisioner/static-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
- image: ghcr.io/nginxinc/nginx-gateway-fabric/nginx:edge
imagePullPolicy: Always
name: nginx
Expand Down Expand Up @@ -106,6 +108,8 @@ spec:
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
terminationGracePeriodSeconds: 30
serviceAccountName: nginx-gateway
shareProcessNamespace: true
Expand All @@ -125,3 +129,5 @@ spec:
emptyDir: {}
- name: nginx-lib
emptyDir: {}
- name: nginx-includes
emptyDir: {}
13 changes: 10 additions & 3 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ spec:
pattern: ^\d{1,4}(ms|s)?$
type: string
type: object
x-kubernetes-validations:
- message: header can only be specified if server is specified
rule: '!(has(self.header) && !has(self.server))'
type: object
targetRef:
description: |-
TargetRef identifies an API object to apply the policy to.
Object must be in the same namespace as the policy.


Support: Gateway, HTTPRoute
Support: Gateway, HTTPRoute, GRPCRoute.
properties:
group:
description: Group is the group of the target resource.
Expand All @@ -137,6 +138,12 @@ spec:
- kind
- name
type: object
x-kubernetes-validations:
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
GRPCRoute'
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
- message: TargetRef Group must be gateway.networking.k8s.io.
rule: (self.group=='gateway.networking.k8s.io')
required:
- targetRef
type: object
Expand Down
8 changes: 8 additions & 0 deletions deploy/manifests/nginx-gateway-experimental.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ rules:
- gateway.nginx.org
resources:
- nginxproxies
- clientsettingspolicies
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- nginxgateways/status
- clientsettingspolicies/status
verbs:
- update
- apiGroups:
Expand Down Expand Up @@ -228,6 +230,8 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
- image: ghcr.io/nginxinc/nginx-gateway-fabric/nginx:edge
imagePullPolicy: Always
name: nginx
Expand Down Expand Up @@ -258,6 +262,8 @@ spec:
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
terminationGracePeriodSeconds: 30
serviceAccountName: nginx-gateway
shareProcessNamespace: true
Expand All @@ -277,6 +283,8 @@ spec:
emptyDir: {}
- name: nginx-lib
emptyDir: {}
- name: nginx-includes
emptyDir: {}
---
# Source: nginx-gateway-fabric/templates/gatewayclass.yaml
apiVersion: gateway.networking.k8s.io/v1
Expand Down
8 changes: 8 additions & 0 deletions deploy/manifests/nginx-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ rules:
- gateway.nginx.org
resources:
- nginxproxies
- clientsettingspolicies
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- nginxgateways/status
- clientsettingspolicies/status
verbs:
- update
- apiGroups:
Expand Down Expand Up @@ -224,6 +226,8 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
- image: ghcr.io/nginxinc/nginx-gateway-fabric/nginx:edge
imagePullPolicy: Always
name: nginx
Expand Down Expand Up @@ -254,6 +258,8 @@ spec:
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
terminationGracePeriodSeconds: 30
serviceAccountName: nginx-gateway
shareProcessNamespace: true
Expand All @@ -273,6 +279,8 @@ spec:
emptyDir: {}
- name: nginx-lib
emptyDir: {}
- name: nginx-includes
emptyDir: {}
---
# Source: nginx-gateway-fabric/templates/gatewayclass.yaml
apiVersion: gateway.networking.k8s.io/v1
Expand Down
8 changes: 8 additions & 0 deletions deploy/manifests/nginx-plus-gateway-experimental.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ rules:
- gateway.nginx.org
resources:
- nginxproxies
- clientsettingspolicies
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- nginxgateways/status
- clientsettingspolicies/status
verbs:
- update
- apiGroups:
Expand Down Expand Up @@ -235,6 +237,8 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
- image: nginx-gateway-fabric/nginx-plus:edge
imagePullPolicy: Always
name: nginx
Expand Down Expand Up @@ -265,6 +269,8 @@ spec:
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
terminationGracePeriodSeconds: 30
serviceAccountName: nginx-gateway
shareProcessNamespace: true
Expand All @@ -284,6 +290,8 @@ spec:
emptyDir: {}
- name: nginx-lib
emptyDir: {}
- name: nginx-includes
emptyDir: {}
---
# Source: nginx-gateway-fabric/templates/gatewayclass.yaml
apiVersion: gateway.networking.k8s.io/v1
Expand Down
8 changes: 8 additions & 0 deletions deploy/manifests/nginx-plus-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ rules:
- gateway.nginx.org
resources:
- nginxproxies
- clientsettingspolicies
verbs:
- list
- watch
- apiGroups:
- gateway.nginx.org
resources:
- nginxgateways/status
- clientsettingspolicies/status
verbs:
- update
- apiGroups:
Expand Down Expand Up @@ -231,6 +233,8 @@ spec:
mountPath: /etc/nginx/secrets
- name: nginx-run
mountPath: /var/run/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
- image: nginx-gateway-fabric/nginx-plus:edge
imagePullPolicy: Always
name: nginx
Expand Down Expand Up @@ -261,6 +265,8 @@ spec:
mountPath: /var/cache/nginx
- name: nginx-lib
mountPath: /var/lib/nginx
- name: nginx-includes
mountPath: /etc/nginx/includes
terminationGracePeriodSeconds: 30
serviceAccountName: nginx-gateway
shareProcessNamespace: true
Expand All @@ -280,6 +286,8 @@ spec:
emptyDir: {}
- name: nginx-lib
emptyDir: {}
- name: nginx-includes
emptyDir: {}
---
# Source: nginx-gateway-fabric/templates/gatewayclass.yaml
apiVersion: gateway.networking.k8s.io/v1
Expand Down
2 changes: 1 addition & 1 deletion docs/proposals/client-settings.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Enhancement Proposal-1632: Client Settings Policy

- Issue: https://github.com/nginxinc/nginx-gateway-fabric/issues/1632
- Status: Implementable
- Status: Completed

## Summary

Expand Down
3 changes: 3 additions & 0 deletions examples/client-settings-policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Client Settings Policy

This directory contains YAML files of ClientSettingsPolicies.
kate-osborn marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading