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
15 changes: 7 additions & 8 deletions pkg/client/clientimplementation/daemonclient/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"

"github.com/devsy-org/devsy/pkg/platform/form"
"github.com/devsy-org/devsy/pkg/platform/project"
"github.com/devsy-org/devsy/pkg/provider"
"github.com/devsy-org/devsy/pkg/terminal"
Expand Down Expand Up @@ -33,14 +34,12 @@ func (c *client) Create(
return fmt.Errorf("unable to create new instance through CLI if stdin is not a terminal")
}

instance, err = createInstanceInteractive(
ctx,
baseClient,
c.workspace.ID,
c.workspace.UID,
c.workspace.Source.String(),
c.workspace.Picture,
)
instance, err = form.CreateInstanceOnCluster(ctx, baseClient, form.InstanceIdentity{
ID: c.workspace.ID,
UID: c.workspace.UID,
Source: c.workspace.Source.String(),
Picture: c.workspace.Picture,
})
if err != nil {
return err
}
Expand Down
182 changes: 0 additions & 182 deletions pkg/client/clientimplementation/daemonclient/form.go

This file was deleted.

51 changes: 43 additions & 8 deletions pkg/platform/form/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,44 @@ func CreateInstance(
baseClient client.Client,
id, uid, source, picture string,
) (*managementv1.DevsyWorkspaceInstance, error) {
instance, _, err := createInstance(ctx, baseClient, InstanceIdentity{
ID: id,
UID: uid,
Source: source,
Picture: picture,
})
return instance, err
}

func CreateInstanceOnCluster(
ctx context.Context,
baseClient client.Client,
identity InstanceIdentity,
) (*managementv1.DevsyWorkspaceInstance, error) {
instance, selection, err := createInstance(ctx, baseClient, identity)
if err != nil {
return nil, err
}

instance.Spec.Target.Cluster = &storagev1.WorkspaceTargetName{Name: selection.cluster.GetName()}
return instance, nil
}

type InstanceIdentity struct {
ID, UID, Source, Picture string
}

func createInstance(
ctx context.Context,
baseClient client.Client,
identity InstanceIdentity,
) (*managementv1.DevsyWorkspaceInstance, createSelection, error) {
formCtx, cancelForm := context.WithCancel(ctx)
defer cancelForm()

selection, err := runCreateSelectionForm(ctx, baseClient, formCtx, cancelForm)
if err != nil {
return nil, err
return nil, createSelection{}, err
}

renderedParameters, err := renderedParametersForCreate(
Expand All @@ -42,23 +74,25 @@ func CreateInstance(
selection.templateVersion,
)
if err != nil {
return nil, err
return nil, createSelection{}, err
}

return buildCreatedInstance(buildCreatedInstanceParams{
id: id,
uid: uid,
source: source,
picture: picture,
instance := buildCreatedInstance(buildCreatedInstanceParams{
id: identity.ID,
uid: identity.UID,
source: identity.Source,
picture: identity.Picture,
selectedProject: selection.project,
selectedTemplate: selection.template,
selectedTemplateVersion: selection.templateVersion,
renderedParameters: renderedParameters,
}), nil
})
return instance, selection, nil
}

type createSelection struct {
project *managementv1.Project
cluster *managementv1.Cluster
template *managementv1.DevsyWorkspaceTemplate
templateVersion string
}
Expand Down Expand Up @@ -111,6 +145,7 @@ func runCreateSelectionForm(

return createSelection{
project: selectedProject,
cluster: selectedCluster,
template: selectedTemplate,
templateVersion: selectedTemplateVersion,
}, nil
Expand Down
Loading