Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions api/v1alpha1/consumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ type Consumer struct {
}

type ConsumerSpec struct {
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`
Credentials []CredentialSpec `json:"credentials,omitempty"`
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`
Credentials []Credential `json:"credentials,omitempty"`
Plugins []Plugin `json:"plugins,omitempty"`
}

type GatewayRef struct {
Expand All @@ -27,8 +28,8 @@ type GatewayRef struct {
Namespace *string `json:"namespace,omitempty"`
}

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

type SecretReference struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name"`
Namespace *string `json:"namespace,omitempty"`
}

type Status struct {
Expand Down
24 changes: 18 additions & 6 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions config/crd/bases/gateway.apisix.io_consumers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ spec:
required:
- type
type: object
x-kubernetes-validations:
- rule: has(self.config) != has(self.secretRef)
type: array
gatewayRef:
properties:
Expand All @@ -77,6 +75,20 @@ spec:
namespace:
type: string
type: object
plugins:
items:
properties:
config:
description: Plugin configuration.
x-kubernetes-preserve-unknown-fields: true
name:
description: The plugin name.
type: string
required:
- config
- name
type: object
type: array
type: object
status:
properties:
Expand Down
8 changes: 8 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
resources:
- bases/gateway.apisix.io_pluginconfigs.yaml
- bases/gateway.apisix.io_gatewayproxies.yaml
- bases/gateway.apisix.io_consumers.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patches:
- path: patches/consumer_credential_oneof.yaml
target:
kind: CustomResourceDefinition
name: consumers.gateway.apisix.io
group: apiextensions.k8s.io
version: v1

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- path: patches/webhook_in_gatewayproxies.yaml
Expand Down
5 changes: 5 additions & 0 deletions config/crd/patches/consumer_credential_oneof.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- op: add
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/credentials/items/oneOf
value:
- required: [ config ]
- required: [ secretRef ]
19 changes: 19 additions & 0 deletions config/samples/gateway.apisix.io_v1alpha1_consumer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: gateway.apisix.io/v1alpha1
kind: Consumer
metadata:
name: consumer-sample
spec:
credentials:
- type: basic-auth
name: basic-auth-sample
secretRef:
name: basic-auth-sample
namespace: default
- type: key-auth
name: key-auth-sample
config:
key: sample-key
plugins:
- name: key-auth
config:
key: sample-key
Loading