Skip to content

Commit 0ca0a72

Browse files
authored
feat: support apisix global rule (#163)
Signed-off-by: ashing <[email protected]>
1 parent f009012 commit 0ca0a72

29 files changed

+939
-165
lines changed

api/adc/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ func (g *GlobalRule) DeepCopy() GlobalRule {
103103
return GlobalRule(copied)
104104
}
105105

106+
// +k8s:deepcopy-gen=true
107+
type GlobalRuleItem struct {
108+
Metadata `json:",inline" yaml:",inline"`
109+
110+
Plugins Plugins `json:"plugins" yaml:"plugins"`
111+
}
112+
106113
type PluginMetadata Plugins
107114

108115
func (p *PluginMetadata) DeepCopy() PluginMetadata {

api/adc/zz_generated.deepcopy.go

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

api/v2/apisixroute_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ type ApisixRoutePlugin struct {
130130
// The plugin name.
131131
Name string `json:"name" yaml:"name"`
132132
// Whether this plugin is in use, default is true.
133+
// +kubebuilder:default=true
133134
Enable bool `json:"enable" yaml:"enable"`
134135
// Plugin configuration.
136+
// +kubebuilder:validation:Optional
135137
Config ApisixRoutePluginConfig `json:"config" yaml:"config"`
136138
// Plugin configuration secretRef.
139+
// +kubebuilder:validation:Optional
137140
SecretRef string `json:"secretRef" yaml:"secretRef"`
138141
}
139142

api/v2/reason.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
package v2
14+
15+
type Reason string
16+
17+
const (
18+
ReasonSyncFailed Reason = "SyncFailed"
19+
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ spec:
5555
description: Plugin configuration.
5656
type: object
5757
enable:
58+
default: true
5859
description: Whether this plugin is in use, default is true.
5960
type: boolean
6061
name:
@@ -64,10 +65,8 @@ spec:
6465
description: Plugin configuration secretRef.
6566
type: string
6667
required:
67-
- config
6868
- enable
6969
- name
70-
- secretRef
7170
type: object
7271
type: array
7372
required:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ spec:
5656
description: Plugin configuration.
5757
type: object
5858
enable:
59+
default: true
5960
description: Whether this plugin is in use, default is true.
6061
type: boolean
6162
name:
@@ -65,10 +66,8 @@ spec:
6566
description: Plugin configuration secretRef.
6667
type: string
6768
required:
68-
- config
6969
- enable
7070
- name
71-
- secretRef
7271
type: object
7372
type: array
7473
required:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ spec:
255255
description: Plugin configuration.
256256
type: object
257257
enable:
258+
default: true
258259
description: Whether this plugin is in use, default is
259260
true.
260261
type: boolean
@@ -265,10 +266,8 @@ spec:
265266
description: Plugin configuration secretRef.
266267
type: string
267268
required:
268-
- config
269269
- enable
270270
- name
271-
- secretRef
272271
type: object
273272
type: array
274273
priority:
@@ -374,6 +373,7 @@ spec:
374373
description: Plugin configuration.
375374
type: object
376375
enable:
376+
default: true
377377
description: Whether this plugin is in use, default is
378378
true.
379379
type: boolean
@@ -384,10 +384,8 @@ spec:
384384
description: Plugin configuration secretRef.
385385
type: string
386386
required:
387-
- config
388387
- enable
389388
- name
390-
- secretRef
391389
type: object
392390
type: array
393391
protocol:

config/rbac/role.yaml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,44 +54,6 @@ rules:
5454
verbs:
5555
- get
5656
- update
57-
- apiGroups:
58-
- apisix.apache.org.github.com
59-
resources:
60-
- apisixconsumers
61-
- apisixglobalrules
62-
- apisixroutes
63-
- apisixtls
64-
- apisixupstreams
65-
verbs:
66-
- create
67-
- delete
68-
- get
69-
- list
70-
- patch
71-
- update
72-
- watch
73-
- apiGroups:
74-
- apisix.apache.org.github.com
75-
resources:
76-
- apisixconsumers/finalizers
77-
- apisixglobalrules/finalizers
78-
- apisixroutes/finalizers
79-
- apisixtls/finalizers
80-
- apisixupstreams/finalizers
81-
verbs:
82-
- update
83-
- apiGroups:
84-
- apisix.apache.org.github.com
85-
resources:
86-
- apisixconsumers/status
87-
- apisixglobalrules/status
88-
- apisixroutes/status
89-
- apisixtls/status
90-
- apisixupstreams/status
91-
verbs:
92-
- get
93-
- patch
94-
- update
9557
- apiGroups:
9658
- coordination.k8s.io
9759
resources:

config/samples/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enable_http2: false # Whether to enable HTTP/2 for the serve
2525
probe_addr: ":8081" # The address the probe endpoint binds to.
2626
# The default value is ":8081".
2727

28-
secure_metrics: "" # The secure metrics configuration.
28+
secure_metrics: false # The secure metrics configuration.
2929
# The default value is "" (empty).
3030

3131
exec_adc_timeout: 15s # The timeout for the ADC to execute.

docs/crd/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,8 @@ them if they are set on the port level.
16321632
_Appears in:_
16331633
- [ApisixUpstreamSpec](#apisixupstreamspec)
16341634

1635+
1636+
16351637
#### UpstreamTimeout
16361638

16371639

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ require (
2727
go.uber.org/zap v1.27.0
2828
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
2929
golang.org/x/net v0.28.0
30-
google.golang.org/protobuf v1.34.2
3130
gopkg.in/yaml.v3 v3.0.1
3231
helm.sh/helm/v3 v3.15.4
3332
k8s.io/api v0.31.1
@@ -202,6 +201,7 @@ require (
202201
google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect
203202
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
204203
google.golang.org/grpc v1.66.2 // indirect
204+
google.golang.org/protobuf v1.34.2 // indirect
205205
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
206206
gopkg.in/fsnotify.v1 v1.4.7 // indirect
207207
gopkg.in/inf.v0 v0.9.1 // indirect

internal/controller/apisixconsumer_controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ type ApisixConsumerReconciler struct {
3232
Log logr.Logger
3333
}
3434

35-
// +kubebuilder:rbac:groups=apisix.apache.org.github.com,resources=apisixconsumers,verbs=get;list;watch;create;update;patch;delete
36-
// +kubebuilder:rbac:groups=apisix.apache.org.github.com,resources=apisixconsumers/status,verbs=get;update;patch
37-
// +kubebuilder:rbac:groups=apisix.apache.org.github.com,resources=apisixconsumers/finalizers,verbs=update
38-
3935
// Reconcile FIXME: implement the reconcile logic (For now, it dose nothing other than directly accepting)
4036
func (r *ApisixConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
4137
r.Log.Info("reconcile", "request", req.NamespacedName)

0 commit comments

Comments
 (0)