Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

feat: support delete node #146

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/client/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
gatewayInferInstanceExecControlPlanePath = "/system/inference/%s/instance/%s/exec"
gatewayServerControlPlanePath = "/system/servers"
gatewayServerLabelCreateControlPlanePath = "/system/server/%s/labels"
gatewayServerNodeDeleteControlPlanePath = "/system/server/%s/delete"
gatewayNamespaceControlPlanePath = "/system/namespaces"
gatewayBuildControlPlanePath = "/system/build"
gatewayBuildInstanceControlPlanePath = "/system/build/%s"
Expand Down
26 changes: 26 additions & 0 deletions agent/client/server_node_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

package client

import (
"context"
"fmt"
"net/url"
)

// ServerLabelCreate create the labels for the servers.
func (cli *Client) ServerNodeDelete(ctx context.Context, name string) error {
urlValues := url.Values{}

resp, err := cli.delete(ctx,
fmt.Sprintf(gatewayServerNodeDeleteControlPlanePath, name), urlValues, nil, nil)
defer ensureReaderClosed(resp)

if err != nil {
return wrapResponseError(err, resp, "server-delete", name)
}

return wrapResponseError(err, resp, "server-delete", name)
}
21 changes: 21 additions & 0 deletions agent/pkg/runtime/server_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package runtime

import (
"context"

"github.com/tensorchord/openmodelz/agent/errdefs"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)


func (r Runtime) ServerDeleteNode(ctx context.Context, name string) error {
err := r.kubeClient.CoreV1().Nodes().Delete(ctx, name, metav1.DeleteOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return errdefs.NotFound(err)
}
return errdefs.System(err)
}
return nil
}
28 changes: 28 additions & 0 deletions agent/pkg/server/handler_server_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package server

import (
"errors"
"net/http"

"github.com/gin-gonic/gin"
)

// @Summary Delete a node from the cluster.
// @Description Delete a node.
// @Tags namespace
// @Param name path string true "Server Name"
// @Accept json
// @Produce json
// @Success 200
// @Router /system/server/{name}/delete [delete]
func (s *Server) handleServerDelete(c *gin.Context) error {
name := c.Param("name")
if name == "" {
return NewError(http.StatusBadRequest, errors.New("name is required"), "server-delete-node")
}
err := s.runtime.ServerDeleteNode(c.Request.Context(), name)
if err != nil {
return errFromErrDefs(err, "server-delete-node")
}
return nil
}
1 change: 1 addition & 0 deletions agent/pkg/server/server_init_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (s *Server) registerRoutes() {
// servers
controlPlane.GET(endpointServerPlural, WrapHandler(s.handleServerList))
controlPlane.POST(endpointServer+"/:name/labels", WrapHandler(s.handleServerLabelCreate))
controlPlane.DELETE(endpointServer+"/:name/delete", WrapHandler(s.handleServerDelete))

// logs
controlPlane.GET(endpointLogPlural+endpointInference,
Expand Down
1 change: 0 additions & 1 deletion mdz/hack/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

set -x
set -o errexit
set -o nounset
set -o pipefail
Expand Down
8 changes: 5 additions & 3 deletions mdz/pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func init() {
rootCmd.AddGroup(&cobra.Group{ID: "basic", Title: "Basic Commands:"})
rootCmd.AddGroup(&cobra.Group{ID: "debug", Title: "Troubleshooting and Debugging Commands:"})
rootCmd.AddGroup(&cobra.Group{ID: "management", Title: "Management Commands:"})

// telemetry
if err := telemetry.Initialize(!disableTelemetry); err != nil {
logrus.WithError(err).Debug("Failed to initialize telemetry")
}
}

func commandInit(cmd *cobra.Command, args []string) error {
Expand All @@ -94,9 +99,6 @@ func commandInit(cmd *cobra.Command, args []string) error {
}
}

if err := telemetry.Initialize(!disableTelemetry); err != nil {
logrus.WithError(err).Debug("Failed to initialize telemetry")
}
return nil
}

Expand Down
25 changes: 25 additions & 0 deletions mdz/pkg/cmd/server_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import "github.com/spf13/cobra"

var serverDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a node from the cluster",
Long: `Delete a node from the cluster`,
Example: ` mdz server delete gpu-node-1`,
PreRunE: commandInit,
Args: cobra.MinimumNArgs(1),
RunE: commandServerDelete,
}

func init() {
serverCmd.AddCommand(serverDeleteCmd)
}

func commandServerDelete(cmd *cobra.Command, args []string) error {
nodeName := args[0]
if err := agentClient.ServerNodeDelete(cmd.Context(), nodeName); err != nil {
return err
}
return nil
}
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def build_if_not_exist():
return
version = get_version()
print(f"build mdz from source ({version})")
subprocess.call(["make", "mdz"])
errno = subprocess.call(shlex.split(
f"make build-release GIT_TAG={version}"
), cwd="mdz")
Expand Down
Loading