From e4ee7928f9d804a13e9b1f532f79cd0ab3624418 Mon Sep 17 00:00:00 2001 From: Johnny Walker Date: Sat, 11 Apr 2026 16:40:45 -0400 Subject: [PATCH] fix: wrap host with brackets if IPv6 address detected --- kubernetes-client/src/Kubernetes/Client/Config.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kubernetes-client/src/Kubernetes/Client/Config.hs b/kubernetes-client/src/Kubernetes/Client/Config.hs index beafe692..3de2e95b 100644 --- a/kubernetes-client/src/Kubernetes/Client/Config.hs +++ b/kubernetes-client/src/Kubernetes/Client/Config.hs @@ -96,10 +96,17 @@ mkInClusterClientConfig = do defTlsParams host <- liftIO $ getEnv "KUBERNETES_SERVICE_HOST" port <- liftIO $ getEnv "KUBERNETES_SERVICE_PORT" - cfg <- setMasterURI (T.pack $ "https://" ++ host ++ ":" ++ port) <$> liftIO + cfg <- setMasterURI (T.pack $ "https://" ++ (formatHost host) ++ ":" ++ port) <$> liftIO (K.newConfig >>= setTokenFileAuth (serviceAccountDir ++ "/token")) return (mgr, cfg) +-- | Wraps host with brackets if IPv6 address detected and not already wrapped +formatHost :: String -> String +formatHost host@('[' : _) = host -- already wrapped with brackets +formatHost host + | ':' `elem` host = "[" ++ host ++ "]" -- assume IPv6 if host has colons + | otherwise = host + -- |Sets the master URI in the 'K.KubernetesClientConfig'. setMasterURI :: T.Text -- ^ Master URI