Skip to content
Merged
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
3 changes: 1 addition & 2 deletions cmd/machine/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/troubleshoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 6 additions & 16 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}
Expand All @@ -153,8 +147,6 @@ type DeleteOptions struct {
GracePeriod string `json:"gracePeriod,omitempty"`
}

type CreateOptions struct{}

type StatusOptions struct {
ContainerStatus bool `json:"containerStatus,omitempty"`
}
Expand Down Expand Up @@ -182,8 +174,6 @@ type SshOptions struct {
Stdout io.Writer
}

type ImportWorkspaceOptions map[string]string

type Status string

const (
Expand All @@ -193,10 +183,6 @@ const (
StatusNotFound = "NotFound"
)

const (
DescriptionNotFound = "{}"
)

func ParseStatus(in string) (Status, error) {
in = strings.ToUpper(strings.TrimSpace(in))
switch in {
Expand All @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/clientimplementation/machine_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
54 changes: 27 additions & 27 deletions pkg/client/clientimplementation/workspace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading