Skip to content

Commit ae9fbc3

Browse files
committed
add kubebuilder annotations for upstream type and hashon validation
1 parent 2d8ddba commit ae9fbc3

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

api/v2/apisixupstream_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ type LoadBalancer struct {
171171
// Type specifies the load balancing algorithms.
172172
// Default is `roundrobin`.
173173
// Can be `roundrobin`, `chash`, `ewma`, or `least_conn`.
174+
// +kubebuilder:validation:Enum=roundrobin;chash;ewma;least_conn;
175+
// +kubebuilder:default=roundrobin
176+
// +kubebuilder:validation:Required
174177
Type string `json:"type" yaml:"type"`
175178
// HashOn specified the type of field used for hashing, required when type is `chash`.
176179
// Default is `vars`. Can be `vars`, `header`, `cookie`, `consumer`, or `vars_combinations`.
180+
// +kubebuilder:validation:Enum=vars;header;cookie;consumer;vars_combinations;
181+
// +kubebuilder:default=vars
177182
HashOn string `json:"hashOn,omitempty" yaml:"hashOn,omitempty"`
178183
// Key is used with HashOn, generally required when type is `chash`.
179184
// When HashOn is `header` or `cookie`, specifies the name of the header or cookie.

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,23 +264,36 @@ spec:
264264
The default strategy is round-robin.
265265
properties:
266266
hashOn:
267+
default: vars
267268
description: |-
268269
HashOn specified the type of field used for hashing, required when type is `chash`.
269270
Default is `vars`. Can be `vars`, `header`, `cookie`, `consumer`, or `vars_combinations`.
271+
enum:
272+
- vars
273+
- header
274+
- cookie
275+
- consumer
276+
- vars_combinations
270277
type: string
271278
key:
272279
description: |-
273-
Key is used with HashOn, generally required when Type is `chash`.
280+
Key is used with HashOn, generally required when type is `chash`.
274281
When HashOn is `header` or `cookie`, specifies the name of the header or cookie.
275282
When HashOn is `consumer`, key is not required, as the consumer name is used automatically.
276283
When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of
277284
[built-in variables](/enterprise/reference/built-in-variables).
278285
type: string
279286
type:
287+
default: roundrobin
280288
description: |-
281289
Type specifies the load balancing algorithms.
282290
Default is `roundrobin`.
283291
Can be `roundrobin`, `chash`, `ewma`, or `least_conn`.
292+
enum:
293+
- roundrobin
294+
- chash
295+
- ewma
296+
- least_conn
284297
type: string
285298
required:
286299
- type
@@ -498,23 +511,36 @@ spec:
498511
The default strategy is round-robin.
499512
properties:
500513
hashOn:
514+
default: vars
501515
description: |-
502516
HashOn specified the type of field used for hashing, required when type is `chash`.
503517
Default is `vars`. Can be `vars`, `header`, `cookie`, `consumer`, or `vars_combinations`.
518+
enum:
519+
- vars
520+
- header
521+
- cookie
522+
- consumer
523+
- vars_combinations
504524
type: string
505525
key:
506526
description: |-
507-
Key is used with HashOn, generally required when Type is `chash`.
527+
Key is used with HashOn, generally required when type is `chash`.
508528
When HashOn is `header` or `cookie`, specifies the name of the header or cookie.
509529
When HashOn is `consumer`, key is not required, as the consumer name is used automatically.
510530
When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of
511531
[built-in variables](/enterprise/reference/built-in-variables).
512532
type: string
513533
type:
534+
default: roundrobin
514535
description: |-
515536
Type specifies the load balancing algorithms.
516537
Default is `roundrobin`.
517538
Can be `roundrobin`, `chash`, `ewma`, or `least_conn`.
539+
enum:
540+
- roundrobin
541+
- chash
542+
- ewma
543+
- least_conn
518544
type: string
519545
required:
520546
- type

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spec:
6262
type: string
6363
key:
6464
description: |-
65-
Key is used with HashOn, generally required when Type is `chash`.
65+
Key is used with HashOn, generally required when type is `chash`.
6666
When HashOn is `header` or `cookie`, specifies the name of the header or cookie.
6767
When HashOn is `consumer`, key is not required, as the consumer name is used automatically.
6868
When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of

docs/crd/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ LoadBalancer describes the load balancing parameters.
366366
| --- | --- |
367367
| `type` _string_ | Type specifies the load balancing algorithms. Default is `roundrobin`. Can be `roundrobin`, `chash`, `ewma`, or `least_conn`. |
368368
| `hashOn` _string_ | HashOn specified the type of field used for hashing, required when type is `chash`. Default is `vars`. Can be `vars`, `header`, `cookie`, `consumer`, or `vars_combinations`. |
369-
| `key` _string_ | Key is used with HashOn, generally required when Type is `chash`. When HashOn is `header` or `cookie`, specifies the name of the header or cookie. When HashOn is `consumer`, key is not required, as the consumer name is used automatically. When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of [built-in variables](/enterprise/reference/built-in-variables). |
369+
| `key` _string_ | Key is used with HashOn, generally required when type is `chash`. When HashOn is `header` or `cookie`, specifies the name of the header or cookie. When HashOn is `consumer`, key is not required, as the consumer name is used automatically. When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of [built-in variables](/enterprise/reference/built-in-variables). |
370370

371371

372372
_Appears in:_
@@ -1473,7 +1473,7 @@ LoadBalancer defines the load balancing strategy for distributing traffic across
14731473
| --- | --- |
14741474
| `type` _string_ | Type specifies the load balancing algorithms. Default is `roundrobin`. Can be `roundrobin`, `chash`, `ewma`, or `least_conn`. |
14751475
| `hashOn` _string_ | HashOn specified the type of field used for hashing, required when type is `chash`. Default is `vars`. Can be `vars`, `header`, `cookie`, `consumer`, or `vars_combinations`. |
1476-
| `key` _string_ | Key is used with HashOn, generally required when Type is `chash`. When HashOn is `header` or `cookie`, specifies the name of the header or cookie. When HashOn is `consumer`, key is not required, as the consumer name is used automatically. When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of [built-in variables](/enterprise/reference/built-in-variables). |
1476+
| `key` _string_ | Key is used with HashOn, generally required when type is `chash`. When HashOn is `header` or `cookie`, specifies the name of the header or cookie. When HashOn is `consumer`, key is not required, as the consumer name is used automatically. When HashOn is `vars` or `vars_combinations`, key refers to one or a combination of [built-in variables](/enterprise/reference/built-in-variables). |
14771477

14781478

14791479
_Appears in:_

0 commit comments

Comments
 (0)