Skip to content

Commit 17b3454

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent ab71737 commit 17b3454

File tree

8 files changed

+233
-33
lines changed

8 files changed

+233
-33
lines changed

api/v2/apisixroute_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ type ApisixRoutePlugin struct {
133133
// +kubebuilder:default=true
134134
Enable bool `json:"enable" yaml:"enable"`
135135
// Plugin configuration.
136+
// +kubebuilder:validation:Optional
136137
Config ApisixRoutePluginConfig `json:"config" yaml:"config"`
137138
// Plugin configuration secretRef.
139+
// +kubebuilder:validation:Optional
138140
SecretRef string `json:"secretRef" yaml:"secretRef"`
139141
}
140142

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ spec:
6565
description: Plugin configuration secretRef.
6666
type: string
6767
required:
68-
- config
6968
- enable
7069
- name
71-
- secretRef
7270
type: object
7371
type: array
7472
required:

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ spec:
6666
description: Plugin configuration secretRef.
6767
type: string
6868
required:
69-
- config
7069
- enable
7170
- name
72-
- secretRef
7371
type: object
7472
type: array
7573
required:

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,8 @@ spec:
266266
description: Plugin configuration secretRef.
267267
type: string
268268
required:
269-
- config
270269
- enable
271270
- name
272-
- secretRef
273271
type: object
274272
type: array
275273
priority:
@@ -386,10 +384,8 @@ spec:
386384
description: Plugin configuration secretRef.
387385
type: string
388386
required:
389-
- config
390387
- enable
391388
- name
392-
- secretRef
393389
type: object
394390
type: array
395391
protocol:

config/samples/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
log_level: "info" # The log level of the APISIX Ingress Controller.
1+
log_level: "debug" # The log level of the APISIX Ingress Controller.
22
# the default value is "info".
33

44
controller_name: apisix.apache.org/apisix-ingress-controller # The controller name of the APISIX Ingress Controller,
@@ -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.

internal/manager/controllers.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,12 @@ func setupControllers(ctx context.Context, mgr manager.Manager, pro provider.Pro
120120
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("IngressClass"),
121121
Provider: pro,
122122
},
123-
&controller.ApisixConsumerReconciler{
124-
Client: mgr.GetClient(),
125-
Scheme: mgr.GetScheme(),
126-
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("ApisixConsumer"),
127-
},
128123
&controller.ApisixGlobalRuleReconciler{
129-
Client: mgr.GetClient(),
130-
Scheme: mgr.GetScheme(),
131-
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("ApisixGlobalRule"),
132-
},
133-
&controller.ApisixRouteReconciler{
134-
Client: mgr.GetClient(),
135-
Scheme: mgr.GetScheme(),
136-
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("ApisixRoute"),
137-
},
138-
&controller.ApisixTlsReconciler{
139-
Client: mgr.GetClient(),
140-
Scheme: mgr.GetScheme(),
141-
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("ApisixTls"),
142-
},
143-
&controller.ApisixUpstreamReconciler{
144-
Client: mgr.GetClient(),
145-
Scheme: mgr.GetScheme(),
146-
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("ApisixUpstream"),
124+
Client: mgr.GetClient(),
125+
Scheme: mgr.GetScheme(),
126+
Log: ctrl.LoggerFrom(ctx).WithName("controllers").WithName("ApisixGlobalRule"),
127+
Provider: pro,
128+
Updater: updater,
147129
},
148130
}, nil
149131
}

internal/provider/adc/adc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
155155
SSLs: result.SSL,
156156
Consumers: result.Consumers,
157157
}
158+
log.Debugw("update resources", zap.Any("resources", resources))
158159

