Skip to content

Commit 87433eb

Browse files
committed
fix: r
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 6da00c6 commit 87433eb

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

internal/webhook/v1/gatewayproxy_webhook.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ type gatewayProxyConfig struct {
177177
serviceKey string
178178
serviceDescription string
179179
endpoints map[string]struct{}
180-
sortedEndpoints []string
181180
}
182181

183182
func buildGatewayProxyConfig(gp *v1alpha1.GatewayProxy) gatewayProxyConfig {
@@ -207,11 +206,9 @@ func buildGatewayProxyConfig(gp *v1alpha1.GatewayProxy) gatewayProxyConfig {
207206

208207
if len(cp.Endpoints) > 0 {
209208
cfg.endpoints = make(map[string]struct{}, len(cp.Endpoints))
210-
cfg.sortedEndpoints = append([]string(nil), cp.Endpoints...)
211-
for _, endpoint := range cfg.sortedEndpoints {
209+
for _, endpoint := range cp.Endpoints {
212210
cfg.endpoints[endpoint] = struct{}{}
213211
}
214-
sort.Strings(cfg.sortedEndpoints)
215212
}
216213

217214
return cfg

test/e2e/gatewayapi/webhook.go

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ spec:
9595
})
9696

9797
Context("GatewayProxy configuration conflicts", func() {
98-
It("should reject GatewayProxy that reuses the same Service and AdminKey Secret as an existing one", func() {
98+
It("should reject GatewayProxy that reuses the same Service and AdminKey Secret as an existing one on create and update", func() {
9999
serviceTemplate := `
100100
apiVersion: v1
101101
kind: Service
@@ -203,8 +203,78 @@ spec:
203203
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s/%s", s.Namespace(), existingProxy)))
204204
Expect(err.Error()).To(ContainSubstring("control plane endpoints"))
205205
Expect(err.Error()).To(ContainSubstring("inline AdminKey value"))
206+
})
206207

207-
Expect(s.DeleteResource("GatewayProxy", existingProxy)).ShouldNot(HaveOccurred())
208+
It("should reject GatewayProxy update that creates conflict with another GatewayProxy", func() {
209+
serviceTemplate := `
210+
apiVersion: v1
211+
kind: Service
212+
metadata:
213+
name: %s
214+
spec:
215+
selector:
216+
app: dummy-control-plane
217+
ports:
218+
- name: admin
219+
port: 9180
220+
targetPort: 9180
221+
`
222+
secretTemplate := `
223+
apiVersion: v1
224+
kind: Secret
225+
metadata:
226+
name: %s
227+
type: Opaque
228+
stringData:
229+
%s: %s
230+
`
231+
gatewayProxyTemplate := `
232+
apiVersion: apisix.apache.org/v1alpha1
233+
kind: GatewayProxy
234+
metadata:
235+
name: %s
236+
spec:
237+
provider:
238+
type: ControlPlane
239+
controlPlane:
240+
service:
241+
name: %s
242+
port: 9180
243+
auth:
244+
type: AdminKey
245+
adminKey:
246+
valueFrom:
247+
secretKeyRef:
248+
name: %s
249+
key: token
250+
`
251+
252+
sharedServiceName := "gatewayproxy-update-shared-service"
253+
sharedSecretName := "gatewayproxy-update-shared-secret"
254+
uniqueServiceName := "gatewayproxy-update-unique-service"
255+
proxyA := "gatewayproxy-update-a"
256+
proxyB := "gatewayproxy-update-b"
257+
258+
Expect(s.CreateResourceFromString(fmt.Sprintf(serviceTemplate, sharedServiceName))).ShouldNot(HaveOccurred(), "creating shared Service")
259+
Expect(s.CreateResourceFromString(fmt.Sprintf(serviceTemplate, uniqueServiceName))).ShouldNot(HaveOccurred(), "creating unique Service")
260+
Expect(s.CreateResourceFromString(fmt.Sprintf(secretTemplate, sharedSecretName, "token", "value"))).ShouldNot(HaveOccurred(), "creating shared Secret")
261+
262+
err := s.CreateResourceFromString(fmt.Sprintf(gatewayProxyTemplate, proxyA, sharedServiceName, sharedSecretName))
263+
Expect(err).ShouldNot(HaveOccurred(), "creating GatewayProxy A with shared Service and Secret")
264+
265+
time.Sleep(2 * time.Second)
266+
267+
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyTemplate, proxyB, uniqueServiceName, sharedSecretName))
268+
Expect(err).ShouldNot(HaveOccurred(), "creating GatewayProxy B with unique Service but same Secret")
269+
270+
time.Sleep(2 * time.Second)
271+
272+
By("updating GatewayProxy B to use the same Service as GatewayProxy A, causing conflict")
273+
err = s.CreateResourceFromString(fmt.Sprintf(gatewayProxyTemplate, proxyB, sharedServiceName, sharedSecretName))
274+
Expect(err).Should(HaveOccurred(), "expecting conflict when updating to same Service")
275+
Expect(err.Error()).To(ContainSubstring("gateway proxy configuration conflict"))
276+
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s/%s", s.Namespace(), proxyA)))
277+
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s/%s", s.Namespace(), proxyB)))
208278
})
209279
})
210280
})

0 commit comments

Comments
 (0)