Skip to content

Commit a77a861

Browse files
ronethingAlinsRan
andauthored
fix(gatewayproxy): add stricter validation rules for provider (#2602) (#307)
(cherry picked from commit 3c808e226a33c4355f5e254c10fe61b85c331f2f) Co-authored-by: AlinsRan <[email protected]>
1 parent 3e33d26 commit a77a861

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

api/v1alpha1/gatewayproxy_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ type GatewayProxySpec struct {
3434
// of GatewayProxy or Ingress resources for developers to access.
3535
StatusAddress []string `json:"statusAddress,omitempty"`
3636
// Provider configures the provider details.
37-
Provider *GatewayProxyProvider `json:"provider,omitempty"`
37+
//
38+
// +kubebuilder:validation:required
39+
Provider *GatewayProxyProvider `json:"provider"`
3840
// Plugins configure global plugins.
3941
Plugins []GatewayProxyPlugin `json:"plugins,omitempty"`
4042
// PluginMetadata configures common configuration shared by all plugin instances of the same name.
@@ -83,6 +85,7 @@ type SecretKeySelector struct {
8385
}
8486

8587
// AdminKeyAuth defines the admin key authentication configuration.
88+
// +kubebuilder:validation:XValidation:rule="has(self.value) != has(self.valueFrom)",message="exactly one of value or valueFrom must be specified"
8689
type AdminKeyAuth struct {
8790
// Value sets the admin key value explicitly (not recommended for production).
8891
// +optional
@@ -101,6 +104,8 @@ type AdminKeyValueFrom struct {
101104
}
102105

103106
// ControlPlaneAuth defines the authentication configuration for control plane.
107+
//
108+
// +kubebuilder:validation:XValidation:rule="self.type == 'AdminKey' ? has(self.adminKey) : true",message="adminKey must be specified when type is AdminKey"
104109
type ControlPlaneAuth struct {
105110
// Type specifies the type of authentication.
106111
// Can only be `AdminKey`.

config/crd/bases/apisix.apache.org_gatewayproxies.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ spec:
103103
type: object
104104
type: object
105105
type: object
106+
x-kubernetes-validations:
107+
- message: exactly one of value or valueFrom must be specified
108+
rule: has(self.value) != has(self.valueFrom)
106109
type:
107110
description: |-
108111
Type specifies the type of authentication.
@@ -113,6 +116,10 @@ spec:
113116
required:
114117
- type
115118
type: object
119+
x-kubernetes-validations:
120+
- message: adminKey must be specified when type is AdminKey
121+
rule: 'self.type == ''AdminKey'' ? has(self.adminKey) :
122+
true'
116123
endpoints:
117124
description: Endpoints specifies the list of control plane
118125
endpoints.
@@ -168,6 +175,8 @@ spec:
168175
items:
169176
type: string
170177
type: array
178+
required:
179+
- provider
171180
type: object
172181
type: object
173182
served: true

0 commit comments

Comments
 (0)