159160
for _, config := range configs {
160161
if err := d.store.Insert(config.Name, resourceTypes, resources, label.GenLabel(obj)); err != nil {

test/e2e/ingress/globalrule.go

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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 ingress
14+
15+
import (
16+
"fmt"
17+
"net/http"
18+
"time"
19+
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
23+
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
24+
)
25+
26+
var _ = Describe("Test GlobalRule", func() {
27+
s := scaffold.NewScaffold(&scaffold.Options{
28+
ControllerName: "apisix.apache.org/apisix-ingress-controller",
29+
})
30+
31+
var gatewayProxyYaml = `
32+
apiVersion: apisix.apache.org/v1alpha1
33+
kind: GatewayProxy
34+
metadata:
35+
name: apisix-proxy-config
36+
namespace: default
37+
spec:
38+
provider:
39+
type: ControlPlane
40+
controlPlane:
41+
endpoints:
42+
- %s
43+
auth:
44+
type: AdminKey
45+
adminKey:
46+
value: "%s"
47+
`
48+
49+
var ingressClassYaml = `
50+
apiVersion: networking.k8s.io/v1
51+
kind: IngressClass
52+
metadata:
53+
name: apisix
54+
spec:
55+
controller: "apisix.apache.org/apisix-ingress-controller"
56+
parameters:
57+
apiGroup: "apisix.apache.org"
58+
kind: "GatewayProxy"
59+
name: "apisix-proxy-config"
60+
namespace: "default"
61+
scope: "Namespace"
62+
`
63+
64+
var ingressYaml = `
65+
apiVersion: networking.k8s.io/v1
66+
kind: Ingress
67+
metadata:
68+
name: test-ingress
69+
spec:
70+
ingressClassName: apisix
71+
rules:
72+
- host: globalrule.example.com
73+
http:
74+
paths:
75+
- path: /
76+
pathType: Prefix
77+
backend:
78+
service:
79+
name: httpbin-service-e2e-test
80+
port:
81+
number: 80
82+
`
83+
84+
Context("ApisixGlobalRule Basic Operations", func() {
85+
BeforeEach(func() {
86+
By("create GatewayProxy")
87+
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey())
88+
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
89+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
90+
time.Sleep(5 * time.Second)
91+
92+
By("create IngressClass")
93+
err = s.CreateResourceFromStringWithNamespace(ingressClassYaml, "")
94+
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
95+
time.Sleep(5 * time.Second)
96+
97+
By("create Ingress")
98+
err = s.CreateResourceFromString(ingressYaml)
99+
Expect(err).NotTo(HaveOccurred(), "creating Ingress")
100+
time.Sleep(5 * time.Second)
101+
102+
By("verify Ingress works")
103+
Eventually(func() int {
104+
return s.NewAPISIXClient().
105+
GET("/get").
106+
WithHost("globalrule.example.com").
107+
Expect().Raw().StatusCode
108+
}).WithTimeout(8 * time.Second).ProbeEvery(time.Second).
109+
Should(Equal(http.StatusOK))
110+
})
111+
112+
FIt("Test GlobalRule with response-rewrite plugin", func() {
113+
globalRuleYaml := `
114+
apiVersion: apisix.apache.org/v2
115+
kind: ApisixGlobalRule
116+
metadata:
117+
name: test-global-rule-response-rewrite
118+
spec:
119+
ingressClassName: apisix
120+
plugins:
121+
- name: response-rewrite
122+
enable: true
123+
config:
124+
headers:
125+
X-Global-Rule: "test-response-rewrite"
126+
X-Global-Test: "enabled"
127+
`
128+
129+
By("create ApisixGlobalRule with response-rewrite plugin")
130+
err := s.CreateResourceFromString(globalRuleYaml)
131+
Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule")
132+
time.Sleep(5 * time.Second)
133+
134+
By("verify global rule is applied - response should have custom headers")
135+
resp := s.NewAPISIXClient().
136+
GET("/get").
137+
WithHost("globalrule.example.com").
138+
Expect().
139+
Status(http.StatusOK)
140+
resp.Header("X-Global-Rule").IsEqual("test-response-rewrite")
141+
resp.Header("X-Global-Test").IsEqual("enabled")
142+
143+
By("delete ApisixGlobalRule")
144+
err = s.DeleteResource("ApisixGlobalRule", "test-global-rule-response-rewrite")
145+
Expect(err).NotTo(HaveOccurred(), "deleting ApisixGlobalRule")
146+
time.Sleep(5 * time.Second)
147+
148+
By("verify global rule is removed - response should not have custom headers")
149+
resp = s.NewAPISIXClient().
150+
GET("/get").
151+
WithHost("globalrule.example.com").
152+
Expect().
153+
Status(http.StatusOK)
154+
resp.Header("X-Global-Rule").IsEmpty()
155+
resp.Header("X-Global-Test").IsEmpty()
156+
})
157+
158+
It("Test GlobalRule update", func() {
159+
globalRuleYaml := `
160+
apiVersion: apisix.apache.org/v2
161+
kind: ApisixGlobalRule
162+
metadata:
163+
name: test-global-rule-update
164+
spec:
165+
ingressClassName: apisix
166+
plugins:
167+
- name: response-rewrite
168+
enable: true
169+
config:
170+
headers:
171+
X-Update-Test: "version1"
172+
`
173+
174+
updatedGlobalRuleYaml := `
175+
apiVersion: apisix.apache.org/v2
176+
kind: ApisixGlobalRule
177+
metadata:
178+
name: test-global-rule-update
179+
spec:
180+
ingressClassName: apisix
181+
plugins:
182+
- name: response-rewrite
183+
enable: true
184+
config:
185+
headers:
186+
X-Update-Test: "version2"
187+
X-New-Header: "added"
188+
`
189+
190+
By("create initial ApisixGlobalRule")
191+
err := s.CreateResourceFromString(globalRuleYaml)
192+
Expect(err).NotTo(HaveOccurred(), "creating ApisixGlobalRule")
193+
time.Sleep(5 * time.Second)
194+
195+
By("verify initial configuration")
196+
resp := s.NewAPISIXClient().
197+
GET("/get").
198+
WithHost("globalrule.example.com").
199+
Expect().
200+
Status(http.StatusOK)
201+
resp.Header("X-Update-Test").IsEqual("version1")
202+
resp.Header("X-New-Header").IsEmpty()
203+
204+
By("update ApisixGlobalRule")
205+
err = s.CreateResourceFromString(updatedGlobalRuleYaml)
206+
Expect(err).NotTo(HaveOccurred(), "updating ApisixGlobalRule")
207+
time.Sleep(5 * time.Second)
208+
209+
By("verify updated configuration")
210+
resp = s.NewAPISIXClient().
211+
GET("/get").
212+
WithHost("globalrule.example.com").
213+
Expect().
214+
Status(http.StatusOK)
215+
resp.Header("X-Update-Test").IsEqual("version2")
216+
resp.Header("X-New-Header").IsEqual("added")
217+
218+
By("delete ApisixGlobalRule")
219+
err = s.DeleteResource("ApisixGlobalRule", "test-global-rule-update")
220+
Expect(err).NotTo(HaveOccurred(), "deleting ApisixGlobalRule")
221+
})
222+
})
223+
})

0 commit comments

Comments
 (0)