mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-18 04:43:12 +02:00
Ability to pre-pull VM images by targeting workers with labels
This commit is contained in:
@@ -10,7 +10,11 @@ func NewCommand() *cobra.Command {
|
||||
Short: "Create resources on the controller",
|
||||
}
|
||||
|
||||
command.AddCommand(newCreateVMCommand(), newCreateServiceAccount())
|
||||
command.AddCommand(
|
||||
newCreateVMCommand(),
|
||||
newCreateServiceAccount(),
|
||||
newCreateImagePullJob(),
|
||||
)
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package create
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/cirruslabs/orchard/internal/simplename"
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newCreateImagePullJob() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "imagepulljob NAME",
|
||||
Short: "Create an image pull job",
|
||||
RunE: runCreateImagePullJob,
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
|
||||
command.Flags().StringVar(&image, "image", "",
|
||||
"image to pull")
|
||||
command.Flags().StringToStringVar(&labels, "labels", map[string]string{},
|
||||
"labels required by this image pull job")
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func runCreateImagePullJob(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
// Issue a warning if the name used will be invalid in the future
|
||||
if err := simplename.ValidateNext(name); err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "WARNING: %v\n", err)
|
||||
}
|
||||
|
||||
// Validate command-line arguments
|
||||
if image == "" {
|
||||
return fmt.Errorf("please specify an \"--image\" to pull")
|
||||
}
|
||||
|
||||
imagePullJob := &v1.ImagePullJob{
|
||||
Meta: v1.Meta{
|
||||
Name: name,
|
||||
},
|
||||
Image: image,
|
||||
Labels: labels,
|
||||
}
|
||||
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return client.ImagePullJobs().Create(cmd.Context(), imagePullJob)
|
||||
}
|
||||
@@ -10,7 +10,13 @@ func NewCommand() *cobra.Command {
|
||||
Short: "Delete resources from the controller",
|
||||
}
|
||||
|
||||
command.AddCommand(newDeleteVMCommand(), newDeleteServiceComandCommand(), newDeleteWorkerCommand())
|
||||
command.AddCommand(
|
||||
newDeleteVMCommand(),
|
||||
newDeleteServiceComandCommand(),
|
||||
newDeleteWorkerCommand(),
|
||||
newDeleteImagePullCommand(),
|
||||
newDeleteImagePullJobCommand(),
|
||||
)
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package deletecmd
|
||||
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newDeleteImagePullCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "imagepull NAME",
|
||||
Short: "Delete an image pull",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runDeleteImagePull,
|
||||
}
|
||||
}
|
||||
|
||||
func runDeleteImagePull(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return client.ImagePulls().Delete(cmd.Context(), name)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package deletecmd
|
||||
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newDeleteImagePullJobCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "imagepulljob NAME",
|
||||
Short: "Delete an image pull job",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runDeleteImagePullJob,
|
||||
}
|
||||
}
|
||||
|
||||
func runDeleteImagePullJob(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return client.ImagePullJobs().Delete(cmd.Context(), name)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/gosuri/uitable"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newListImagePullJobsCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "imagepulljobs",
|
||||
Short: "List image pull jobs",
|
||||
RunE: runListImagePullJobs,
|
||||
}
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func runListImagePullJobs(cmd *cobra.Command, args []string) error {
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
imagePullJobs, err := client.ImagePullJobs().List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if quiet {
|
||||
for _, imagePullJob := range imagePullJobs {
|
||||
fmt.Println(imagePullJob.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
table := uitable.New()
|
||||
table.Wrap = true
|
||||
|
||||
table.AddRow("Name", "Image", "Labels", "Progressing", "Succeeded", "Failed", "Total")
|
||||
|
||||
for _, imagePullJob := range imagePullJobs {
|
||||
table.AddRow(imagePullJob.Name, imagePullJob.Image, imagePullJob.Labels, imagePullJob.Progressing,
|
||||
imagePullJob.Succeeded, imagePullJob.Failed, imagePullJob.Total)
|
||||
}
|
||||
|
||||
fmt.Println(table)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"github.com/gosuri/uitable"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newListImagePullsCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "imagepulls",
|
||||
Short: "List image pulls",
|
||||
RunE: runListImagePulls,
|
||||
}
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func runListImagePulls(cmd *cobra.Command, args []string) error {
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
imagePulls, err := client.ImagePulls().List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if quiet {
|
||||
for _, imagePull := range imagePulls {
|
||||
fmt.Println(imagePull.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
table := uitable.New()
|
||||
table.Wrap = true
|
||||
|
||||
table.AddRow("Name", "Image", "Worker", "Conditions")
|
||||
|
||||
for _, imagePullJob := range imagePulls {
|
||||
table.AddRow(imagePullJob.Name, imagePullJob.Image, imagePullJob.Worker,
|
||||
v1.ConditionsHumanize(imagePullJob.Conditions))
|
||||
}
|
||||
|
||||
fmt.Println(table)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -12,7 +12,13 @@ func NewCommand() *cobra.Command {
|
||||
Short: "List resources on the controller",
|
||||
}
|
||||
|
||||
command.AddCommand(newListWorkersCommand(), newListVMsCommand(), newListServiceAccountsCommand())
|
||||
command.AddCommand(
|
||||
newListWorkersCommand(),
|
||||
newListVMsCommand(),
|
||||
newListServiceAccountsCommand(),
|
||||
newListImagePullsCommand(),
|
||||
newListImagePullJobsCommand(),
|
||||
)
|
||||
|
||||
command.Flags().BoolVarP(&quiet, "", "q", false, "only show resource names")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user