Skip to content

Commit

Permalink
feat: Update env client to support multiple envs (#1052)
Browse files Browse the repository at this point in the history
* feat: Update env client to support multiple envs

Signed-off-by: Ce Gao <cegao@tensorchord.ai>

* chore: Update vendor

Signed-off-by: Ce Gao <cegao@tensorchord.ai>

* fix: Update envd-server

Signed-off-by: Ce Gao <cegao@tensorchord.ai>

Signed-off-by: Ce Gao <cegao@tensorchord.ai>
  • Loading branch information
gaocegege committed Oct 20, 2022
1 parent 711dfb2 commit 044d89e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 97 deletions.
18 changes: 4 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/tensorchord/envd
go 1.18

require (
github.com/Pallinder/go-randomdata v1.2.0
github.com/alessio/shellescape v1.4.1
github.com/cockroachdb/errors v1.9.0
github.com/containerd/console v1.0.3
Expand All @@ -20,15 +21,15 @@ require (
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/morikuni/aec v1.0.0
github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo/v2 v2.3.1
github.com/onsi/gomega v1.22.1
github.com/onsi/ginkgo/v2 v2.2.0
github.com/onsi/gomega v1.21.1
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc1
github.com/pkg/sftp v1.13.5
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
github.com/tensorchord/envd-server v0.0.4
github.com/tensorchord/envd-server v0.0.5
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f
github.com/urfave/cli/v2 v2.20.2
Expand All @@ -37,22 +38,11 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.0.0-20220919170432-7a66f970e087
golang.org/x/time v0.0.0-20220920022843-2ce7c2934d45
k8s.io/api v0.25.3
)

require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473 // indirect
github.com/pkg/errors v0.9.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/apimachinery v0.25.3 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

require (
Expand Down
38 changes: 8 additions & 30 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v
github.com/Microsoft/hcsshim v0.8.10/go.mod h1:g5uw8EV2mAlzqe94tfNBNdr89fnbD/n3HV0OhsddkmM=
github.com/Microsoft/hcsshim v0.9.2 h1:wB06W5aYFfUB3IvootYAY2WnOmIdgPGfqSI6tufQNnY=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Pallinder/go-randomdata v1.2.0 h1:DZ41wBchNRb/0GfsePLiSwb0PHZmT67XY00lCDlaYPg=
github.com/Pallinder/go-randomdata v1.2.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
Expand Down Expand Up @@ -235,8 +237,6 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -313,8 +313,6 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -377,8 +375,6 @@ github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c/go.m
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
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/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
Expand Down Expand Up @@ -468,12 +464,9 @@ github.com/moby/term v0.0.0-20201110203204-bea5bbe245bf/go.mod h1:FBS0z0QWA44HXy
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 h1:dcztxKSvZ4Id8iPpHERQBbIJfabdt4wUm5qy3wOL2Zc=
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
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=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
Expand All @@ -498,12 +491,12 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8=
github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys=
github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI=
github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.22.1 h1:pY8O4lBfsHKZHM/6nrxkhVPUznOlIu3quZcKP/M20KI=
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM=
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473 h1:J1QZwDXgZ4dJD2s19iqR9+U00OWM2kDzbf1O/fmvCWg=
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -582,7 +575,6 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
Expand Down Expand Up @@ -618,6 +610,8 @@ github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNG
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tensorchord/envd-server v0.0.4 h1:4RkSchgzxqhWGI9vAfYuUPtLWlPTK/FkELXGqsQmy+k=
github.com/tensorchord/envd-server v0.0.4/go.mod h1:V76OpMczrgBeu19K+rgFqSf4ZK3DXo/U82/0xel/jYg=
github.com/tensorchord/envd-server v0.0.5 h1:tbkMU79PTp8OONFwD4uGGQSpOY//gUouCWs1z5d+74s=
github.com/tensorchord/envd-server v0.0.5/go.mod h1:V76OpMczrgBeu19K+rgFqSf4ZK3DXo/U82/0xel/jYg=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tonistiigi/fsutil v0.0.0-20220115021204-b19f7f9cb274 h1:wbyZxD6IPFp0sl5uscMOJRsz5UKGFiNiD16e+MVfKZY=
github.com/tonistiigi/fsutil v0.0.0-20220115021204-b19f7f9cb274/go.mod h1:oPAfvw32vlUJSjyDcQ3Bu0nb2ON2B+G0dtVN/SZNJiA=
Expand Down Expand Up @@ -1097,8 +1091,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down Expand Up @@ -1134,20 +1126,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.25.3 h1:Q1v5UFfYe87vi5H7NU0p4RXC26PPMT8KOpr1TLQbCMQ=
k8s.io/api v0.25.3/go.mod h1:o42gKscFrEVjHdQnyRenACrMtbuJsVdP+WVjqejfzmI=
k8s.io/apimachinery v0.25.3 h1:7o9ium4uyUOM76t6aunP0nZuex7gDf8VGwkR5RcJnQc=
k8s.io/apimachinery v0.25.3/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73 h1:H9TCJUUx+2VA0ZiD9lvtaX8fthFsMoD+Izn93E/hm8U=
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
29 changes: 25 additions & 4 deletions pkg/app/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
package app

import (
"strings"
"time"

"github.com/Pallinder/go-randomdata"
"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/tensorchord/envd-server/sshname"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/envd"
Expand All @@ -42,6 +45,10 @@ var CommandCreate = &cli.Command{
DefaultText: "PROJECT:dev",
Required: true,
},
&cli.StringFlag{
Name: "name",
Usage: "environment name",
},
&cli.DurationFlag{
Name: "timeout",
Usage: "Timeout of container creation",
Expand Down Expand Up @@ -76,9 +83,14 @@ func create(clicontext *cli.Context) error {
return err
}

name := clicontext.String("name")
if name == "" {
name = strings.ToLower(randomdata.SillyName())
}
opt := envd.StartOptions{
Image: clicontext.String("image"),
Timeout: clicontext.Duration("timeout"),
Image: clicontext.String("image"),
Timeout: clicontext.Duration("timeout"),
EnvironmentName: name,
}
if c.Runner == types.RunnerTypeEnvdServer {
opt.EnvdServerSource = &envd.EnvdServerSource{}
Expand All @@ -96,26 +108,35 @@ func create(clicontext *cli.Context) error {
return errors.Wrap(err, "failed to get the ssh hostname")
}

ac, err := home.GetManager().AuthGetCurrent()
if err != nil {
return errors.Wrap(err, "failed to get the auth information")
}
username, err := sshname.Username(ac.IdentityToken, res.Name)
if err != nil {
return errors.Wrap(err, "failed to get the username")
}
eo := sshconfig.EntryOptions{
Name: res.Name,
IFace: hostname,
Port: res.SSHPort,
PrivateKeyPath: clicontext.Path("private-key"),
EnableHostKeyCheck: false,
EnableAgentForward: false,
User: res.Name,
User: username,
}
if err = sshconfig.AddEntry(eo); err != nil {
logrus.Infof("failed to add entry %s to your SSH config file: %s", res.Name, err)
return errors.Wrap(err, "failed to add entry to your SSH config file")
}

// TODO(gaocegege): Test why it fails.
if !clicontext.Bool("detach") {
opt := ssh.DefaultOptions()
opt.PrivateKeyPath = clicontext.Path("private-key")
opt.Port = res.SSHPort
opt.AgentForwarding = false
opt.User = res.Name
opt.User = username
opt.Server = hostname

sshClient, err := ssh.NewClient(opt)
Expand Down
74 changes: 32 additions & 42 deletions pkg/envd/envdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
servertypes "github.com/tensorchord/envd-server/api/types"
"github.com/tensorchord/envd-server/client"
"github.com/tensorchord/envd-server/errdefs"
v1 "k8s.io/api/core/v1"

"github.com/tensorchord/envd/pkg/types"
)
Expand Down Expand Up @@ -67,47 +66,42 @@ func (e *envdServerEngine) ResumeEnvironment(ctx context.Context, env string) (s
}

func (e *envdServerEngine) ListEnvironment(ctx context.Context) ([]types.EnvdEnvironment, error) {
req := servertypes.EnvironmentListRequest{
IdentityToken: e.IdentityToken,
}

ctr, err := e.EnvironmentList(ctx, req)
env, err := e.EnvironmentList(ctx, e.IdentityToken)
if err != nil {
return nil, errors.Wrap(err, "failed to get environment")
}
env, err := types.NewEnvironmentFromPod(ctr.Pod)
if err != nil {
return nil, errors.Wrap(err, "failed to create env from the container")
res := []types.EnvdEnvironment{}
for _, e := range env.Items {
env, err := types.NewEnvironmentFromServer(e)
if err != nil {
return nil, errors.Wrap(err, "failed to create env from the container")
}
res = append(res, *env)
}
return []types.EnvdEnvironment{*env}, nil
}

func (e *envdServerEngine) ListEnvDependency(ctx context.Context, env string) (*types.Dependency, error) {
req := servertypes.EnvironmentListRequest{
IdentityToken: e.IdentityToken,
}
return res, nil
}

func (e *envdServerEngine) ListEnvDependency(
ctx context.Context, name string) (*types.Dependency, error) {
logger := logrus.WithFields(logrus.Fields{
"env": env,
"env": name,
})
logger.Debug("getting dependencies")
ctr, err := e.EnvironmentList(ctx, req)
env, err := e.EnvironmentGet(ctx, e.IdentityToken, name)
if err != nil {
return nil, errors.Wrap(err, "failed to get environment")
}
dep, err := types.NewDependencyFromLabels(ctr.Pod.Annotations)
dep, err := types.NewDependencyFromLabels(env.Labels)
if err != nil {
return nil, errors.Wrap(err, "failed to create dependency from the container")
}
return dep, nil
}

func (e *envdServerEngine) ListEnvPortBinding(ctx context.Context, env string) ([]types.PortBinding, error) {
req := servertypes.EnvironmentListRequest{
IdentityToken: e.IdentityToken,
}

_, err := e.EnvironmentList(ctx, req)
func (e *envdServerEngine) ListEnvPortBinding(
ctx context.Context, name string) ([]types.PortBinding, error) {
_, err := e.EnvironmentGet(ctx, e.IdentityToken, name)
if err != nil {
return nil, errors.Wrap(err, "failed to get environment")
}
Expand All @@ -132,10 +126,7 @@ func (e *envdServerEngine) CleanEnvdIfExists(ctx context.Context, name string, f
return nil
}

req := servertypes.EnvironmentRemoveRequest{
IdentityToken: e.IdentityToken,
}
return e.EnvironmentRemove(ctx, req)
return e.EnvironmentRemove(ctx, e.IdentityToken, name)
}

// StartEnvd creates the container for the given tag and container name.
Expand All @@ -145,11 +136,17 @@ func (e *envdServerEngine) StartEnvd(ctx context.Context, so StartOptions) (*Sta
}

req := servertypes.EnvironmentCreateRequest{
IdentityToken: e.IdentityToken,
Image: so.Image,
Environment: servertypes.Environment{
ObjectMeta: servertypes.ObjectMeta{
Name: so.EnvironmentName,
},
Spec: servertypes.EnvironmentSpec{
Image: so.Image,
},
},
}

resp, err := e.EnvironmentCreate(ctx, req)
resp, err := e.EnvironmentCreate(ctx, e.IdentityToken, req)
if err != nil {
return nil, errors.Wrap(err, "failed to create the environment")
}
Expand All @@ -168,23 +165,16 @@ func (e *envdServerEngine) StartEnvd(ctx context.Context, so StartOptions) (*Sta
}

func (e *envdServerEngine) IsRunning(ctx context.Context, name string) (bool, error) {
req := servertypes.EnvironmentListRequest{
IdentityToken: e.IdentityToken,
}

resp, err := e.EnvironmentList(ctx, req)
resp, err := e.EnvironmentGet(ctx, e.IdentityToken, name)
if err != nil {
return false, errors.Wrap(err, "failed to list the environment")
}
return resp.Pod.Status.Phase == v1.PodRunning, nil
// "Running" is hard-coded here.
return resp.Status.Phase == "Running", nil
}

func (e *envdServerEngine) Exists(ctx context.Context, name string) (bool, error) {
req := servertypes.EnvironmentListRequest{
IdentityToken: e.IdentityToken,
}

_, err := e.EnvironmentList(ctx, req)
_, err := e.EnvironmentGet(ctx, e.IdentityToken, name)
if err != nil {
if errdefs.IsNotFound(err) {
return false, nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ type generalClient struct {
}

func NewClient(opt Options) (Client, error) {
logrus.WithFields(logrus.Fields{
"user": opt.User,
"port": opt.Port,
"server": opt.Server,
"agent-forwarding": opt.AgentForwarding,
"auth": opt.Auth,
}).Debug("ssh to the environment")

config := &ssh.ClientConfig{
User: opt.User,
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
Expand Down
Loading

0 comments on commit 044d89e

Please sign in to comment.