Ability to pre-pull VM images by targeting workers with labels

This commit is contained in:
Nikolay Edigaryev
2025-12-10 20:43:34 +01:00
parent 173a34b083
commit aa36ad4cb6
29 changed files with 1463 additions and 8 deletions
+5 -1
View File
@@ -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
}
+56
View File
@@ -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)
}