Skip to content

Commit 3745fbd

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

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

internal/webhook/v1/gatewayproxy_webhook.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (v *GatewayProxyCustomValidator) validateGatewayProxyConflict(ctx context.C
153153
gp.GetNamespace(), gp.GetName(),
154154
other.GetNamespace(), other.GetName(),
155155
current.serviceDescription,
156-
current.adminKeyDescription,
156+
current.adminKeyDetail(),
157157
)
158158
}
159159
if len(current.endpoints) > 0 && len(otherConfig.endpoints) > 0 {
@@ -162,7 +162,7 @@ func (v *GatewayProxyCustomValidator) validateGatewayProxyConflict(ctx context.C
162162
gp.GetNamespace(), gp.GetName(),
163163
other.GetNamespace(), other.GetName(),
164164
strings.Join(overlap, ", "),
165-
current.adminKeyDescription,
165+
current.adminKeyDetail(),
166166
)
167167
}
168168
}
@@ -172,11 +172,11 @@ func (v *GatewayProxyCustomValidator) validateGatewayProxyConflict(ctx context.C
172172
}
173173

174174
type gatewayProxyConfig struct {
175-
adminKeyKey string
176-
adminKeyDescription string
177-
serviceKey string
178-
serviceDescription string
179-
endpoints map[string]struct{}
175+
adminKeyKey string
176+
secretKey string
177+
serviceKey string
178+
serviceDescription string
179+
endpoints map[string]struct{}
180180
}
181181

182182
func buildGatewayProxyConfig(gp *v1alpha1.GatewayProxy) gatewayProxyConfig {
@@ -191,11 +191,10 @@ func buildGatewayProxyConfig(gp *v1alpha1.GatewayProxy) gatewayProxyConfig {
191191
if cp.Auth.AdminKey != nil {
192192
if value := strings.TrimSpace(cp.Auth.AdminKey.Value); value != "" {
193193
cfg.adminKeyKey = "value:" + value
194-
cfg.adminKeyDescription = "the same inline AdminKey value"
195194
} else if cp.Auth.AdminKey.ValueFrom != nil && cp.Auth.AdminKey.ValueFrom.SecretKeyRef != nil {
196195
ref := cp.Auth.AdminKey.ValueFrom.SecretKeyRef
197196
cfg.adminKeyKey = fmt.Sprintf("secret:%s/%s:%s", gp.GetNamespace(), ref.Name, ref.Key)
198-
cfg.adminKeyDescription = fmt.Sprintf("AdminKey secret %s/%s key %s", gp.GetNamespace(), ref.Name, ref.Key)
197+
cfg.secretKey = fmt.Sprintf("%s/%s:%s", gp.GetNamespace(), ref.Name, ref.Key)
199198
}
200199
}
201200

@@ -214,6 +213,13 @@ func buildGatewayProxyConfig(gp *v1alpha1.GatewayProxy) gatewayProxyConfig {
214213
return cfg
215214
}
216215

216+
func (c gatewayProxyConfig) adminKeyDetail() string {
217+
if c.secretKey != "" {
218+
return fmt.Sprintf("AdminKey secret %s", c.secretKey)
219+
}
220+
return "the same inline AdminKey value"
221+
}
222+
217223
func (c gatewayProxyConfig) readyForConflict() bool {
218224
if c.adminKeyKey == "" {
219225
return false

internal/webhook/v1/gatewayproxy_webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestGatewayProxyValidator_DetectsServiceConflict(t *testing.T) {
220220
require.Len(t, warnings, 0)
221221
require.Contains(t, err.Error(), "gateway proxy configuration conflict")
222222
require.Contains(t, err.Error(), "Service default/control-plane port 9180")
223-
require.Contains(t, err.Error(), "AdminKey secret default/admin-key key token")
223+
require.Contains(t, err.Error(), "AdminKey secret default/admin-key:token")
224224
}
225225

226226
func TestGatewayProxyValidator_DetectsEndpointConflict(t *testing.T) {
@@ -243,7 +243,7 @@ func TestGatewayProxyValidator_DetectsEndpointConflict(t *testing.T) {
243243
require.Len(t, warnings, 0)
244244
require.Contains(t, err.Error(), "gateway proxy configuration conflict")
245245
require.Contains(t, err.Error(), "endpoints [https://10.0.0.1:9443, https://127.0.0.1:9443]")
246-
require.Contains(t, err.Error(), "AdminKey secret default/admin-key key token")
246+
require.Contains(t, err.Error(), "AdminKey secret default/admin-key:token")
247247
}
248248

249249
func TestGatewayProxyValidator_AllowsDistinctGatewayGroups(t *testing.T) {

0 commit comments

Comments
 (0)