mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-08 16:01:20 +02:00
Always require a client for running a worker (#52)
* Always require a client for running a worker * Actually validate roles * Delete worker Fixes #46 * Update internal/worker/worker.go Co-authored-by: Nikolay Edigaryev <edigaryev@gmail.com> --------- Co-authored-by: Nikolay Edigaryev <edigaryev@gmail.com>
This commit is contained in:
co-authored by
Nikolay Edigaryev
parent
af074f499d
commit
362ea85b4f
@@ -10,7 +10,7 @@ func NewCommand() *cobra.Command {
|
||||
Short: "Delete resources from the controller",
|
||||
}
|
||||
|
||||
command.AddCommand(newDeleteVMCommand(), newDeleteServiceComandCommand())
|
||||
command.AddCommand(newDeleteVMCommand(), newDeleteServiceComandCommand(), newDeleteWorkerCommand())
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package deletecmd
|
||||
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newDeleteWorkerCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "worker NAME",
|
||||
Short: "Delete a worker",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runDeleteWorker,
|
||||
}
|
||||
}
|
||||
|
||||
func runDeleteWorker(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return client.Workers().Delete(cmd.Context(), name)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package dev
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/internal/controller"
|
||||
"github.com/cirruslabs/orchard/internal/worker"
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
@@ -80,7 +81,11 @@ func CreateDevControllerAndWorker(devDataDirPath string) (*controller.Controller
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
devWorker, err := worker.New(worker.WithDataDirPath(devDataDirPath), worker.WithLogger(logger))
|
||||
defaultClient, err := client.New()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
devWorker, err := worker.New(defaultClient, worker.WithLogger(logger))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func runWorker(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
workerInstance, err := worker.New(worker.WithClient(controllerClient), worker.WithLogger(logger))
|
||||
workerInstance, err := worker.New(controllerClient, worker.WithLogger(logger))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user