-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow multiple pods to be created / removed
- Loading branch information
1 parent
53baa35
commit fd88b4f
Showing
27 changed files
with
288 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.