Skip to content

Commit

Permalink
feat: support config shm size (#176)
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <[email protected]>
kemingy authored Jan 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f9e9d26 commit f39e69f
Showing 12 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions api/types/environment.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ type ResourceSpec struct {
CPU string `json:"cpu,omitempty"`
Memory string `json:"memory,omitempty"`
GPU string `json:"gpu,omitempty"`
Shm string `json:"shm,omitempty"`
}

type ObjectMeta struct {
4 changes: 2 additions & 2 deletions cmd/envd-server/main.go
Original file line number Diff line number Diff line change
@@ -44,8 +44,8 @@ func handleErr(err error) {
// @license.url https://mozilla.org/MPL/2.0/

// @securitydefinitions.apikey Authentication
// @in header
// @name JWT
// @in header
// @name JWT

// @host localhost:8080
// @BasePath /api/v1
3 changes: 3 additions & 0 deletions pkg/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1035,6 +1035,9 @@ const docTemplate = `{
},
"memory": {
"type": "string"
},
"shm": {
"type": "string"
}
}
}
2 changes: 2 additions & 0 deletions pkg/runtime/kubernetes/const.go
Original file line number Diff line number Diff line change
@@ -6,4 +6,6 @@ package kubernetes

const (
ResourceNvidiaGPU = "nvidia.com/gpu"
ResourceShm = "shm"
ResourceShmPath = "/dev/shm"
)
21 changes: 21 additions & 0 deletions pkg/runtime/kubernetes/environment_create.go
Original file line number Diff line number Diff line change
@@ -157,6 +157,27 @@ func (p generalProvisioner) EnvironmentCreate(ctx context.Context,
})
}

if env.Resources.Shm != "" {
shm, err := resource.ParseQuantity(env.Resources.Shm)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse shm resource: %s", env.Resources.Shm)
}
logrus.Debugf("configure shared memory to %s", env.Resources.Shm)
expectedPod.Spec.Volumes = append(expectedPod.Spec.Volumes, v1.Volume{
Name: ResourceShm,
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{
Medium: "Memory",
SizeLimit: &shm,
},
},
})
expectedPod.Spec.Containers[0].VolumeMounts = append(expectedPod.Spec.Containers[0].VolumeMounts, v1.VolumeMount{
Name: ResourceShm,
MountPath: ResourceShmPath,
})
}

if p.imagePullSecretName != nil {
expectedPod.Spec.ImagePullSecrets = []v1.LocalObjectReference{
{
6 changes: 3 additions & 3 deletions pkg/server/environment_create.go
Original file line number Diff line number Diff line change
@@ -19,9 +19,9 @@ import (
// @Tags environment
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Param request body types.EnvironmentCreateRequest true "query params"
// @Success 201 {object} types.EnvironmentCreateResponse
// @Param login_name path string true "login name" example("alice")
// @Param request body types.EnvironmentCreateRequest true "query params"
// @Success 201 {object} types.EnvironmentCreateResponse
// @Router /users/{login_name}/environments [post]
func (s Server) environmentCreate(c *gin.Context) error {
owner := c.GetString(ContextLoginName)
6 changes: 3 additions & 3 deletions pkg/server/environment_get.go
Original file line number Diff line number Diff line change
@@ -19,9 +19,9 @@ import (
// @Tags environment
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Param name path string true "environment name" example("pytorch-example")
// @Success 200 {object} types.EnvironmentGetResponse
// @Param login_name path string true "login name" example("alice")
// @Param name path string true "environment name" example("pytorch-example")
// @Success 200 {object} types.EnvironmentGetResponse
// @Router /users/{login_name}/environments/{name} [get]
func (s Server) environmentGet(c *gin.Context) error {
owner := c.GetString(ContextLoginName)
4 changes: 2 additions & 2 deletions pkg/server/environment_list.go
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ import (
// @Tags environment
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Success 200 {object} types.EnvironmentListResponse
// @Param login_name path string true "login name" example("alice")
// @Success 200 {object} types.EnvironmentListResponse
// @Router /users/{login_name}/environments [get]
func (s Server) environmentList(c *gin.Context) error {
owner := c.GetString(ContextLoginName)
6 changes: 3 additions & 3 deletions pkg/server/environment_remove.go
Original file line number Diff line number Diff line change
@@ -19,9 +19,9 @@ import (
// @Tags environment
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Param name path string true "environment name" example("pytorch-example")
// @Success 200 {object} types.EnvironmentRemoveResponse
// @Param login_name path string true "login name" example("alice")
// @Param name path string true "environment name" example("pytorch-example")
// @Success 200 {object} types.EnvironmentRemoveResponse
// @Router /users/{login_name}/environments/{name} [delete]
func (s *Server) environmentRemove(c *gin.Context) error {
owner := c.GetString(ContextLoginName)
6 changes: 3 additions & 3 deletions pkg/server/image_get.go
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ import (
// @Tags image
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Param name path string true "digest" example("python-example")
// @Success 200 {object} types.ImageGetResponse
// @Param login_name path string true "login name" example("alice")
// @Param name path string true "digest" example("python-example")
// @Success 200 {object} types.ImageGetResponse
// @Router /users/{login_name}/images/{name} [get]
func (s *Server) imageGet(c *gin.Context) error {
owner := c.GetString(ContextLoginName)
4 changes: 2 additions & 2 deletions pkg/server/image_list.go
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ import (
// @Tags image
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Success 200 {object} types.ImageListResponse
// @Param login_name path string true "login name" example("alice")
// @Success 200 {object} types.ImageListResponse
// @Router /users/{login_name}/images [get]
func (s *Server) imageList(c *gin.Context) error {
owner := c.GetString(ContextLoginName)
6 changes: 3 additions & 3 deletions pkg/server/key_create.go
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ import (
// @Tags key
// @Accept json
// @Produce json
// @Param login_name path string true "login name" example("alice")
// @Param request body types.KeyCreateRequest true "query params"
// @Success 201 {object} types.KeyCreateResponse
// @Param login_name path string true "login name" example("alice")
// @Param request body types.KeyCreateRequest true "query params"
// @Success 201 {object} types.KeyCreateResponse
// @Router /users/{login_name}/keys [post]
func (s Server) keyCreate(c *gin.Context) error {
owner := c.GetString(ContextLoginName)

0 comments on commit f39e69f

Please sign in to comment.