diff --git a/cmd/machine/create.go b/cmd/machine/create.go index 473b80789..6f4028ce4 100644 --- a/cmd/machine/create.go +++ b/cmd/machine/create.go @@ -4,7 +4,6 @@ import ( "context" "github.com/skevetter/devpod/cmd/flags" - "github.com/skevetter/devpod/pkg/client" "github.com/skevetter/devpod/pkg/config" "github.com/skevetter/devpod/pkg/workspace" "github.com/skevetter/log" @@ -52,7 +51,7 @@ func (cmd *CreateCmd) Run(ctx context.Context, args []string) error { return err } - err = machineClient.Create(ctx, client.CreateOptions{}) + err = machineClient.Create(ctx) if err != nil { return err } diff --git a/cmd/machine/start.go b/cmd/machine/start.go index 78085bad6..ec4e0d77c 100644 --- a/cmd/machine/start.go +++ b/cmd/machine/start.go @@ -4,7 +4,6 @@ import ( "context" "github.com/skevetter/devpod/cmd/flags" - "github.com/skevetter/devpod/pkg/client" "github.com/skevetter/devpod/pkg/config" "github.com/skevetter/devpod/pkg/workspace" "github.com/skevetter/log" @@ -44,7 +43,7 @@ func (cmd *StartCmd) Run(ctx context.Context, args []string) error { return err } - err = machineClient.Start(ctx, client.StartOptions{}) + err = machineClient.Start(ctx) if err != nil { return err } diff --git a/cmd/troubleshoot.go b/cmd/troubleshoot.go index 817c1056b..ab085fd76 100644 --- a/cmd/troubleshoot.go +++ b/cmd/troubleshoot.go @@ -55,7 +55,7 @@ func NewTroubleshootCmd(flags *flags.GlobalFlags) *cobra.Command { func (cmd *TroubleshootCmd) Run(ctx context.Context, args []string) { // (ThomasK33): We're creating an anonymous struct here, so that we group - // everything and then we can serialize it in one call. + // everything so that we can serialize it in one call. var info struct { CLIVersion string Config *config.Config diff --git a/pkg/client/client.go b/pkg/client/client.go index 16bb77afb..100f694f2 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -45,13 +45,13 @@ type Client interface { AgentURL() string // Create creates a new workspace - Create(ctx context.Context, options CreateOptions) error + Create(ctx context.Context) error // Describe retrieves the virtual machine description Describe(ctx context.Context) (string, error) // Start starts the workspace - Start(ctx context.Context, options StartOptions) error + Start(ctx context.Context) error // Command creates an SSH tunnel into the workspace Command(ctx context.Context, options CommandOptions) error @@ -135,12 +135,6 @@ type WorkspaceClient interface { AgentInfo(options provider.CLIOptions) (string, *provider.AgentWorkspaceInfo, error) } -type InitOptions struct{} - -type ValidateOptions struct{} - -type StartOptions struct{} - type StopOptions struct { Platform devpod.PlatformOptions `json:"platform"` } @@ -153,8 +147,6 @@ type DeleteOptions struct { GracePeriod string `json:"gracePeriod,omitempty"` } -type CreateOptions struct{} - type StatusOptions struct { ContainerStatus bool `json:"containerStatus,omitempty"` } @@ -182,8 +174,6 @@ type SshOptions struct { Stdout io.Writer } -type ImportWorkspaceOptions map[string]string - type Status string const ( @@ -193,10 +183,6 @@ const ( StatusNotFound = "NotFound" ) -const ( - DescriptionNotFound = "{}" -) - func ParseStatus(in string) (Status, error) { in = strings.ToUpper(strings.TrimSpace(in)) switch in { @@ -217,6 +203,10 @@ func ParseStatus(in string) (Status, error) { } } +const ( + DescriptionNotFound = "{}" +) + type WorkspaceStatus struct { ID string `json:"id,omitempty"` Context string `json:"context,omitempty"` diff --git a/pkg/client/clientimplementation/machine_client.go b/pkg/client/clientimplementation/machine_client.go index 364845b5a..958a030cf 100644 --- a/pkg/client/clientimplementation/machine_client.go +++ b/pkg/client/clientimplementation/machine_client.go @@ -187,11 +187,11 @@ func (s *machineClient) Context() string { return s.machine.Context } -func (s *machineClient) Create(ctx context.Context, options client.CreateOptions) error { +func (s *machineClient) Create(ctx context.Context) error { return s.executor.lifecycleCommand(ctx, "create", s.config.Exec.Create, "creating", "created") } -func (s *machineClient) Start(ctx context.Context, options client.StartOptions) error { +func (s *machineClient) Start(ctx context.Context) error { return s.executor.lifecycleCommand(ctx, "start", s.config.Exec.Start, "starting", "started") } diff --git a/pkg/client/clientimplementation/workspace_client.go b/pkg/client/clientimplementation/workspace_client.go index f89e4d026..d172635da 100644 --- a/pkg/client/clientimplementation/workspace_client.go +++ b/pkg/client/clientimplementation/workspace_client.go @@ -324,7 +324,7 @@ func (s *workspaceClient) Unlock() { } } -func (s *workspaceClient) Create(ctx context.Context, options client.CreateOptions) error { +func (s *workspaceClient) Create(ctx context.Context) error { s.m.Lock() defer s.m.Unlock() @@ -353,7 +353,7 @@ func (s *workspaceClient) Create(ctx context.Context, options client.CreateOptio } // create the machine - return machineClient.Create(ctx, client.CreateOptions{}) + return machineClient.Create(ctx) } func (s *workspaceClient) Delete(ctx context.Context, opt client.DeleteOptions) error { @@ -469,7 +469,7 @@ func (s *workspaceClient) isMachineRunning(ctx context.Context) (bool, error) { return false, nil } -func (s *workspaceClient) Start(ctx context.Context, options client.StartOptions) error { +func (s *workspaceClient) Start(ctx context.Context) error { s.m.Lock() defer s.m.Unlock() @@ -482,7 +482,7 @@ func (s *workspaceClient) Start(ctx context.Context, options client.StartOptions return err } - return machineClient.Start(ctx, options) + return machineClient.Start(ctx) } func (s *workspaceClient) Stop(ctx context.Context, opt client.StopOptions) error { @@ -609,6 +609,27 @@ func (s *workspaceClient) Status( return client.StatusNotFound, nil } +func (s *workspaceClient) Describe(ctx context.Context) (string, error) { + s.m.Lock() + defer s.m.Unlock() + + // check if provider has 'describe' command + if s.isMachineProvider() && len(s.config.Exec.Describe) > 0 { + if s.machine == nil { + return client.DescriptionNotFound, nil + } + + machineClient, err := NewMachineClient(s.devPodConfig, s.config, s.machine, s.log) + if err != nil { + return client.DescriptionNotFound, err + } + + return machineClient.Describe(ctx) + } + + return client.DescriptionNotFound, nil +} + func (s *workspaceClient) initLock() error { s.workspaceLockOnce.Do(func() { s.m.Lock() @@ -694,27 +715,6 @@ func (s *workspaceClient) getContainerStatus(ctx context.Context) (client.Status return parsed, nil } -func (s *workspaceClient) Describe(ctx context.Context) (string, error) { - s.m.Lock() - defer s.m.Unlock() - - // check if provider has 'describe' command - if s.isMachineProvider() && len(s.config.Exec.Describe) > 0 { - if s.machine == nil { - return client.DescriptionNotFound, nil - } - - machineClient, err := NewMachineClient(s.devPodConfig, s.config, s.machine, s.log) - if err != nil { - return client.DescriptionNotFound, err - } - - return machineClient.Describe(ctx) - } - - return client.DescriptionNotFound, nil -} - func (s *workspaceClient) isMachineProvider() bool { return len(s.config.Exec.Create) > 0 } @@ -933,7 +933,7 @@ func handleStoppedStatus( create bool, ) error { if create { - err := workspaceClient.Start(ctx, client.StartOptions{}) + err := workspaceClient.Start(ctx) if err != nil { return fmt.Errorf("start workspace: %w", err) } @@ -948,7 +948,7 @@ func handleNotFoundStatus( create bool, ) error { if create { - err := workspaceClient.Create(ctx, client.CreateOptions{}) + err := workspaceClient.Create(ctx) if err != nil { return err } diff --git a/pkg/workspace/workspace.go b/pkg/workspace/workspace.go index 0d027506a..55b64fc8a 100644 --- a/pkg/workspace/workspace.go +++ b/pkg/workspace/workspace.go @@ -442,7 +442,7 @@ func createWorkspace( } // create machine - err = machineClient.Create(ctx, client.CreateOptions{}) + err = machineClient.Create(ctx) if err != nil { _ = clientimplementation.DeleteMachineFolder( machineConfig.Context,