Skip to content

Commit b03aa71

Browse files
authored
fix: unable to install consumer crd (#79)
1 parent ab0a67d commit b03aa71

File tree

6 files changed

+71
-14
lines changed

6 files changed

+71
-14
lines changed

api/v1alpha1/consumer_types.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ type Consumer struct {
1616
}
1717

1818
type ConsumerSpec struct {
19-
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`
20-
Credentials []CredentialSpec `json:"credentials,omitempty"`
19+
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`
20+
Credentials []Credential `json:"credentials,omitempty"`
21+
Plugins []Plugin `json:"plugins,omitempty"`
2122
}
2223

2324
type GatewayRef struct {
@@ -27,8 +28,8 @@ type GatewayRef struct {
2728
Namespace *string `json:"namespace,omitempty"`
2829
}
2930

30-
// +kubebuilder:validation:XValidation:rule="has(self.config) != has(self.secretRef)"
31-
type CredentialSpec struct {
31+
type Credential struct {
32+
// +kubebuilder:validation:Required
3233
// +kubebuilder:validation:Enum=jwt-auth;basic-auth;key-auth;hmac-auth;
3334
Type string `json:"type"`
3435
Config apiextensionsv1.JSON `json:"config,omitempty"`
@@ -37,8 +38,8 @@ type CredentialSpec struct {
3738
}
3839

3940
type SecretReference struct {
40-
Name string `json:"name"`
41-
Namespace string `json:"namespace,omitempty"`
41+
Name string `json:"name"`
42+
Namespace *string `json:"namespace,omitempty"`
4243
}
4344

4445
type Status struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/gateway.apisix.io_consumers.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ spec:
6363
required:
6464
- type
6565
type: object
66-
x-kubernetes-validations:
67-
- rule: has(self.config) != has(self.secretRef)
6866
type: array
6967
gatewayRef:
7068
properties:
@@ -77,6 +75,20 @@ spec:
7775
namespace:
7876
type: string
7977
type: object
78+
plugins:
79+
items:
80+
properties:
81+
config:
82+
description: Plugin configuration.
83+
x-kubernetes-preserve-unknown-fields: true
84+
name:
85+
description: The plugin name.
86+
type: string
87+
required:
88+
- config
89+
- name
90+
type: object
91+
type: array
8092
type: object
8193
status:
8294
properties:

config/crd/kustomization.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
resources:
55
- bases/gateway.apisix.io_pluginconfigs.yaml
66
- bases/gateway.apisix.io_gatewayproxies.yaml
7+
- bases/gateway.apisix.io_consumers.yaml
78
# +kubebuilder:scaffold:crdkustomizeresource
89

910
patches:
11+
- path: patches/consumer_credential_oneof.yaml
12+
target:
13+
kind: CustomResourceDefinition
14+
name: consumers.gateway.apisix.io
15+
group: apiextensions.k8s.io
16+
version: v1
17+
1018
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1119
# patches here are for enabling the conversion webhook for each CRD
1220
#- path: patches/webhook_in_gatewayproxies.yaml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- op: add
2+
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/credentials/items/oneOf
3+
value:
4+
- required: [ config ]
5+
- required: [ secretRef ]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: gateway.apisix.io/v1alpha1
2+
kind: Consumer
3+
metadata:
4+
name: consumer-sample
5+
spec:
6+
credentials:
7+
- type: basic-auth
8+
name: basic-auth-sample
9+
secretRef:
10+
name: basic-auth-sample
11+
namespace: default
12+
- type: key-auth
13+
name: key-auth-sample
14+
config:
15+
key: sample-key
16+
plugins:
17+
- name: key-auth
18+
config:
19+
key: sample-key

0 commit comments

Comments
 (0)