mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* Update proto to add namespace * Update apiserver to add namespace * Update cli * Make namespace a part of of the get/delete request url path * Update proto and reconstruct request url path * Update API server to ensure namespace is required for cluster ops * Update CLI to ensure namespace is a required flag for cluster opss * Update docs * Add ListAllClusters endpoint * Validate requests in GRPC layer instead of resource manager layer
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package cluster
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/ray-project/kuberay/cli/pkg/cmdutil"
|
|
"github.com/ray-project/kuberay/proto/go_client"
|
|
"github.com/spf13/cobra"
|
|
"k8s.io/klog/v2"
|
|
)
|
|
|
|
type DeleteOptions struct {
|
|
namespace string
|
|
}
|
|
|
|
func newCmdDelete() *cobra.Command {
|
|
opts := DeleteOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "delete <cluster name>",
|
|
Short: "Delete a ray cluster by name",
|
|
Args: cobra.MaximumNArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return deleteCluster(args[0], opts)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVarP(&opts.namespace, "namespace", "n", "",
|
|
"kubernetes namespace where the cluster is provisioned")
|
|
if err := cmd.MarkFlagRequired("namespace"); err != nil {
|
|
klog.Warning(err)
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func deleteCluster(name string, opts DeleteOptions) error {
|
|
// Get gRPC connection
|
|
conn, err := cmdutil.GetGrpcConn()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer conn.Close()
|
|
|
|
// build gRPC client
|
|
client := go_client.NewClusterServiceClient(conn)
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
request := &go_client.DeleteClusterRequest{
|
|
Name: name,
|
|
Namespace: opts.namespace,
|
|
}
|
|
if _, err := client.DeleteCluster(ctx, request); err != nil {
|
|
log.Fatalf("could not delete cluster %v", err)
|
|
}
|
|
|
|
log.Printf("cluster %v has been deleted", name)
|
|
return nil
|
|
}
|