{"record":{"id":"da7bf8f90cd883f0","repo":"microsoft/aspire","slug":"gateway-gatewayname-was-not-assigned-a-hostname-address","errorCode":null,"errorMessage":"Gateway '{gatewayName}' was not assigned a hostname address within the discovery timeout. TLS hostname discovery cannot complete. Either retry the deploy (the controller may still be provisioning the address) or set an explicit hostname via WithHostname().","messagePattern":"Gateway '(.+?)' was not assigned a hostname address within the discovery timeout\\. TLS hostname discovery cannot complete\\. Either retry the deploy \\(the controller may still be provisioning the address\\) or set an explicit hostname via WithHostname\\(\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentResource.cs","lineNumber":1448,"sourceCode":"            // We use -o json and parse the full status to select Hostname-type addresses,\n            // since some controllers return IP addresses which are not valid for TLS hostnames.\n            context.Logger.LogInformation(\n                \"Waiting for Gateway '{GatewayName}' to be assigned a hostname address...\", gatewayName);\n\n            var discoveredFqdn = await DiscoverGatewayFqdnAsync(\n                gatewayName, @namespace, environment, context).ConfigureAwait(false);\n\n            if (string.IsNullOrEmpty(discoveredFqdn))\n            {\n                // Hard failure rather than a logged warning: when the user has TLS configured\n                // without an explicit hostname, the deployment is only meaningful once the\n                // listener hostname is patched (cert-manager's gateway shim issues no\n                // certificate for a hostname-less HTTPS listener). Silently continuing\n                // produces an apparently-successful deploy that never serves valid TLS, which\n                // is far worse than failing visibly here. The user can fix this by either\n                // waiting for their controller to assign an address sooner or by passing an\n                // explicit hostname via WithHostname() / WithTls(hostname: ...).\n                throw new InvalidOperationException(\n                    $\"Gateway '{gatewayName}' was not assigned a hostname address within the discovery timeout. \" +\n                    \"TLS hostname discovery cannot complete. Either retry the deploy (the controller may still be \" +\n                    \"provisioning the address) or set an explicit hostname via WithHostname().\");\n            }\n\n            context.Logger.LogInformation(\n                \"Gateway '{GatewayName}' assigned address: {Fqdn}. Patching HTTPS listener(s) and bootstrapping TLS.\",\n                gatewayName, discoveredFqdn);\n\n            // Find HTTPS listeners without a hostname by parsing the full Gateway JSON.\n            var httpsListenerIndices = await FindHostnamelessHttpsListeners(\n                gatewayName, @namespace, environment, context).ConfigureAwait(false);\n\n            if (httpsListenerIndices.Count == 0)\n            {\n                context.Logger.LogWarning(\n                    \"No HTTPS listeners without hostname found on Gateway '{GatewayName}'. Skipping hostname patch.\",\n                    gatewayName);","sourceCodeStart":1430,"sourceCodeEnd":1466,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentResource.cs#L1430-L1466","documentation":"During deployment, TLS hostname discovery waits for the Gateway's provisioned address (from the gateway controller) within a timeout. If no address appears, no certificate can be issued for the HTTPS listener (cert-manager issues no cert for a hostname-less listener), so the deploy fails visibly instead of silently producing a non-functional gateway.","triggerScenarios":"Deploying a Kubernetes environment with a TLS-enabled gateway where the controller (e.g. an LB implementation) is slow or fails to assign an address within the discovery timeout, and no explicit hostname was provided via WithHostname().","commonSituations":"Slow cloud load-balancer provisioning (e.g. fresh clusters where the LB takes minutes); controller crashes or misconfiguration (no GatewayClass controller installed); network/RBAC issues preventing the controller from updating the Gateway status.","solutions":["Retry the deploy — the controller may still be provisioning the address","Set an explicit hostname via WithHostname() (or WithTls(hostname: ...)) to skip discovery","Verify the Gateway API controller is installed and healthy and that the Gateway's status is being populated","Check controller logs/events for provisioning failures"],"exampleFix":"// before\nvar gateway = env.AddKubernetesGateway(\"gw\").WithTls();\n// after\nvar gateway = env.AddKubernetesGateway(\"gw\").WithTls(hostname: \"app.example.com\"); // or .WithHostname(\"app.example.com\")","handlingStrategy":"retry","validationCode":"// before deploy: ensure an explicit hostname is set for TLS gateways\nif (tlsEnabled && string.IsNullOrEmpty(explicitHostname))\n    logger.LogWarning(\"No explicit TLS hostname; discovery may time out on slow controllers.\");","typeGuard":null,"tryCatchPattern":"try { await deployAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"hostname address within the discovery timeout\"))\n{ logger.LogError(ex, \"Gateway address not assigned in time; retry or set WithHostname().\"); }","preventionTips":["Set an explicit hostname via WithHostname()/WithTls(hostname:) for TLS gateways in environments with slow LB provisioning","Ensure the Gateway API controller is installed before deploying","Pre-provision/wait for the load balancer before running the deploy","Increase tolerance by retrying the deploy once before changing config"],"tags":["kubernetes","gateway-api","tls","timeout","deploy"],"backgroundTag":"request-timeout","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}