Skip to content

Commit

Permalink
First sketch of refactored commands (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal authored Feb 3, 2020
1 parent 0253a4f commit 08aef13
Show file tree
Hide file tree
Showing 6 changed files with 530 additions and 95 deletions.
125 changes: 105 additions & 20 deletions deploy/crds/workspaces.ecd.eclipse.org_devworkspaces_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,118 @@ spec:
description: Predefined, ready-to-use, workspace-related commands
items:
properties:
actions:
items:
properties:
command:
composite:
description: Composite command
properties:
alias:
type: string
attributes:
additionalProperties:
type: string
component:
type: object
commands:
description: The commands that comprise this composite
command
items:
type: string
reference:
type: array
label:
type: string
parallel:
type: boolean
type: object
custom:
description: Custom command
properties:
alias:
type: string
attributes:
additionalProperties:
type: string
referenceContent:
type: object
commandClass:
type: string
embeddedResource:
type: object
label:
type: string
required:
- commandClass
- embeddedResource
type: object
exec:
description: Exec command
properties:
alias:
type: string
attributes:
additionalProperties:
type: string
type:
type: object
commandLine:
description: The actual command-line string
type: string
component:
description: Describes component to which given action
relates
type: string
label:
type: string
workdir:
description: Working directory where the command should
be executed
type: string
required:
- commandLine
type: object
type:
description: Type of workspace command
enum:
- Exec
- VscodeTask
- VscodeLaunch
- Custom
type: string
vscodeLaunch:
description: VscodeLaunch command
properties:
alias:
type: string
attributes:
additionalProperties:
type: string
workdir:
type: object
inlined:
description: Embedded content of the vscode configuration
file
type: string
locationType:
description: Type of Vscode configuration command location
type: string
url:
description: Location as an absolute of relative URL
type: string
type: object
vscodeTask:
description: VscodeTask command
properties:
alias:
type: string
attributes:
additionalProperties:
type: string
required:
- type
type: object
type: array
attributes:
additionalProperties:
type: string
type: object
inlined:
description: Embedded content of the vscode configuration
file
type: string
locationType:
description: Type of Vscode configuration command location
type: string
url:
description: Location as an absolute of relative URL
type: string
type: object
name:
type: string
required:
- name
type: object
type: array
components:
Expand Down
24 changes: 19 additions & 5 deletions devfiles/simple-devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ projects:
location: "https://github.com/che-incubator/devworkspace-api"
branch: "master"
commands:
- name: Create json schema from Go API
actions:
- type: exec
command: "./buildSchema.sh"
component: build-tools
- exec:
commandLine: "./buildSchema.sh"
component: build-tools
alias: buildSchema
- vscodeTask:
alias: openDevfile
inlined:
json
- composite:
Label: Build schema and open devfile
commands:
- buildSchema
- openDevfile
parallel: false
- custom:
commandClass: myCommandType
embeddedResource:
myEmbeddedObject:
label: My very own and special command
components:
- chePlugin:
registry:
Expand Down
118 changes: 108 additions & 10 deletions pkg/apis/workspaces/v1alpha1/commands.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,114 @@
package v1alpha1

type Command struct {
Actions []CommandAction `json:"actions,omitempty"` // List of the actions of given command. Now the only one command must be specified in list; but there are plans to implement supporting multiple actions commands.
import runtime "k8s.io/apimachinery/pkg/runtime"

// CommandType describes the type of command.
// Only one of the following command type may be specified.
// +kubebuilder:validation:Enum=Exec;VscodeTask;VscodeLaunch;Custom
type CommandType string

const (
ExecCommandType CommandType = "Exec"
VscodeTaskCommandType CommandType = "VscodeTask"
VscodeLaunchCommandType CommandType = "VscodeLaunch"
CompositeCommandType CommandType = "Composite"
CustomCommandType CommandType = "Custom"
)

type BaseCommand struct {
Alias string `json:"alias,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"` // Additional command attributes
Name string `json:"name"` // Describes the name of the command. Should be unique per commands set.
}

type CommandAction struct {
Command *string `json:"command,omitempty"` // The actual action command-line string
Component *string `json:"component,omitempty"` // Describes component to which given action relates
Type string `json:"type"` // Describes action type
Workdir *string `json:"workdir,omitempty"` // Working directory where the command should be executed
Reference *string `json:"reference,omitempty"` // Working directory where the command should be executed
ReferenceContent *string `json:"referenceContent,omitempty"` // Working directory where the command should be executed
type LabeledCommand struct {
BaseCommand `json:",inline"`
Label string `json:"label,omitempty"`
}

type Command struct {
PolymorphicCommand `json:",inline"`
}

// +k8s:openapi-gen=true
// +union
type PolymorphicCommand struct {
// Type of workspace command
// +unionDiscriminator
// +optional
Type CommandType `json:"type"`

// Exec command
// +optional
Exec *ExecCommand `json:"exec,omitempty"`

// VscodeTask command
// +optional
VscodeTask *VscodeConfigurationCommand `json:"vscodeTask,omitempty"`

// VscodeLaunch command
// +optional
VscodeLaunch *VscodeConfigurationCommand `json:"vscodeLaunch,omitempty"`

// Composite command
// +optional
Composite *CompositeCommand `json:"composite,omitempty"`

// Custom command
// +optional
Custom *CustomCommand `json:"custom,omitempty"`
}

type ExecCommand struct {
LabeledCommand `json:",inline"`

// The actual command-line string
CommandLine string `json:"commandLine"`

// Describes component to which given action relates
Component string `json:"component,omitempty"`

// Working directory where the command should be executed
Workdir *string `json:"workdir,omitempty"`
}

type CompositeCommand struct {
LabeledCommand `json:",inline"`

// The commands that comprise this composite command
Commands []string `json:"commands,omitempty"`

// +optional
Parallel bool `json:"parallel,omitempty"`
}

// +k8s:openapi-gen=true
// +union
type VscodeConfigurationCommandLocation struct {
// Type of Vscode configuration command location
// +
// +unionDiscriminator
// +optional
LocationType string `json:"locationType"`

// Location as an absolute of relative URL
// +optional
Url string `json:"url,omitempty"`

// Embedded content of the vscode configuration file
// +optional
Inlined string `json:"inlined,omitempty"`
}

type VscodeConfigurationCommand struct {
BaseCommand `json:",inline"`
Location VscodeConfigurationCommandLocation `json:",inline"`
}

type CustomCommand struct {
LabeledCommand `json:",inline"`
CommandClass string `json:"commandClass"`

// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:EmbeddedResource
EmbeddedResource runtime.RawExtension `json:"embeddedResource"`
}
2 changes: 1 addition & 1 deletion pkg/apis/workspaces/v1alpha1/devworkspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type DevWorkspaceSpec struct {
type DevWorkspaceTemplateSpec struct {
// Predefined, ready-to-use, workspace-related commands
Commands []Command `json:"commands,omitempty"`

// Projects worked on in the workspace, containing names and sources locations
Projects []Project `json:"projects,omitempty"`

Expand Down
Loading

0 comments on commit 08aef13

Please sign in to comment.