Skip to content

Commit 0725fb5

Browse files
committed
feat: Add ReferenceGrant support and refactor backend reference handling
This commit introduces support for Gateway API ReferenceGrant CRD, enabling cross-namespace references for HTTPRoutes. It refactors backend reference handling to validate Service references and check ReferenceGrants. Also includes minor code cleanups, added cluster role permissions for ReferenceGrants, and adjustments to e2e manifests.
1 parent f04b3f4 commit 0725fb5

File tree

10 files changed

+227
-130
lines changed

10 files changed

+227
-130
lines changed

api/v1alpha1/backendtrafficpolicy_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type BackendTrafficPolicy struct {
2222
metav1.TypeMeta `json:",inline"`
2323
metav1.ObjectMeta `json:"metadata,omitempty"`
2424

25-
// BackendTrafficPolicySpec defines traffic handling policies applied to backend services,
26-
// such as load balancing strategy, connection settings, and failover behavior.
25+
// BackendTrafficPolicySpec defines traffic handling policies applied to backend services,
26+
// such as load balancing strategy, connection settings, and failover behavior.
2727
Spec BackendTrafficPolicySpec `json:"spec,omitempty"`
2828
Status PolicyStatus `json:"status,omitempty"`
2929
}

api/v1alpha1/consumer_types.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ type Consumer struct {
2323
metav1.TypeMeta `json:",inline"`
2424
metav1.ObjectMeta `json:"metadata,omitempty"`
2525

26-
// ConsumerSpec defines the configuration for a consumer, including consumer name,
26+
// ConsumerSpec defines the configuration for a consumer, including consumer name,
2727
// authentication credentials, and plugin settings.
2828
Spec ConsumerSpec `json:"spec,omitempty"`
2929
Status Status `json:"status,omitempty"`
3030
}
3131

3232
type ConsumerSpec struct {
3333
// GatewayRef specifies the gateway details.
34-
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`
34+
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`
3535
// Credentials specifies the credential details of a consumer.
3636
Credentials []Credential `json:"credentials,omitempty"`
3737
// Plugins define the plugins associated with a consumer.
38-
Plugins []Plugin `json:"plugins,omitempty"`
38+
Plugins []Plugin `json:"plugins,omitempty"`
3939
}
4040

