Skip to content

Commit

Permalink
feat: allow multiple pods to be created / removed
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-singh committed Feb 9, 2023
1 parent 53baa35 commit fd88b4f
Show file tree
Hide file tree
Showing 27 changed files with 288 additions and 39 deletions.
2 changes: 2 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"cli/cmd/pod"
"cli/cmd/pods"

"github.com/spf13/cobra"
)
Expand All @@ -14,4 +15,5 @@ var createCmd = &cobra.Command{

func init() {
createCmd.AddCommand(pod.CreatePodCmd)
createCmd.AddCommand(pods.CreatePodsCmd)
}
9 changes: 4 additions & 5 deletions cmd/pod/createPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ var volumeInGb int
var volumeMountPath string

var CreatePodCmd = &cobra.Command{
Use: "pod",
Aliases: []string{"pods"},
Args: cobra.ExactArgs(0),
Short: "start a pod",
Long: "start a pod from runpod.io",
Use: "pod",
Args: cobra.ExactArgs(0),
Short: "start a pod",
Long: "start a pod from runpod.io",
Run: func(cmd *cobra.Command, args []string) {
input := &api.CreatePodInput{
ContainerDiskInGb: containerDiskInGb,
Expand Down
9 changes: 4 additions & 5 deletions cmd/pod/getPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import (
var AllFields bool

var GetPodCmd = &cobra.Command{
Use: "pod [podId]",
Aliases: []string{"pods"},
Args: cobra.MaximumNArgs(1),
Short: "get all pods",
Long: "get all pods or specify pod id",
Use: "pod [podId]",
Args: cobra.MaximumNArgs(1),
Short: "get all pods",
Long: "get all pods or specify pod id",
Run: func(cmd *cobra.Command, args []string) {
pods, err := api.GetPods()
cobra.CheckErr(err)
Expand Down
9 changes: 4 additions & 5 deletions cmd/pod/removePod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
)

var RemovePodCmd = &cobra.Command{
Use: "pod [podId]",
Aliases: []string{"pods"},
Args: cobra.ExactArgs(1),
Short: "remove a pod",
Long: "remove a pod from runpod.io",
Use: "pod [podId]",
Args: cobra.ExactArgs(1),
Short: "remove a pod",
Long: "remove a pod from runpod.io",
Run: func(cmd *cobra.Command, args []string) {
_, err := api.RemovePod(args[0])
cobra.CheckErr(err)
Expand Down
9 changes: 4 additions & 5 deletions cmd/pod/startPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
var bidPerGpu float32

var StartPodCmd = &cobra.Command{
Use: "pod [podId]",
Aliases: []string{"pods"},
Args: cobra.ExactArgs(1),
Short: "start a pod",
Long: "start a pod from runpod.io",
Use: "pod [podId]",
Args: cobra.ExactArgs(1),
Short: "start a pod",
Long: "start a pod from runpod.io",
Run: func(cmd *cobra.Command, args []string) {
var err error
var pod map[string]interface{}
Expand Down
9 changes: 4 additions & 5 deletions cmd/pod/stopPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
)

var StopPodCmd = &cobra.Command{
Use: "pod [podId]",
Aliases: []string{"pods"},
Args: cobra.ExactArgs(1),
Short: "stop a pod",
Long: "stop a pod from runpod.io",
Use: "pod [podId]",
Args: cobra.ExactArgs(1),
Short: "stop a pod",
Long: "stop a pod from runpod.io",
Run: func(cmd *cobra.Command, args []string) {
pod, err := api.StopPod(args[0])
cobra.CheckErr(err)
Expand Down
99 changes: 99 additions & 0 deletions cmd/pods/createPods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package pods

import (
"cli/api"
"fmt"
"strings"

"github.com/spf13/cobra"
)

var communityCloud bool
var containerDiskInGb int
var deployCost float32
var dockerArgs string
var env []string
var gpuCount int
var gpuTypeId string
var imageName string
var minMemoryInGb int
var minVcpuCount int
var name string
var podCount int
var ports []string
var secureCloud bool
var volumeInGb int
var volumeMountPath string

var CreatePodsCmd = &cobra.Command{
Use: "pods",
Args: cobra.ExactArgs(0),
Short: "create a group of pods",
Long: "create a group of pods on runpod.io",
Run: func(cmd *cobra.Command, args []string) {
input := &api.CreatePodInput{
ContainerDiskInGb: containerDiskInGb,
DeployCost: deployCost,
DockerArgs: dockerArgs,
GpuCount: gpuCount,
GpuTypeId: gpuTypeId,
ImageName: imageName,
MinMemoryInGb: minMemoryInGb,
MinVcpuCount: minVcpuCount,
Name: name,
VolumeInGb: volumeInGb,
VolumeMountPath: volumeMountPath,
}
if len(ports) > 0 {
input.Ports = strings.Join(ports, ",")
}
input.Env = make([]*api.PodEnv, len(env))
for i, v := range env {
e := strings.Split(v, "=")
if len(e) != 2 {
cobra.CheckErr(fmt.Errorf("wrong env value: %s", e))
}
input.Env[i] = &api.PodEnv{Key: e[0], Value: e[1]}
}
if secureCloud {
input.CloudType = "SECURE"
} else {
input.CloudType = "COMMUNITY"
}

for x := 0; x < podCount; x++ {
pod, err := api.CreatePod(input)
cobra.CheckErr(err)

if pod["desiredStatus"] == "RUNNING" {
fmt.Printf(`pod "%s" created for $%.3f / hr`, pod["id"], pod["costPerHr"])
fmt.Println()
} else {
cobra.CheckErr(fmt.Errorf(`pod "%s" start failed; status is %s`, args[0], pod["desiredStatus"]))
}
}
},
}

func init() {
CreatePodsCmd.Flags().BoolVar(&communityCloud, "communityCloud", false, "create in community cloud")
CreatePodsCmd.Flags().BoolVar(&secureCloud, "secureCloud", false, "create in secure cloud")
CreatePodsCmd.Flags().Float32Var(&deployCost, "cost", 0, "$/hr price ceiling, if not defined, pod will be created with lowest price available")
CreatePodsCmd.Flags().IntVar(&containerDiskInGb, "containerDiskSize", 20, "container disk size in GB")
CreatePodsCmd.Flags().IntVar(&gpuCount, "gpuCount", 1, "number of GPUs for the pod")
CreatePodsCmd.Flags().IntVar(&minMemoryInGb, "mem", 20, "minimum system memory needed")
CreatePodsCmd.Flags().IntVar(&minVcpuCount, "vcpu", 1, "minimum vCPUs needed")
CreatePodsCmd.Flags().IntVar(&podCount, "podCount", 1, "number of pods to create with the same name")
CreatePodsCmd.Flags().IntVar(&volumeInGb, "volumeSize", 1, "persistant volume disk size in GB")
CreatePodsCmd.Flags().StringSliceVar(&env, "env", nil, "container arguments")
CreatePodsCmd.Flags().StringSliceVar(&ports, "ports", nil, "ports to expose; max only 1 http and 1 tcp allowed; e.g. '8888/http'")
CreatePodsCmd.Flags().StringVar(&dockerArgs, "args", "", "container arguments")
CreatePodsCmd.Flags().StringVar(&gpuTypeId, "gpuType", "", "gpu type id, e.g. 'NVIDIA GeForce RTX 3090'")
CreatePodsCmd.Flags().StringVar(&imageName, "imageName", "", "container image name")
CreatePodsCmd.Flags().StringVar(&name, "name", "", "any pod name for easy reference")
CreatePodsCmd.Flags().StringVar(&volumeMountPath, "volumePath", "/runpod", "container volume path")

CreatePodsCmd.MarkFlagRequired("gpuType") //nolint
CreatePodsCmd.MarkFlagRequired("imageName") //nolint
CreatePodsCmd.MarkFlagRequired("name") //nolint
}
37 changes: 37 additions & 0 deletions cmd/pods/removePods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package pods

import (
"cli/api"
"fmt"

"github.com/spf13/cobra"
)

var RemovePodsCmd = &cobra.Command{
Use: "pods [name]",
Args: cobra.ExactArgs(1),
Short: "remove all pods using name",
Long: "remove all pods using name from runpod.io",
Run: func(cmd *cobra.Command, args []string) {
mypods, err := api.GetPods()
cobra.CheckErr(err)

removed := 0
for _, pod := range mypods {
if pod.Name == args[0] && removed < podCount {
_, err := api.RemovePod(pod.Id)
if err == nil {
removed++
}
cobra.CheckErr(err)
}
}

fmt.Printf(`%d pods removed with name "%s"`, removed, args[0])
fmt.Println()
},
}

func init() {
RemovePodsCmd.Flags().IntVar(&podCount, "podCount", 1, "number of pods to remove with the same name")
}
2 changes: 2 additions & 0 deletions cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"cli/cmd/pod"
"cli/cmd/pods"

"github.com/spf13/cobra"
)
Expand All @@ -14,4 +15,5 @@ var removeCmd = &cobra.Command{

func init() {
removeCmd.AddCommand(pod.RemovePodCmd)
removeCmd.AddCommand(pods.RemovePodsCmd)
}
4 changes: 3 additions & 1 deletion doc/runpodctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ runpodctl is a CLI tool to manage your pods for runpod.io
* [runpodctl config](runpodctl_config.md) - CLI Config
* [runpodctl create](runpodctl_create.md) - create a resource
* [runpodctl get](runpodctl_get.md) - get resource
* [runpodctl receive](runpodctl_receive.md) - receive file(s), or folder
* [runpodctl remove](runpodctl_remove.md) - remove a resource
* [runpodctl send](runpodctl_send.md) - send file(s), or folder
* [runpodctl start](runpodctl_start.md) - start a resource
* [runpodctl stop](runpodctl_stop.md) - stop a resource
* [runpodctl version](runpodctl_version.md) - runpodctl version

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
2 changes: 1 addition & 1 deletion doc/runpodctl_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ runpodctl config [flags]

* [runpodctl](runpodctl.md) - runpodctl for runpod.io

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
3 changes: 2 additions & 1 deletion doc/runpodctl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ create a resource in runpod.io

* [runpodctl](runpodctl.md) - runpodctl for runpod.io
* [runpodctl create pod](runpodctl_create_pod.md) - start a pod
* [runpodctl create pods](runpodctl_create_pods.md) - create a group of pods

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
2 changes: 1 addition & 1 deletion doc/runpodctl_create_pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ runpodctl create pod [flags]

* [runpodctl create](runpodctl_create.md) - create a resource

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
39 changes: 39 additions & 0 deletions doc/runpodctl_create_pods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## runpodctl create pods

create a group of pods

### Synopsis

create a group of pods on runpod.io

```
runpodctl create pods [flags]
```

### Options

```
--args string container arguments
--communityCloud create in community cloud
--containerDiskSize int container disk size in GB (default 20)
--cost float32 $/hr price ceiling, if not defined, pod will be created with lowest price available
--env strings container arguments
--gpuCount int number of GPUs for the pod (default 1)
--gpuType string gpu type id, e.g. 'NVIDIA GeForce RTX 3090'
-h, --help help for pods
--imageName string container image name
--mem int minimum system memory needed (default 20)
--name string any pod name for easy reference
--podCount int number of pods to create with the same name (default 1)
--ports strings ports to expose; max only 1 http and 1 tcp allowed; e.g. '8888/http'
--secureCloud create in secure cloud
--vcpu int minimum vCPUs needed (default 1)
--volumePath string container volume path (default "/runpod")
--volumeSize int persistant volume disk size in GB (default 1)
```

### SEE ALSO

* [runpodctl create](runpodctl_create.md) - create a resource

###### Auto generated by spf13/cobra on 8-Feb-2023
2 changes: 1 addition & 1 deletion doc/runpodctl_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ get resources for pods
* [runpodctl get cloud](runpodctl_get_cloud.md) - get all cloud gpus
* [runpodctl get pod](runpodctl_get_pod.md) - get all pods

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
2 changes: 1 addition & 1 deletion doc/runpodctl_get_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ runpodctl get cloud [gpuCount] [flags]

* [runpodctl get](runpodctl_get.md) - get resource

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
2 changes: 1 addition & 1 deletion doc/runpodctl_get_pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ runpodctl get pod [podId] [flags]

* [runpodctl get](runpodctl_get.md) - get resource

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
23 changes: 23 additions & 0 deletions doc/runpodctl_receive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## runpodctl receive

receive file(s), or folder

### Synopsis

receive file(s), or folder from pod or any computer

```
runpodctl receive [code] [flags]
```

### Options

```
-h, --help help for receive
```

### SEE ALSO

* [runpodctl](runpodctl.md) - runpodctl for runpod.io

###### Auto generated by spf13/cobra on 8-Feb-2023
3 changes: 2 additions & 1 deletion doc/runpodctl_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ remove a resource in runpod.io

* [runpodctl](runpodctl.md) - runpodctl for runpod.io
* [runpodctl remove pod](runpodctl_remove_pod.md) - remove a pod
* [runpodctl remove pods](runpodctl_remove_pods.md) - remove all pods using name

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
2 changes: 1 addition & 1 deletion doc/runpodctl_remove_pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ runpodctl remove pod [podId] [flags]

* [runpodctl remove](runpodctl_remove.md) - remove a resource

###### Auto generated by spf13/cobra on 12-Apr-2022
###### Auto generated by spf13/cobra on 8-Feb-2023
24 changes: 24 additions & 0 deletions doc/runpodctl_remove_pods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## runpodctl remove pods

remove all pods using name

### Synopsis

remove all pods using name from runpod.io

```
runpodctl remove pods [name] [flags]
```

### Options

```
-h, --help help for pods
--podCount int number of pods to remove with the same name (default 1)
```

### SEE ALSO

* [runpodctl remove](runpodctl_remove.md) - remove a resource

###### Auto generated by spf13/cobra on 8-Feb-2023
Loading

0 comments on commit fd88b4f

Please sign in to comment.