Skip to content

Commit 081cb53

Browse files
committed
fix: check API hostname conflict before instance validation
Move the API hostname conflict check earlier in the validation flow so users get a clear "reserved for API" error instead of a confusing "instance not found" error.
1 parent 80cd4ae commit 081cb53

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/ingress/manager.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ func (m *manager) Create(ctx context.Context, req CreateIngressRequest) (*Ingres
297297
}
298298
}
299299

300+
// Check if any hostname conflicts with API hostname (reserved for Hypeman API)
301+
// This check must happen before instance validation to give a clear error message
302+
if m.config.APIIngress.IsEnabled() {
303+
for _, rule := range req.Rules {
304+
if rule.Match.Hostname == m.config.APIIngress.Hostname {
305+
return nil, fmt.Errorf("%w: hostname %q is reserved for the Hypeman API", ErrHostnameInUse, rule.Match.Hostname)
306+
}
307+
}
308+
}
309+
300310
// Validate that all target instances exist and resolve their names (only for literal hostnames)
301311
// Pattern hostnames have dynamic target instances that can't be validated at creation time
302312
var resolvedInstanceIDs []string // Track IDs for logging (used for hypeman.log routing)
@@ -323,12 +333,6 @@ func (m *manager) Create(ctx context.Context, req CreateIngressRequest) (*Ingres
323333

324334
for _, rule := range req.Rules {
325335
newPort := rule.Match.GetPort()
326-
327-
// Check if hostname conflicts with API hostname (reserved for Hypeman API)
328-
if m.config.APIIngress.IsEnabled() && rule.Match.Hostname == m.config.APIIngress.Hostname {
329-
return nil, fmt.Errorf("%w: hostname %q is reserved for the Hypeman API", ErrHostnameInUse, rule.Match.Hostname)
330-
}
331-
332336
for _, existing := range existingIngresses {
333337
for _, existingRule := range existing.Rules {
334338
existingPort := existingRule.Match.GetPort()

0 commit comments

Comments
 (0)