Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions agentteams-controller/internal/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package initializer
import (
"context"
"fmt"
"net"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -340,15 +341,27 @@ func (i *Initializer) initGatewayRoutes(ctx context.Context) error {
if strings.HasPrefix(cfg.OpenAIBaseURL, "http://") {
proto = "http"
}
if err := i.Gateway.EnsureServiceSource(ctx, "openai-compat", host, port, proto); err != nil {
logger.Error(err, "failed to register openai-compat service source (non-fatal)")
svcName := "openai-compat"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No unit tests exist for initializer.go yet. The IP-vs-domain branching is easy to test in isolation — consider a table-driven test covering bare IPv4, bracketed IPv6, plain domain, domain with port, localhost, and empty host.

svcSuffix := "dns"
if net.ParseIP(host) != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proto is computed but unused in the static branch: EnsureStaticServiceSource hardcodes protocol: "http" internally. An https:// base URL would silently register an http static source. Consistent with existing static-source usage (Tuwunel, Element Web), but worth a short comment or log line documenting the limitation.

// Bare IP addresses cannot be registered as DNS-type service sources
// (Higress console checkDomain rejects IPs, and Envoy DNS clusters
// cannot resolve them); use a static service source instead.
svcSuffix = "static"
if err := i.Gateway.EnsureStaticServiceSource(ctx, svcName, host, port); err != nil {
logger.Error(err, "failed to register openai-compat static service source (non-fatal)")
}
} else {
if err := i.Gateway.EnsureServiceSource(ctx, svcName, host, port, proto); err != nil {
logger.Error(err, "failed to register openai-compat service source (non-fatal)")
}
}
// Wait for DNS service source to propagate before creating provider
// Wait for service source to propagate before creating provider
time.Sleep(2 * time.Second)
raw := map[string]interface{}{
"agentteamsMode": true,
"openaiCustomUrl": cfg.OpenAIBaseURL,
"openaiCustomServiceName": "openai-compat.dns",
"openaiCustomServiceName": svcName + "." + svcSuffix,
"openaiCustomServicePort": port,
}
if err := i.Gateway.EnsureAIProvider(ctx, gateway.AIProviderRequest{
Expand All @@ -375,14 +388,24 @@ func (i *Initializer) initGatewayRoutes(ctx context.Context) error {
if strings.HasPrefix(cfg.OpenAIBaseURL, "http://") {
proto = "http"
}
if err := i.Gateway.EnsureServiceSource(ctx, provider, host, port, proto); err != nil {
logger.Error(err, "failed to register service source for provider (non-fatal)")
svcSuffix := "dns"
if net.ParseIP(host) != nil {
// Bare IP addresses cannot be registered as DNS-type service sources;
// use a static service source instead.
svcSuffix = "static"
if err := i.Gateway.EnsureStaticServiceSource(ctx, provider, host, port); err != nil {
logger.Error(err, "failed to register static service source for provider (non-fatal)")
}
} else {
if err := i.Gateway.EnsureServiceSource(ctx, provider, host, port, proto); err != nil {
logger.Error(err, "failed to register service source for provider (non-fatal)")
}
}
time.Sleep(2 * time.Second)
raw := map[string]interface{}{
"agentteamsMode": true,
"openaiCustomUrl": cfg.OpenAIBaseURL,
"openaiCustomServiceName": provider + ".dns",
"openaiCustomServiceName": provider + "." + svcSuffix,
"openaiCustomServicePort": port,
}
if err := i.Gateway.EnsureAIProvider(ctx, gateway.AIProviderRequest{
Expand Down
Loading