Skip to content

Commit

Permalink
refact: move env to server (#1172)
Browse files Browse the repository at this point in the history
* refact: move env to server

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* mv service to status

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* upgrade server to 0.0.8

Signed-off-by: Keming <kemingyang@tensorchord.ai>

Signed-off-by: Keming <kemingyang@tensorchord.ai>
  • Loading branch information
kemingy committed Nov 9, 2022
1 parent bd869c6 commit dd9dd30
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/tensorchord/envd-server v0.0.7
github.com/tensorchord/envd-server v0.0.8
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f
github.com/urfave/cli/v2 v2.23.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tensorchord/envd-server v0.0.7 h1:9fSY+lbKYXJwEz9ju+OAvdoVKjqX6JPy5DGR37iPSXQ=
github.com/tensorchord/envd-server v0.0.7/go.mod h1:dVHjUZoyZ8VbYEz0wGzk+tdAEQ7u5Ri4y6prh/+xtn0=
github.com/tensorchord/envd-server v0.0.8 h1:Jz4trht+3XgsUZvTLPmNwBEUy1BR61MXP3PAXB2CjcE=
github.com/tensorchord/envd-server v0.0.8/go.mod h1:dVHjUZoyZ8VbYEz0wGzk+tdAEQ7u5Ri4y6prh/+xtn0=
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
12 changes: 6 additions & 6 deletions pkg/app/env_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ func renderEnvironments(envs []types.EnvdEnvironment, w io.Writer) {
envRow[0] = env.Name
envRow[1] = endpointOrNone(env)
envRow[2] = fmt.Sprintf("%s.envd", env.Name)
envRow[3] = env.Image
envRow[3] = env.Spec.Image
envRow[4] = strconv.FormatBool(env.GPU)
envRow[5] = stringOrNone(env.CUDA)
envRow[6] = stringOrNone(env.CUDNN)
envRow[7] = env.Status
envRow[7] = env.Status.Phase
table.Append(envRow)
}
table.Render()
}

func endpointOrNone(env types.EnvdEnvironment) string {
var res strings.Builder
if env.JupyterAddr != nil {
res.WriteString(fmt.Sprintf("jupyter: %s", *env.JupyterAddr))
if env.Status.JupyterAddr != nil {
res.WriteString(fmt.Sprintf("jupyter: %s", *env.Status.JupyterAddr))
}
if env.RStudioServerAddr != nil {
res.WriteString(fmt.Sprintf("rstudio: %s", *env.RStudioServerAddr))
if env.Status.RStudioServerAddr != nil {
res.WriteString(fmt.Sprintf("rstudio: %s", *env.Status.RStudioServerAddr))
}
return res.String()
}
30 changes: 10 additions & 20 deletions pkg/types/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,15 @@ var BaseAptPackage = []string{
}

type EnvdImage struct {
servertypes.ImageMeta
servertypes.ImageMeta `json:",inline,omitempty"`

EnvdManifest `json:",inline,omitempty"`
}

type EnvdEnvironment struct {
Image string `json:"image,omitempty"`
Name string `json:"name,omitempty"`
servertypes.Environment `json:",inline,omitempty"`

Status string `json:"status,omitempty"`
JupyterAddr *string `json:"jupyter_addr,omitempty"`
RStudioServerAddr *string `json:"rstudio_server_addr,omitempty"`
EnvdManifest `json:",inline,omitempty"`
EnvdManifest `json:",inline,omitempty"`
}

type EnvdManifest struct {
Expand Down Expand Up @@ -206,17 +202,19 @@ func NewImageFromMeta(meta servertypes.ImageMeta) (*EnvdImage, error) {

func NewEnvironmentFromContainer(ctr types.Container) (*EnvdEnvironment, error) {
env := EnvdEnvironment{
Image: ctr.Image,
Status: ctr.Status,
Environment: servertypes.Environment{
Spec: servertypes.EnvironmentSpec{Image: ctr.Image},
Status: servertypes.EnvironmentStatus{Phase: ctr.Status},
},
}
if name, ok := ctr.Labels[ContainerLabelName]; ok {
env.Name = name
}
if jupyterAddr, ok := ctr.Labels[ContainerLabelJupyterAddr]; ok {
env.JupyterAddr = &jupyterAddr
env.Status.JupyterAddr = &jupyterAddr
}
if rstudioServerAddr, ok := ctr.Labels[ContainerLabelRStudioServerAddr]; ok {
env.RStudioServerAddr = &rstudioServerAddr
env.Status.RStudioServerAddr = &rstudioServerAddr
}

m, err := newManifest(ctr.Labels)
Expand All @@ -229,15 +227,7 @@ func NewEnvironmentFromContainer(ctr types.Container) (*EnvdEnvironment, error)

func NewEnvironmentFromServer(ctr servertypes.Environment) (*EnvdEnvironment, error) {
env := EnvdEnvironment{
Image: ctr.Spec.Image,
Status: ctr.Status.Phase,
Name: ctr.Name,
}
if jupyterAddr, ok := ctr.Labels[ContainerLabelJupyterAddr]; ok {
env.JupyterAddr = &jupyterAddr
}
if rstudioServerAddr, ok := ctr.Labels[ContainerLabelRStudioServerAddr]; ok {
env.RStudioServerAddr = &rstudioServerAddr
Environment: ctr,
}

m, err := newManifest(ctr.Labels)
Expand Down

0 comments on commit dd9dd30

Please sign in to comment.