Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/command/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 56 additions & 0 deletions internal/command/create/imagepulljob.go
Original file line number Diff line number Diff line change
@@ -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)
}
8 changes: 7 additions & 1 deletion internal/command/deletecmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
26 changes: 26 additions & 0 deletions internal/command/deletecmd/imagepull.go
Original file line number Diff line number Diff line change
@@ -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)
}
26 changes: 26 additions & 0 deletions internal/command/deletecmd/imagepulljob.go
Original file line number Diff line number Diff line change
@@ -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)
}
53 changes: 53 additions & 0 deletions internal/command/list/imagepulljobs.go
Original file line number Diff line number Diff line change
@@ -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
}
54 changes: 54 additions & 0 deletions internal/command/list/imagepulls.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 7 additions & 1 deletion internal/command/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
31 changes: 31 additions & 0 deletions internal/controller/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,37 @@ func (controller *Controller) initAPI() *gin.Engine {
controller.appendVMEvents(c).Respond(c)
})

// Image pulls
v1.POST("/imagepulls", func(c *gin.Context) {
controller.createImagePull(c).Respond(c)
})
v1.PUT("/imagepulls/:name/state", func(c *gin.Context) {
controller.updateImagePullState(c).Respond(c)
})
v1.GET("/imagepulls/:name", func(c *gin.Context) {
controller.getImagePull(c).Respond(c)
})
v1.GET("/imagepulls", func(c *gin.Context) {
controller.listImagePulls(c).Respond(c)
})
v1.DELETE("/imagepulls/:name", func(c *gin.Context) {
controller.deleteImagePull(c).Respond(c)
})

// Image pull jobs
v1.POST("/imagepulljobs", func(c *gin.Context) {
controller.createImagePullJob(c).Respond(c)
})
v1.GET("/imagepulljobs/:name", func(c *gin.Context) {
controller.getImagePullJob(c).Respond(c)
})
v1.GET("/imagepulljobs", func(c *gin.Context) {
controller.listImagePullJobs(c).Respond(c)
})
v1.DELETE("/imagepulljobs/:name", func(c *gin.Context) {
controller.deleteImagePullJob(c).Respond(c)
})

return ginEngine
}

Expand Down
1 change: 1 addition & 0 deletions internal/controller/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (controller *Controller) controllerInfo(ctx *gin.Context) responder.Respond
capabilities := []v1pkg.ControllerCapability{
v1pkg.ControllerCapabilityRPCV1,
v1pkg.ControllerCapabilityVMStateEndpoint,
v1pkg.ControllerCapabilityImagePullResource,
}

if controller.experimentalRPCV2 {
Expand Down
Loading