Skip to content

Commit

Permalink
feat: add new ApisixGlobalRule resource to support global rules (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlinsRan authored Jan 31, 2023
1 parent 4c0535b commit fa57ff5
Show file tree
Hide file tree
Showing 29 changed files with 1,680 additions and 3 deletions.
50 changes: 50 additions & 0 deletions docs/en/latest/concepts/apisix_global_rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: ApisixGlobalRule
keywords:
- APISIX ingress
- Apache APISIX
- ApisixGlobalRule
description: Guide to using ApisixGlobalRule custom Kubernetes resource.
---

<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

`ApisixGlobalRule` is a Kubernetes CRD resource used to create an APISIX [global-rule](https://apisix.apache.org/docs/apisix/terminology/global-rule/) object, which can apply the [plugin](https://apisix.apache.org/docs/apisix/next/terminology/plugin/) to all requests.

## Example

Enable the [limit-count](https://apisix.apache.org/docs/apisix/next/plugins/limit-count/) plugin on the APISIX, which can limit all requests.

```yaml
apiVersion: apisix.apache.org/v2
kind: ApisixGlobalRule
metadata:
name: global
spec:
plugins:
name: limit-count
enalbed: true
config:
time_window": 60,
policy: "local",
count: 2,
key: "remote_addr",
rejected_code: 503
```
37 changes: 37 additions & 0 deletions docs/en/latest/references/apisix_global_rule_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: ApisixGlobalRule/v2
keywords:
- APISIX ingress
- Apache APISIX
- ApisixGlobalRule
description: Reference for ApisixGlobalRule/v2 custom Kubernetes resource.
---
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

## Spec

,See the [definition](../concepts/apisix_global_rule.md) on GitHub.

| Field | Type | Description |
|------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------|
| plugins | array | Plugins that will be executed on the all requests. |
| plugins[].name | string | Name of the Plugin. See [Plugin hub](https://apisix.apache.org/plugins/) for a list of available Plugins. |
| plugins[].enable | boolean | When set to `true`, enables the Plugin. |
| plugins[].config | object | Configuration of the Plugin, the schema is totally same to the one in APISIX. |
32 changes: 32 additions & 0 deletions pkg/kube/apisix/apis/config/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,3 +758,35 @@ type ApisixPluginConfigList struct {
metav1.ListMeta `json:"metadata" yaml:"metadata"`
Items []ApisixPluginConfig `json:"items,omitempty" yaml:"items,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status

// ApisixGlobalRule is the Schema for the ApisixGlobalRule resource.
// An ApisixGlobalRule is used to support a group of plugin configs
type ApisixGlobalRule struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ObjectMeta `json:"metadata" yaml:"metadata"`

// Spec defines the desired state of ApisixGlobalRuleSpec.
Spec ApisixGlobalRuleSpec `json:"spec" yaml:"spec"`
Status ApisixStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// ApisixGlobalRuleSpec defines the desired state of ApisixGlobalRuleSpec.
type ApisixGlobalRuleSpec struct {
// Plugins contains a list of ApisixRoutePlugin
// +required
Plugins []ApisixRoutePlugin `json:"plugins" yaml:"plugins"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:generate=true

// ApisixGlobalRuleList contains a list of ApisixGlobalRule.
type ApisixGlobalRuleList struct {
metav1.TypeMeta `json:",inline" yaml:",inline"`
metav1.ListMeta `json:"metadata" yaml:"metadata"`
Items []ApisixGlobalRule `json:"items,omitempty" yaml:"items,omitempty"`
}
84 changes: 84 additions & 0 deletions pkg/kube/apisix/apis/config/v2/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions pkg/kube/apisix/apis/config/v2/zz_generated.register.go

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

Loading

0 comments on commit fa57ff5

Please sign in to comment.