Skip to content

Commit 266d0da

Browse files
committed
allow namespace-scoped parametersRef
This patch adds a namespace field to the parametersRef reference. This allows cluster-scoped GatewayClass resource to reference a namespaced-scoped parameters resource. This is in-line with upstream KEP 2365: https://github.com/kubernetes/enhancements/blob/master/keps/prod-readiness/sig-network/2365.yaml Why is it done the way it is done? - Namespace field was not added to LocalObjectReference because that type is referenced in a lot of places. We don't want to add in an optional namespace field in all these places and increase security issues with cross-namespace references. - ObjectReference was not used because upstream discourages its use: https://pkg.go.dev/k8s.io/api/core/v1#ObjectReference. Instead, a new type was introduced as per upstream's guidance. - A new "Cluster" field was added as advised upstream: kubernetes/enhancements#2366 (comment)
1 parent def9c89 commit 266d0da

File tree

6 files changed

+272
-41
lines changed

6 files changed

+272
-41
lines changed

apis/v1alpha1/gatewayclass_types.go

+45-6
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,59 @@ type GatewayClassSpec struct {
6262
// +kubebuilder:validation:MaxLength=253
6363
Controller string `json:"controller"`
6464

65-
// ParametersRef is a controller-specific resource containing the
66-
// configuration parameters corresponding to this class. This is optional if
67-
// the controller does not require any additional configuration.
65+
// ParametersRef is a reference to a resource that contains the configuration
66+
// parameters corresponding to the GatewayClass. This is optional if the
67+
// controller does not require any additional configuration.
6868
//
69-
// Parameters resources are implementation specific custom resources. These
70-
// resources must be cluster-scoped.
69+
// ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap,
70+
// or an implementation-specific custom resource. The resource can be
71+
// cluster-scoped or namespace-scoped.
7172
//
7273
// If the referent cannot be found, the GatewayClass's "InvalidParameters"
7374
// status condition will be true.
7475
//
7576
// Support: Custom
7677
//
7778
// +optional
78-
ParametersRef *LocalObjectReference `json:"parametersRef,omitempty"`
79+
ParametersRef *ParametersReference `json:"parametersRef,omitempty"`
80+
}
81+
82+
// ParametersReference identifies an API object containing controller-specific
83+
// configuration resource within the cluster.
84+
type ParametersReference struct {
85+
// Group is the group of the referent.
86+
//
87+
// +kubebuilder:validation:MinLength=1
88+
// +kubebuilder:validation:MaxLength=253
89+
Group string `json:"group"`
90+
91+
// Kind is kind of the referent.
92+
//
93+
// +kubebuilder:validation:MinLength=1
94+
// +kubebuilder:validation:MaxLength=253
95+
Kind string `json:"kind"`
96+
97+
// Name is the name of the referent.
98+
//
99+
// +kubebuilder:validation:MinLength=1
100+
// +kubebuilder:validation:MaxLength=253
101+
Name string `json:"name"`
102+
103+
// Scope represents if the referent is a Cluster or Namespace scoped resource.
104+
// This may be set to "Cluster" or "Namespace".
105+
// +kubebuilder:validation:Enum=Cluster;Namespace
106+
// +kubebuilder:default=Cluster
107+
// +optional
108+
Scope string `json:"scope,omitempty"`
109+
110+
// Namespace is the namespace of the referent.
111+
// This field is required when scope is set to "Namespace" and ignored when
112+
// scope is set to "Cluster".
113+
//
114+
// +kubebuilder:validation:MinLength=1
115+
// +kubebuilder:validation:MaxLength=253
116+
// +optional
117+
Namespace string `json:"namespace,omitempty"`
79118
}
80119

81120
// GatewayClassConditionType is the type of status conditions. This

apis/v1alpha1/local_object_reference_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19-
// LocalObjectReference identifies an API object within a known namespace.
19+
// LocalObjectReference identifies an API object within the namespace of the
20+
// referrer.
2021
type LocalObjectReference struct {
2122
// Group is the group of the referent.
2223
//

apis/v1alpha1/zz_generated.deepcopy.go

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/networking.x-k8s.io_gatewayclasses.yaml

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs-src/spec.md

+98-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)