|
95 | 95 | }) |
96 | 96 |
|
97 | 97 | 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() { |
99 | 99 | serviceTemplate := ` |
100 | 100 | apiVersion: v1 |
101 | 101 | kind: Service |
@@ -203,8 +203,78 @@ spec: |
203 | 203 | Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("%s/%s", s.Namespace(), existingProxy))) |
204 | 204 | Expect(err.Error()).To(ContainSubstring("control plane endpoints")) |
205 | 205 | Expect(err.Error()).To(ContainSubstring("inline AdminKey value")) |
| 206 | + }) |
206 | 207 |
|
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))) |
208 | 278 | }) |
209 | 279 | }) |
210 | 280 | }) |
0 commit comments