Skip to content

armgit / ax

Public Imported from GitHub
0

Agent Executor (AX) is Google's open agentic orchestration runtime

Go

feat: replace standard command-line kubectl with clientSets (#155)

JoyceLiueb438ce6ab69
diff --git a/go.mod b/go.mod
index 07bff05..1c2ae42 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module github.com/google/ax
-go 1.25.0
+go 1.26.1
require (
github.com/charmbracelet/huh v0.8.0
@@ -14,9 +14,11 @@ require (
google.golang.org/grpc v1.79.3
google.golang.org/protobuf v1.36.11
gopkg.in/yaml.v3 v3.0.1
+ k8s.io/api v0.35.2
k8s.io/apimachinery v0.35.2
k8s.io/client-go v0.35.2
modernc.org/sqlite v1.47.0
+ sigs.k8s.io/agent-sandbox v0.2.2-0.20260330232013-dff20f58c81e
)
require (
@@ -37,28 +39,45 @@ require (
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
+ github.com/emicklei/go-restful/v3 v3.13.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
+ github.com/go-openapi/jsonpointer v0.22.1 // indirect
+ github.com/go-openapi/jsonreference v0.21.2 // indirect
+ github.com/go-openapi/swag v0.25.1 // indirect
+ github.com/go-openapi/swag/cmdutils v0.25.1 // indirect
+ github.com/go-openapi/swag/conv v0.25.1 // indirect
+ github.com/go-openapi/swag/fileutils v0.25.1 // indirect
+ github.com/go-openapi/swag/jsonname v0.25.1 // indirect
+ github.com/go-openapi/swag/jsonutils v0.25.1 // indirect
+ github.com/go-openapi/swag/loading v0.25.1 // indirect
+ github.com/go-openapi/swag/mangling v0.25.1 // indirect
+ github.com/go-openapi/swag/netutils v0.25.1 // indirect
+ github.com/go-openapi/swag/stringutils v0.25.1 // indirect
+ github.com/go-openapi/swag/typeutils v0.25.1 // indirect
+ github.com/go-openapi/swag/yamlutils v0.25.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
+ github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
- github.com/kr/pretty v0.3.1 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
+ github.com/moby/spdystream v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
+ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
@@ -67,14 +86,15 @@ require (
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.opencensus.io v0.24.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
+ go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
- golang.org/x/time v0.9.0 // indirect
+ golang.org/x/time v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect
- gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
+ gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
@@ -82,6 +102,7 @@ require (
modernc.org/libc v1.70.0 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
+ sigs.k8s.io/controller-runtime v0.22.2 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
diff --git a/go.sum b/go.sum
index 7d119a7..1fe9f3e 100644
--- a/go.sum
+++ b/go.sum
@@ -8,6 +8,10 @@ cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCB
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
+github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
+github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
+github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
+github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
@@ -54,7 +58,6 @@ github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuh
github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
-github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -62,8 +65,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
-github.com/emicklei/go-restful/v3 v3.12.2 h1:DhwDP0vY3k8ZzE0RunuJy8GhNpPL6zqLkDf9B/a0/xU=
-github.com/emicklei/go-restful/v3 v3.12.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
+github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes=
+github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
@@ -76,12 +79,38 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
-github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
-github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
-github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
-github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
-github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
-github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
+github.com/go-openapi/jsonpointer v0.22.1 h1:sHYI1He3b9NqJ4wXLoJDKmUmHkWy/L7rtEo92JUxBNk=
+github.com/go-openapi/jsonpointer v0.22.1/go.mod h1:pQT9OsLkfz1yWoMgYFy4x3U5GY5nUlsOn1qSBH5MkCM=
+github.com/go-openapi/jsonreference v0.21.2 h1:Wxjda4M/BBQllegefXrY/9aq1fxBA8sI5M/lFU6tSWU=
+github.com/go-openapi/jsonreference v0.21.2/go.mod h1:pp3PEjIsJ9CZDGCNOyXIQxsNuroxm8FAJ/+quA0yKzQ=
+github.com/go-openapi/swag v0.25.1 h1:6uwVsx+/OuvFVPqfQmOOPsqTcm5/GkBhNwLqIR916n8=
+github.com/go-openapi/swag v0.25.1/go.mod h1:bzONdGlT0fkStgGPd3bhZf1MnuPkf2YAys6h+jZipOo=
+github.com/go-openapi/swag/cmdutils v0.25.1 h1:nDke3nAFDArAa631aitksFGj2omusks88GF1VwdYqPY=
+github.com/go-openapi/swag/cmdutils v0.25.1/go.mod h1:pdae/AFo6WxLl5L0rq87eRzVPm/XRHM3MoYgRMvG4A0=
+github.com/go-openapi/swag/conv v0.25.1 h1:+9o8YUg6QuqqBM5X6rYL/p1dpWeZRhoIt9x7CCP+he0=
+github.com/go-openapi/swag/conv v0.25.1/go.mod h1:Z1mFEGPfyIKPu0806khI3zF+/EUXde+fdeksUl2NiDs=
+github.com/go-openapi/swag/fileutils v0.25.1 h1:rSRXapjQequt7kqalKXdcpIegIShhTPXx7yw0kek2uU=
+github.com/go-openapi/swag/fileutils v0.25.1/go.mod h1:+NXtt5xNZZqmpIpjqcujqojGFek9/w55b3ecmOdtg8M=
+github.com/go-openapi/swag/jsonname v0.25.1 h1:Sgx+qbwa4ej6AomWC6pEfXrA6uP2RkaNjA9BR8a1RJU=
+github.com/go-openapi/swag/jsonname v0.25.1/go.mod h1:71Tekow6UOLBD3wS7XhdT98g5J5GR13NOTQ9/6Q11Zo=
+github.com/go-openapi/swag/jsonutils v0.25.1 h1:AihLHaD0brrkJoMqEZOBNzTLnk81Kg9cWr+SPtxtgl8=
+github.com/go-openapi/swag/jsonutils v0.25.1/go.mod h1:JpEkAjxQXpiaHmRO04N1zE4qbUEg3b7Udll7AMGTNOo=
+github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.1 h1:DSQGcdB6G0N9c/KhtpYc71PzzGEIc/fZ1no35x4/XBY=
+github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.1/go.mod h1:kjmweouyPwRUEYMSrbAidoLMGeJ5p6zdHi9BgZiqmsg=
+github.com/go-openapi/swag/loading v0.25.1 h1:6OruqzjWoJyanZOim58iG2vj934TysYVptyaoXS24kw=
+github.com/go-openapi/swag/loading v0.25.1/go.mod h1:xoIe2EG32NOYYbqxvXgPzne989bWvSNoWoyQVWEZicc=
+github.com/go-openapi/swag/mangling v0.25.1 h1:XzILnLzhZPZNtmxKaz/2xIGPQsBsvmCjrJOWGNz/ync=
+github.com/go-openapi/swag/mangling v0.25.1/go.mod h1:CdiMQ6pnfAgyQGSOIYnZkXvqhnnwOn997uXZMAd/7mQ=
+github.com/go-openapi/swag/netutils v0.25.1 h1:2wFLYahe40tDUHfKT1GRC4rfa5T1B4GWZ+msEFA4Fl4=
+github.com/go-openapi/swag/netutils v0.25.1/go.mod h1:CAkkvqnUJX8NV96tNhEQvKz8SQo2KF0f7LleiJwIeRE=
+github.com/go-openapi/swag/stringutils v0.25.1 h1:Xasqgjvk30eUe8VKdmyzKtjkVjeiXx1Iz0zDfMNpPbw=
+github.com/go-openapi/swag/stringutils v0.25.1/go.mod h1:JLdSAq5169HaiDUbTvArA2yQxmgn4D6h4A+4HqVvAYg=
+github.com/go-openapi/swag/typeutils v0.25.1 h1:rD/9HsEQieewNt6/k+JBwkxuAHktFtH3I3ysiFZqukA=
+github.com/go-openapi/swag/typeutils v0.25.1/go.mod h1:9McMC/oCdS4BKwk2shEB7x17P6HmMmA6dQRtAkSnNb8=
+github.com/go-openapi/swag/yamlutils v0.25.1 h1:mry5ez8joJwzvMbaTGLhw8pXUnhDK91oSJLDPF1bmGk=
+github.com/go-openapi/swag/yamlutils v0.25.1/go.mod h1:cm9ywbzncy3y6uPm/97ysW8+wZ09qsks+9RS8fLWKqg=
+github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
+github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
@@ -124,21 +153,14 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
-github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
-github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
-github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
-github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
-github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
-github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
@@ -147,6 +169,8 @@ github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byF
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
+github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
+github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -161,9 +185,14 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
+github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
+github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
-github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
+github.com/onsi/ginkgo/v2 v2.27.2 h1:LzwLj0b89qtIy6SSASkzlNvX6WktqurSHwkk2ipF/Ns=
+github.com/onsi/ginkgo/v2 v2.27.2/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
+github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
+github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -171,7 +200,6 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
-github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@@ -199,16 +227,16 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
-go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
-go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
-go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
-go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
-go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18=
-go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE=
+go.opentelemetry.io/otel v1.42.0 h1:lSQGzTgVR3+sgJDAU/7/ZMjN9Z+vUip7leaqBKy4sho=
+go.opentelemetry.io/otel v1.42.0/go.mod h1:lJNsdRMxCUIWuMlVJWzecSMuNjE7dOYyWlqOXWkdqCc=
+go.opentelemetry.io/otel/metric v1.42.0 h1:2jXG+3oZLNXEPfNmnpxKDeZsFI5o4J+nz6xUlaFdF/4=
+go.opentelemetry.io/otel/metric v1.42.0/go.mod h1:RlUN/7vTU7Ao/diDkEpQpnz3/92J9ko05BIwxYa2SSI=
+go.opentelemetry.io/otel/sdk v1.42.0 h1:LyC8+jqk6UJwdrI/8VydAq/hvkFKNHZVIWuslJXYsDo=
+go.opentelemetry.io/otel/sdk v1.42.0/go.mod h1:rGHCAxd9DAph0joO4W6OPwxjNTYWghRWmkHuGbayMts=
go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8=
go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew=
-go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
-go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
+go.opentelemetry.io/otel/trace v1.42.0 h1:OUCgIPt+mzOnaUTpOQcBiM/PLQ/Op7oq6g4LenLmOYY=
+go.opentelemetry.io/otel/trace v1.42.0/go.mod h1:f3K9S+IFqnumBkKhRJMeaZeNk9epyhnCmQh/EysQCdc=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
@@ -255,8 +283,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
-golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
-golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
+golang.org/x/time v0.13.0 h1:eUlYslOIt32DgYD6utsuUeHs4d7AsEYLuIAdg7FlYgI=
+golang.org/x/time v0.13.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -346,6 +374,10 @@ modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
+sigs.k8s.io/agent-sandbox v0.2.2-0.20260330232013-dff20f58c81e h1:pWRnvUEp87A/NmMYKuwxxuZNkmxlRlAxaf89Khn7ICQ=
+sigs.k8s.io/agent-sandbox v0.2.2-0.20260330232013-dff20f58c81e/go.mod h1:KgzzW+pWCb1u3/+xaw+zhpKp+O7WlHYWCQtbfypARGQ=
+sigs.k8s.io/controller-runtime v0.22.2 h1:cK2l8BGWsSWkXz09tcS4rJh95iOLney5eawcK5A33r4=
+sigs.k8s.io/controller-runtime v0.22.2/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
diff --git a/internal/agent/k8s_sandbox.go b/internal/agent/k8s_sandbox.go
index 4799f7b..97a223b 100644
--- a/internal/agent/k8s_sandbox.go
+++ b/internal/agent/k8s_sandbox.go
@@ -110,12 +110,7 @@ func (a *KubernetesSandboxAgent) Connect(ctx context.Context, execID string, sta
// Wait for Sandbox to bound and get the warm pool pod selector
selector, err := a.client.WaitForSandbox(ctx, claimName)
if err != nil {
- return err
- }
-
- // Wait for the Sandbox to become Ready so its DNS record is populated
- if err := a.client.WaitForSandboxReady(ctx, claimName); err != nil {
- log.Printf("Warning: failed to wait for sandbox readiness: %v", err)
+ return fmt.Errorf("failed to wait for sandbox: %w", err)
}
// 2. Setup Connection (Direct or Router)
diff --git a/internal/sandboxclient/client.go b/internal/sandboxclient/client.go
index c16febb..23cde4d 100644
--- a/internal/sandboxclient/client.go
+++ b/internal/sandboxclient/client.go
@@ -19,185 +19,341 @@ package sandboxclient
import (
"context"
"fmt"
- "os"
- "os/exec"
- "strings"
+ "log"
"time"
+ corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
- "k8s.io/apimachinery/pkg/runtime/schema"
- "k8s.io/client-go/dynamic"
+ "k8s.io/apimachinery/pkg/watch"
+ "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
-)
-var (
- SandboxGVR = schema.GroupVersionResource{
- Group: "agents.x-k8s.io",
- Version: "v1alpha1",
- Resource: "sandboxes",
- }
- SandboxClaimGVR = schema.GroupVersionResource{
- Group: "extensions.agents.x-k8s.io",
- Version: "v1alpha1",
- Resource: "sandboxclaims",
- }
+ sandboxv1alpha1 "sigs.k8s.io/agent-sandbox/api/v1alpha1"
+ agentsclientset "sigs.k8s.io/agent-sandbox/clients/k8s/clientset/versioned"
+ extclientset "sigs.k8s.io/agent-sandbox/clients/k8s/extensions/clientset/versioned"
+ extensionsv1alpha1 "sigs.k8s.io/agent-sandbox/extensions/api/v1alpha1"
)
-// Client represents a high-level client for managing Sandbox resources in Kubernetes.
+const routerLabelSelector = "app=sandbox-router"
+
+// Client implements a high-level client for managing Sandbox resources in Kubernetes.
+//
+// It holds three typed clientsets — one per API group:
+//
+// - agentsClient: for Sandbox resources (agents.x-k8s.io/v1alpha1).
+// Used to Watch/Get sandboxes and check the Ready condition.
+//
+// - extClient: for SandboxClaim, SandboxTemplate, SandboxWarmPool
+// (extensions.agents.x-k8s.io/v1alpha1). Used to Create/Delete claims.
+//
+// - clientset: for core Kubernetes resources (pods, services).
+// Needed for pod discovery during port-forward setup and for the
+// CoreV1().RESTClient() that SPDY port-forward tunneling requires.
type Client struct {
- dynClient dynamic.Interface
- namespace string
+ agentsClient agentsclientset.Interface // Handles Sandbox resources (agents.x-k8s.io/v1alpha1)
+ extClient extclientset.Interface // Handles SandboxClaim, SandboxTemplate, SandboxWarmPool (extensions.agents.x-k8s.io/v1alpha1)
+ clientset kubernetes.Interface // Handles Core Kubernetes resources (Pods, Services, REST client)
+ restConfig *rest.Config
+ namespace string
}
// NewClient creates a new Sandbox client using the local kubeconfig or cluster environment.
func NewClient(namespace string) (*Client, error) {
- // 1. Try in-cluster config first
config, err := rest.InClusterConfig()
if err != nil {
- // 2. Fall back to local kubeconfig
- kubeconfig := clientcmd.NewDefaultClientConfigLoadingRules().GetDefaultFilename()
+ kubeconfig := clientcmd.RecommendedHomeFile
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
- return nil, fmt.Errorf("failed to load kubernetes configuration: %w", err)
+ return nil, fmt.Errorf("failed to load kubeconfig: %w", err)
}
}
- dynClient, err := dynamic.NewForConfig(config)
+ agentsClient, err := agentsclientset.NewForConfig(config)
+ if err != nil {
+ return nil, fmt.Errorf("failed to create agents clientset: %w", err)
+ }
+
+ extClient, err := extclientset.NewForConfig(config)
if err != nil {
- return nil, fmt.Errorf("failed to create dynamic client: %w", err)
+ return nil, fmt.Errorf("failed to create extensions clientset: %w", err)
+ }
+
+ clientset, err := kubernetes.NewForConfig(config)
+ if err != nil {
+ return nil, fmt.Errorf("failed to create kubernetes clientset: %w", err)
}
return &Client{
- dynClient: dynClient,
- namespace: namespace,
+ agentsClient: agentsClient,
+ extClient: extClient,
+ clientset: clientset,
+ restConfig: config,
+ namespace: namespace,
}, nil
}
-// CreateClaim provisions an ephemeral sandbox execution environment.
+// CreateClaim provisions an ephemeral sandbox execution environment by creating a SandboxClaim.
func (c *Client) CreateClaim(ctx context.Context, claimName, templateRef string) error {
- claim := &unstructured.Unstructured{
- Object: map[string]any{
- "apiVersion": "extensions.agents.x-k8s.io/v1alpha1",
- "kind": "SandboxClaim",
- "metadata": map[string]any{
- "name": claimName,
- "namespace": c.namespace,
- },
- "spec": map[string]any{
- "sandboxTemplateRef": map[string]any{
- "name": templateRef,
- },
+ claim := &extensionsv1alpha1.SandboxClaim{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: claimName,
+ },
+ Spec: extensionsv1alpha1.SandboxClaimSpec{
+ TemplateRef: extensionsv1alpha1.SandboxTemplateRef{
+ Name: templateRef,
},
},
}
- _, err := c.dynClient.Resource(SandboxClaimGVR).Namespace(c.namespace).Create(ctx, claim, metav1.CreateOptions{})
+ _, err := c.extClient.ExtensionsV1alpha1().SandboxClaims(c.namespace).
+ Create(ctx, claim, metav1.CreateOptions{})
return err
}
-// DeleteClaim destroys an ephemeral sandbox execution environment.
-func (c *Client) DeleteClaim(ctx context.Context, claimName string) error {
- return c.dynClient.Resource(SandboxClaimGVR).Namespace(c.namespace).Delete(ctx, claimName, metav1.DeleteOptions{})
-}
+// ResolveSandboxName watches the SandboxClaim until its status contains the resolved
+// Sandbox name (populated by the controller after a warm-pool pod is assigned).
+func (c *Client) ResolveSandboxName(ctx context.Context, claimName string, timeout time.Duration) (string, error) {
+ ctx, cancel := context.WithTimeout(ctx, timeout)
+ defer cancel()
-// WaitForSandbox waits for the Sandbox resource to be ready and returns the pod selector.
-func (c *Client) WaitForSandbox(ctx context.Context, claimName string) (selector string, err error) {
- for range 300 {
- select {
- case <-ctx.Done():
- return "", ctx.Err()
- case <-time.After(1 * time.Second):
- s, err := c.dynClient.Resource(SandboxGVR).Namespace(c.namespace).Get(ctx, claimName, metav1.GetOptions{})
- if err != nil {
- continue
- }
+ watcher, err := c.extClient.ExtensionsV1alpha1().SandboxClaims(c.namespace).
+ Watch(ctx, metav1.ListOptions{
+ FieldSelector: fmt.Sprintf("metadata.name=%s", claimName),
+ })
+ if err != nil {
+ return "", fmt.Errorf("failed to watch SandboxClaim %s: %w", claimName, err)
+ }
+ defer watcher.Stop()
- sel, ok, _ := unstructured.NestedString(s.Object, "status", "selector")
- if ok && sel != "" {
- selector = sel
+ for event := range watcher.ResultChan() {
+ if event.Type == watch.Error {
+ continue
+ }
+ claim, ok := event.Object.(*extensionsv1alpha1.SandboxClaim)
+ if !ok {
+ continue
+ }
+ // In the current schema, the Sandbox name is identical to the claim name,
+ // and we wait for the claim to be Ready to ensure it's bound.
+ for _, cond := range claim.Status.Conditions {
+ if string(cond.Type) == "Ready" && string(cond.Status) == string(metav1.ConditionTrue) {
+ return claimName, nil
}
+ }
+ }
+ return "", fmt.Errorf("timeout waiting for sandbox readiness on claim %s", claimName)
+}
+
+// ResolveSandboxStatus watches the Sandbox until its status is fully populated,
+// returning the label selector and service name needed for port-forwarding.
+func (c *Client) ResolveSandboxStatus(ctx context.Context, sandboxName string, timeout time.Duration) (selector, svc string, err error) {
+ ctx, cancel := context.WithTimeout(ctx, timeout)
+ defer cancel()
+
+ watcher, err := c.agentsClient.AgentsV1alpha1().Sandboxes(c.namespace).
+ Watch(ctx, metav1.ListOptions{
+ FieldSelector: fmt.Sprintf("metadata.name=%s", sandboxName),
+ })
+ if err != nil {
+ return "", "", fmt.Errorf("failed to watch Sandbox %s: %w", sandboxName, err)
+ }
+ defer watcher.Stop()
+
+ for event := range watcher.ResultChan() {
+ if event.Type == watch.Error {
+ continue
+ }
+ sandbox, ok := event.Object.(*sandboxv1alpha1.Sandbox)
+ if !ok {
+ continue
+ }
+ if sandbox.Status.LabelSelector != "" && sandbox.Status.Service != "" {
+ return sandbox.Status.LabelSelector, sandbox.Status.Service, nil
+ }
+ }
+ return "", "", fmt.Errorf("timeout waiting for sandbox status for %s", sandboxName)
+}
+
+// WaitForSandboxReady watches the Sandbox until the Ready condition is True.
+func (c *Client) WaitForSandboxReady(ctx context.Context, sandboxName string) error {
+ watcher, err := c.agentsClient.AgentsV1alpha1().Sandboxes(c.namespace).
+ Watch(ctx, metav1.ListOptions{
+ FieldSelector: fmt.Sprintf("metadata.name=%s", sandboxName),
+ })
+ if err != nil {
+ return fmt.Errorf("failed to watch Sandbox %s: %w", sandboxName, err)
+ }
+ defer watcher.Stop()
- svc, found, _ := unstructured.NestedString(s.Object, "status", "service")
- if found && svc != "" {
- return selector, nil // Return once the service status is actively populated
+ for event := range watcher.ResultChan() {
+ sandbox, ok := event.Object.(*sandboxv1alpha1.Sandbox)
+ if !ok {
+ continue
+ }
+ for _, cond := range sandbox.Status.Conditions {
+ if string(cond.Type) == string(sandboxv1alpha1.SandboxConditionReady) && string(cond.Status) == string(metav1.ConditionTrue) {
+ return nil
}
}
}
- return "", fmt.Errorf("timeout waiting for sandbox service IP for claim %s", claimName)
+ return fmt.Errorf("timeout waiting for Sandbox %s to be ready", sandboxName)
}
-// WaitForSandboxReady waits for the Sandbox to become Ready.
-func (c *Client) WaitForSandboxReady(ctx context.Context, claimName string) error {
- waitCmd := exec.CommandContext(ctx, "kubectl", "wait", "--for=condition=Ready", "--namespace", c.namespace, "sandbox.agents.x-k8s.io/"+claimName, "--timeout=120s")
- if err := waitCmd.Run(); err != nil {
- return fmt.Errorf("failed waiting for sandbox %s to be ready: %w", claimName, err)
+// findRunningPod finds a Running pod matching the given label selector.
+func (c *Client) findRunningPod(ctx context.Context, selector string) (string, error) {
+ pods, err := c.clientset.CoreV1().Pods(c.namespace).List(ctx, metav1.ListOptions{
+ LabelSelector: selector,
+ FieldSelector: "status.phase=Running",
+ })
+ if err != nil {
+ return "", fmt.Errorf("failed to list pods with selector %s: %w", selector, err)
+ }
+ if len(pods.Items) == 0 {
+ return "", fmt.Errorf("no running pod found with selector %s", selector)
}
- return nil
+ return pods.Items[0].Name, nil
}
// PortForward establishes a local connection to the remote sandbox pod over the given port.
-// It returns a cleanup function the caller MUST execute when finished, closing the port-forward pipeline.
+// It returns a cleanup function the caller MUST execute when finished.
func (c *Client) PortForward(ctx context.Context, claimName, selector string, localPort, targetPort int) (cancelFunc func(), err error) {
- pfCtx, pfCancel := context.WithCancel(ctx)
-
- // Wait for Sandbox to be ready first
- waitCmd := exec.CommandContext(pfCtx, "kubectl", "wait", "--for=condition=Ready", "--namespace", c.namespace, "sandbox.agents.x-k8s.io/"+claimName, "--timeout=120s")
- if err := waitCmd.Run(); err != nil {
- pfCancel()
- return nil, fmt.Errorf("failed waiting for sandbox %s to be ready: %w", claimName, err)
- }
-
- target := "svc/" + claimName
- if selector != "" {
- // Find the backing pod specifically to correctly link the port pipe with WarmPools
- findPodCmd := exec.CommandContext(pfCtx, "kubectl", "get", "pods", "--namespace", c.namespace, "-l", selector, "--field-selector=status.phase=Running", "-o", "name")
- out, err := findPodCmd.Output()
- if err == nil {
- podNames := strings.Split(strings.TrimSpace(string(out)), "\n")
- if len(podNames) > 0 && podNames[0] != "" {
- target = podNames[0]
- }
+ ctx, cancel := context.WithCancel(ctx)
+
+ // 1. Resolve sandbox name from the claim
+ sandboxName, err := c.ResolveSandboxName(ctx, claimName, 2*time.Minute)
+ if err != nil {
+ cancel()
+ return nil, fmt.Errorf("failed to resolve sandbox for claim %s: %w", claimName, err)
+ }
+
+ // 2. Wait for Sandbox to be ready
+ waitCtx, waitCancel := context.WithTimeout(ctx, 2*time.Minute)
+ defer waitCancel()
+
+ if err := c.WaitForSandboxReady(waitCtx, sandboxName); err != nil {
+ cancel()
+ return nil, fmt.Errorf("failed waiting for Sandbox %s to be ready: %w", sandboxName, err)
+ }
+
+ // 3. Resolve sandbox status to get the label selector if not provided
+ if selector == "" {
+ resolvedSelector, _, err := c.ResolveSandboxStatus(ctx, sandboxName, 30*time.Second)
+ if err != nil {
+ cancel()
+ return nil, fmt.Errorf("failed to resolve sandbox status for %s: %w", sandboxName, err)
}
+ selector = resolvedSelector
}
- cmd := exec.CommandContext(pfCtx, "kubectl", "port-forward", "--namespace", c.namespace, target, fmt.Sprintf("%d:%d", localPort, targetPort))
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- if err := cmd.Start(); err != nil {
- pfCancel()
- return nil, fmt.Errorf("failed to start port-forward: %w", err)
+ // 4. Find the specific running pod assigned to the claim
+ podName, err := c.findRunningPod(ctx, selector)
+ if err != nil {
+ cancel()
+ return nil, fmt.Errorf("failed to find running pod for %s: %w", claimName, err)
}
- // Give port-forwarding a moment to establish
- time.Sleep(10 * time.Second)
+ // 5. Establish SPDY port-forward (no kubectl subprocess)
+ if err := c.forwardPortToPod(ctx, cancel, podName, localPort, targetPort); err != nil {
+ cancel()
+ return nil, err
+ }
- return pfCancel, nil
+ return cancel, nil
}
// PortForwardRouter establishes a local connection to the Sandbox Router service.
-// It returns a cleanup function the caller MUST execute when finished.
func (c *Client) PortForwardRouter(ctx context.Context, localPort, targetPort int) (cancelFunc func(), err error) {
- pfCtx, pfCancel := context.WithCancel(ctx)
+ ctx, cancel := context.WithCancel(ctx)
- // Wait for Router service to be ready
- waitCmd := exec.CommandContext(pfCtx, "kubectl", "wait", "--for=condition=Ready", "--namespace", c.namespace, "pod", "-l", "app=sandbox-router", "--timeout=120s")
- if err := waitCmd.Run(); err != nil {
- pfCancel()
+ routerPodName, err := c.waitForRouterPod(ctx, 2*time.Minute)
+ if err != nil {
+ cancel()
return nil, fmt.Errorf("failed waiting for sandbox-router to be ready: %w", err)
}
- cmd := exec.CommandContext(pfCtx, "kubectl", "port-forward", "--namespace", c.namespace, "svc/sandbox-router-svc", fmt.Sprintf("%d:%d", localPort, targetPort))
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- if err := cmd.Start(); err != nil {
- pfCancel()
- return nil, fmt.Errorf("failed to start router port-forward: %w", err)
+ if err := c.forwardPortToPod(ctx, cancel, routerPodName, localPort, targetPort); err != nil {
+ cancel()
+ return nil, err
+ }
+
+ return cancel, nil
+}
+
+// waitForPod watches for a Ready pod matching the given selector.
+func (c *Client) waitForPod(ctx context.Context, selector string, timeout time.Duration) (string, error) {
+ ctx, cancel := context.WithTimeout(ctx, timeout)
+ defer cancel()
+
+ // Check if already ready
+ pods, err := c.clientset.CoreV1().Pods(c.namespace).List(ctx, metav1.ListOptions{
+ LabelSelector: selector,
+ })
+ if err != nil {
+ return "", fmt.Errorf("failed to list pods with selector %s: %w", selector, err)
+ }
+ for _, pod := range pods.Items {
+ if isPodReady(&pod) {
+ return pod.Name, nil
+ }
+ }
+
+ // Watch until one becomes Ready
+ watcher, err := c.clientset.CoreV1().Pods(c.namespace).Watch(ctx, metav1.ListOptions{
+ LabelSelector: selector,
+ })
+ if err != nil {
+ return "", fmt.Errorf("failed to watch pods with selector %s: %w", selector, err)
+ }
+ defer watcher.Stop()
+
+ for event := range watcher.ResultChan() {
+ pod, ok := event.Object.(*corev1.Pod)
+ if !ok {
+ continue
+ }
+ if isPodReady(pod) {
+ return pod.Name, nil
+ }
+ }
+ return "", fmt.Errorf("timeout waiting for pod with selector %s to be ready", selector)
+}
+
+// waitForRouterPod watches for a Ready sandbox-router pod.
+func (c *Client) waitForRouterPod(ctx context.Context, timeout time.Duration) (string, error) {
+ return c.waitForPod(ctx, routerLabelSelector, timeout)
+}
+
+func isPodReady(pod *corev1.Pod) bool {
+ for _, cond := range pod.Status.Conditions {
+ if cond.Type == corev1.PodReady && cond.Status == corev1.ConditionTrue {
+ return true
+ }
}
+ return false
+}
+
+// DeleteClaim deletes the SandboxClaim, releasing the sandbox back to the warm pool.
+func (c *Client) DeleteClaim(ctx context.Context, claimName string) error {
+ return c.extClient.ExtensionsV1alpha1().SandboxClaims(c.namespace).
+ Delete(ctx, claimName, metav1.DeleteOptions{})
+}
- // Give port-forwarding a moment to establish
- time.Sleep(2 * time.Second)
+// WaitForSandbox wraps the name resolution, selector resolution, and readiness wait into a single call for callers.
+func (c *Client) WaitForSandbox(ctx context.Context, claimName string) (string, error) {
+ sandboxName, err := c.ResolveSandboxName(ctx, claimName, 2*time.Minute)
+ if err != nil {
+ return "", fmt.Errorf("failed to resolve sandbox name: %w", err)
+ }
+
+ selector, _, err := c.ResolveSandboxStatus(ctx, sandboxName, 30*time.Second)
+ if err != nil {
+ return "", fmt.Errorf("failed to resolve sandbox status: %w", err)
+ }
+
+ if err := c.WaitForSandboxReady(ctx, sandboxName); err != nil {
+ log.Printf("Warning: failed waiting for Sandbox %s to be ready: %v", sandboxName, err)
+ }
- return pfCancel, nil
+ return selector, nil
}
diff --git a/internal/sandboxclient/portforward.go b/internal/sandboxclient/portforward.go
new file mode 100644
index 0000000..b922a93
--- /dev/null
+++ b/internal/sandboxclient/portforward.go
@@ -0,0 +1,72 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sandboxclient
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "net/http"
+ "time"
+
+ "k8s.io/client-go/tools/portforward"
+ "k8s.io/client-go/transport/spdy"
+)
+
+// forwardPortToPod executes the low-level SPDY stream connection to forward ports.
+func (c *Client) forwardPortToPod(ctx context.Context, cancel context.CancelFunc, podName string, localPort, targetPort int) error {
+ req := c.clientset.CoreV1().RESTClient().Post().
+ Resource("pods").
+ Namespace(c.namespace).
+ Name(podName).
+ SubResource("portforward")
+
+ transport, upgrader, err := spdy.RoundTripperFor(c.restConfig)
+ if err != nil {
+ return fmt.Errorf("error creating round tripper: %w", err)
+ }
+
+ dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, http.MethodPost, req.URL())
+
+ readyChan := make(chan struct{})
+ ports := []string{fmt.Sprintf("%d:%d", localPort, targetPort)}
+
+ var stdoutBuf bytes.Buffer
+ var stderrBuf bytes.Buffer
+
+ pf, err := portforward.New(dialer, ports, ctx.Done(), readyChan, &stdoutBuf, &stderrBuf)
+ if err != nil {
+ return fmt.Errorf("error creating portforward: %w", err)
+ }
+
+ errChan := make(chan error, 1)
+ go func() {
+ errChan <- pf.ForwardPorts()
+ }()
+
+ timer := time.NewTimer(30 * time.Second)
+ defer timer.Stop()
+
+ select {
+ case <-readyChan:
+ return nil
+ case err := <-errChan:
+ cancel()
+ return fmt.Errorf("port forwarding failed: %w", err)
+ case <-timer.C:
+ cancel()
+ return fmt.Errorf("timeout waiting for port-forward to be ready")
+ }
+}