4141
type GatewayRef struct {
@@ -48,7 +48,7 @@ type GatewayRef struct {
4848
Kind *string `json:"kind,omitempty"`
4949
// Group is the API group the resource belongs to. Default is `gateway.networking.k8s.io`.
5050
// +kubebuilder:default=gateway.networking.k8s.io
51-
Group *string `json:"group,omitempty"`
51+
Group *string `json:"group,omitempty"`
5252
// Namespace is namespace of the resource.
5353
Namespace *string `json:"namespace,omitempty"`
5454
}
@@ -58,18 +58,18 @@ type Credential struct {
5858
// +kubebuilder:validation:Enum=jwt-auth;basic-auth;key-auth;hmac-auth;
5959
// Type specifies the type of authentication to configure credentials for.
6060
// Can be one of `jwt-auth`, `basic-auth`, `key-auth`, or `hmac-auth`.
61-
Type string `json:"type"`
61+
Type string `json:"type"`
6262
// Config specifies the credential details for authentication.
63-
Config apiextensionsv1.JSON `json:"config,omitempty"`
63+
Config apiextensionsv1.JSON `json:"config,omitempty"`
6464
// SecretRef references to the Secret that contains the credentials.
65-
SecretRef *SecretReference `json:"secretRef,omitempty"`
65+
SecretRef *SecretReference `json:"secretRef,omitempty"`
6666
// Name is the name of the credential.
67-
Name string `json:"name,omitempty"`
67+
Name string `json:"name,omitempty"`
6868
}
6969

7070
type SecretReference struct {
7171
// Name is the name of the secret.
72-
Name string `json:"name"`
72+
Name string `json:"name"`
7373
// Namespace is the namespace of the secret.
7474
Namespace *string `json:"namespace,omitempty"`
7575
}

api/v1alpha1/gatewayproxy_types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ type GatewayProxySpec struct {
2727

2828
// PublishService specifies the LoadBalancer-type Service whose external address the controller uses to
2929
// update the status of Ingress resources.
30-
PublishService string `json:"publishService,omitempty"`
30+
PublishService string `json:"publishService,omitempty"`
3131
// StatusAddress specifies the external IP addresses that the controller uses to populate the status field
3232
// of GatewayProxy or Ingress resources for developers to access.
33-
StatusAddress []string `json:"statusAddress,omitempty"`
33+
StatusAddress []string `json:"statusAddress,omitempty"`
3434
// Provider configures the provider details.
35-
Provider *GatewayProxyProvider `json:"provider,omitempty"`
35+
Provider *GatewayProxyProvider `json:"provider,omitempty"`
3636
// Plugins configure global plugins.
37-
Plugins []GatewayProxyPlugin `json:"plugins,omitempty"`
37+
Plugins []GatewayProxyPlugin `json:"plugins,omitempty"`
3838
// PluginMetadata configures common configurations shared by all plugin instances of the same name.
3939
PluginMetadata map[string]apiextensionsv1.JSON `json:"pluginMetadata,omitempty"`
4040
}
@@ -132,8 +132,8 @@ type GatewayProxy struct {
132132
metav1.TypeMeta `json:",inline"`
133133
metav1.ObjectMeta `json:"metadata,omitempty"`
134134

135-
// GatewayProxySpec defines the desired state and configuration of a GatewayProxy,
136-
// including networking settings, global plugins, and plugin metadata.
135+
// GatewayProxySpec defines the desired state and configuration of a GatewayProxy,
136+
// including networking settings, global plugins, and plugin metadata.
137137
Spec GatewayProxySpec `json:"spec,omitempty"`
138138
}
139139

@@ -148,11 +148,11 @@ type GatewayProxyList struct {
148148
// GatewayProxyPlugin contains plugin configurations.
149149
type GatewayProxyPlugin struct {
150150
// Name is the name of the plugin.
151-
Name string `json:"name,omitempty"`
152-
// Enabled defines whether the plugin is enabled.
153-
Enabled bool `json:"enabled,omitempty"`
151+
Name string `json:"name,omitempty"`
152+
// Enabled defines whether the plugin is enabled.
153+
Enabled bool `json:"enabled,omitempty"`
154154
// Config defines the plugin's configuration details.
155-
Config apiextensionsv1.JSON `json:"config,omitempty"`
155+
Config apiextensionsv1.JSON `json:"config,omitempty"`
156156
}
157157

158158
func init() {

api/v1alpha1/httproutepolicy_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ type HTTPRoutePolicySpec struct {
2525
// +kubebuilder:validation:MaxItems=16
2626
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"`
2727
// Priority sets the priority for route. A higher value sets a higher priority in route matching.
28-
Priority *int64 `json:"priority,omitempty" yaml:"priority,omitempty"`
28+
Priority *int64 `json:"priority,omitempty" yaml:"priority,omitempty"`
2929
// Vars sets the request matching conditions.
30-
Vars []apiextensionsv1.JSON `json:"vars,omitempty" yaml:"vars,omitempty"`
30+
Vars []apiextensionsv1.JSON `json:"vars,omitempty" yaml:"vars,omitempty"`
3131
}
3232

3333
// +kubebuilder:object:root=true

charts/templates/cluster_role.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ rules:
170170
- get
171171
- list
172172
- watch
173+
- apiGroups:
174+
- gateway.networking.k8s.io
175+
resources:
176+
- referencegrants
177+
verbs:
178+
- get
179+
- list
180+
- watch
181+
- apiGroups:
182+
- gateway.networking.k8s.io
183+
resources:
184+
- referencegrants/status
185+
verbs:
186+
- get
173187
- apiGroups:
174188
- networking.k8s.io
175189
resources:

0 commit comments

Comments
 (0)