Skip to content

Commit 4496bd9

Browse files
committed
Restore v1alpha1 DevWorkspace CRD
The v1alpha1 apiVersion of the DevWorkspace (and DevWorkspaceTemplate) CRD was removed prematurely as there are existing users that depend on it. This commit restores the v1alpha1 API as removed in PR #639 in order to allow dependents of the DevWorkspace API to update to later versions of the v1alpha2 API without breaking v1alpha1 compatibility. Signed-off-by: Angel Misevski <[email protected]>
1 parent 3654d1a commit 4496bd9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+27760
-7394
lines changed

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ generator/build/generator "interfaces" "paths=./pkg/apis/workspaces/v1alpha2"
5151

5252
echo "Generating K8S CRDs"
5353

54-
generator/build/generator "crds" "output:crds:artifacts:config=crds" "paths=./pkg/apis/workspaces/v1alpha2;"
54+
generator/build/generator "crds" "output:crds:artifacts:config=crds" "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1"
5555

5656
echo "Generating DeepCopy implementations"
5757

58-
generator/build/generator "deepcopy" "paths=./pkg/apis/workspaces/v1alpha2;"
58+
generator/build/generator "deepcopy" "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1"
5959

6060
echo "Generating JsonSchemas"
6161

crds/workspace.devfile.io_devworkspaces.v1beta1.yaml

Lines changed: 7937 additions & 3800 deletions
Large diffs are not rendered by default.

crds/workspace.devfile.io_devworkspaces.yaml

Lines changed: 4082 additions & 0 deletions
Large diffs are not rendered by default.

crds/workspace.devfile.io_devworkspacetemplates.v1beta1.yaml

Lines changed: 7519 additions & 3588 deletions
Large diffs are not rendered by default.

crds/workspace.devfile.io_devworkspacetemplates.yaml

Lines changed: 3875 additions & 0 deletions
Large diffs are not rendered by default.

devfile.api.code-workspace

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"mode": "auto",
6666
"program": "${workspaceFolder:generator}",
6767
"env": { "GOMOD": "${workspaceFolder:generator}/go.mod"},
68-
"args": [ "crds", "paths=./pkg/apis/workspaces/v1alpha2;", "output:crds:artifacts:config=crds" ],
68+
"args": [ "crds", "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1", "output:crds:artifacts:config=crds" ],
6969
"cwd": "${workspaceFolder:api}"
7070
},
7171
{
@@ -75,7 +75,7 @@
7575
"mode": "auto",
7676
"program": "${workspaceFolder:generator}",
7777
"env": { "GOMOD": "${workspaceFolder:generator}/go.mod"},
78-
"args": [ "deepcopy", "paths=./pkg/apis/workspaces/v1alpha2;" ],
78+
"args": [ "deepcopy", "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1" ],
7979
"cwd": "${workspaceFolder:api}"
8080
},
8181
{
@@ -85,7 +85,7 @@
8585
"mode": "auto",
8686
"program": "${workspaceFolder:generator}",
8787
"env": { "GOMOD": "${workspaceFolder:generator}/go.mod"},
88-
"args": [ "schemas", "paths=./pkg/apis/workspaces/v1alpha2;", "output:schemas:artifacts:config=schemas" ],
88+
"args": [ "schemas", "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1", "output:schemas:artifacts:config=schemas" ],
8989
"cwd": "${workspaceFolder:api}"
9090
},
9191
{

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ go 1.13
44

55
require (
66
github.com/ghodss/yaml v1.0.0
7-
github.com/google/gofuzz v1.2.0 // indirect
7+
github.com/google/go-cmp v0.5.5
8+
github.com/google/gofuzz v1.2.0
89
github.com/hashicorp/go-multierror v1.1.0
910
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb
1011
github.com/mitchellh/reflectwalk v1.0.1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package v1alpha1
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/devfile/api/v2/pkg/attributes"
7+
)
8+
9+
func convertAttributesTo_v1alpha2(src map[string]string, dest *attributes.Attributes) {
10+
dest.FromStringMap(src)
11+
}
12+
13+
func convertAttributesFrom_v1alpha2(src *attributes.Attributes, dest map[string]string) error {
14+
if dest == nil {
15+
return fmt.Errorf("trying to insert into a nil map")
16+
}
17+
var err error
18+
stringAttributes := src.Strings(&err)
19+
if err != nil {
20+
return err
21+
}
22+
for k, v := range stringAttributes {
23+
dest[k] = v
24+
}
25+
return nil
26+
}
27+
28+
func getCommandAttributes(command *Command) map[string]string {
29+
switch {
30+
case command.Exec != nil:
31+
return command.Exec.Attributes
32+
case command.Apply != nil:
33+
return command.Apply.Attributes
34+
case command.Composite != nil:
35+
return command.Composite.Attributes
36+
case command.Custom != nil:
37+
return command.Custom.Attributes
38+
}
39+
return nil
40+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
package v1alpha1
2+
3+
import runtime "k8s.io/apimachinery/pkg/runtime"
4+
5+
// CommandType describes the type of command.
6+
// Only one of the following command type may be specified.
7+
// +kubebuilder:validation:Enum=Exec;Apply;VscodeTask;VscodeLaunch;Composite;Custom
8+
type CommandType string
9+
10+
const (
11+
ExecCommandType CommandType = "Exec"
12+
ApplyCommandType CommandType = "Apply"
13+
VscodeTaskCommandType CommandType = "VscodeTask"
14+
VscodeLaunchCommandType CommandType = "VscodeLaunch"
15+
CompositeCommandType CommandType = "Composite"
16+
CustomCommandType CommandType = "Custom"
17+
)
18+
19+
// CommandGroupKind describes the kind of command group.
20+
// +kubebuilder:validation:Enum=build;run;test;debug
21+
type CommandGroupKind string
22+
23+
const (
24+
BuildCommandGroupKind CommandGroupKind = "build"
25+
RunCommandGroupKind CommandGroupKind = "run"
26+
TestCommandGroupKind CommandGroupKind = "test"
27+
DebugCommandGroupKind CommandGroupKind = "debug"
28+
)
29+
30+
type CommandGroup struct {
31+
// Kind of group the command is part of
32+
Kind CommandGroupKind `json:"kind"`
33+
34+
// +optional
35+
// Identifies the default command for a given group kind
36+
IsDefault bool `json:"isDefault,omitempty"`
37+
}
38+
39+
type BaseCommand struct {
40+
// Mandatory identifier that allows referencing
41+
// this command in composite commands, from
42+
// a parent, or in events.
43+
Id string `json:"id"`
44+
45+
// +optional
46+
// Defines the group this command is part of
47+
Group *CommandGroup `json:"group,omitempty"`
48+
49+
// Optional map of free-form additional command attributes
50+
Attributes map[string]string `json:"attributes,omitempty"`
51+
}
52+
53+
type LabeledCommand struct {
54+
BaseCommand `json:",inline"`
55+
56+
// +optional
57+
// Optional label that provides a label for this command
58+
// to be used in Editor UI menus for example
59+
Label string `json:"label,omitempty"`
60+
}
61+
62+
// +k8s:openapi-gen=true
63+
// +union
64+
type Command struct {
65+
// Type of workspace command
66+
// +unionDiscriminator
67+
// +optional
68+
CommandType CommandType `json:"commandType,omitempty"`
69+
70+
// CLI Command executed in an existing component container
71+
// +optional
72+
Exec *ExecCommand `json:"exec,omitempty"`
73+
74+
// Command that consists in applying a given component definition,
75+
// typically bound to a workspace event.
76+
//
77+
// For example, when an `apply` command is bound to a `preStart` event,
78+
// and references a `container` component, it will start the container as a
79+
// K8S initContainer in the workspace POD, unless the component has its
80+
// `dedicatedPod` field set to `true`.
81+
//
82+
// When no `apply` command exist for a given component,
83+
// it is assumed the component will be applied at workspace start
84+
// by default.
85+
// +optional
86+
Apply *ApplyCommand `json:"apply,omitempty"`
87+
88+
// Command providing the definition of a VsCode Task
89+
//
90+
// Deprecated; removed in v1alpha2
91+
// +optional
92+
VscodeTask *VscodeConfigurationCommand `json:"vscodeTask,omitempty"`
93+
94+
// Command providing the definition of a VsCode launch action
95+
//
96+
// Deprecated; removed in v1alpha2
97+
// +optional
98+
VscodeLaunch *VscodeConfigurationCommand `json:"vscodeLaunch,omitempty"`
99+
100+
// Composite command that allows executing several sub-commands
101+
// either sequentially or concurrently
102+
// +optional
103+
Composite *CompositeCommand `json:"composite,omitempty"`
104+
105+
// Custom command whose logic is implementation-dependant
106+
// and should be provided by the user
107+
// possibly through some dedicated plugin
108+
// +optional
109+
Custom *CustomCommand `json:"custom,omitempty"`
110+
}
111+
112+
type ExecCommand struct {
113+
LabeledCommand `json:",inline"`
114+
115+
// The actual command-line string
116+
//
117+
// Special variables that can be used:
118+
//
119+
// - `$PROJECTS_ROOT`: A path where projects sources are mounted
120+
//
121+
// - `$PROJECT_SOURCE`: A path to a project source ($PROJECTS_ROOT/<project-name>). If there are multiple projects, this will point to the directory of the first one.
122+
CommandLine string `json:"commandLine,omitempty"`
123+
124+
// Describes component to which given action relates
125+
Component string `json:"component,omitempty"`
126+
127+
// Working directory where the command should be executed
128+
//
129+
// Special variables that can be used:
130+
//
131+
// - `${PROJECTS_ROOT}`: A path where projects sources are mounted
132+
//
133+
// - `${PROJECT_SOURCE}`: A path to a project source (${PROJECTS_ROOT}/<project-name>). If there are multiple projects, this will point to the directory of the first one.
134+
WorkingDir string `json:"workingDir,omitempty"`
135+
136+
// +optional
137+
// Optional list of environment variables that have to be set
138+
// before running the command
139+
Env []EnvVar `json:"env,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
140+
141+
// +optional
142+
// Whether the command is capable to reload itself when source code changes.
143+
// If set to `true` the command won't be restarted and it is expected to handle file changes on its own.
144+
//
145+
// Default value is `false`
146+
HotReloadCapable bool `json:"hotReloadCapable,omitempty"`
147+
}
148+
149+
type ApplyCommand struct {
150+
LabeledCommand `json:",inline"`
151+
152+
// Describes component that will be applied
153+
Component string `json:"component,omitempty"`
154+
}
155+
156+
type CompositeCommand struct {
157+
LabeledCommand `json:",inline"`
158+
159+
// The commands that comprise this composite command
160+
Commands []string `json:"commands,omitempty" patchStrategy:"replace"`
161+
162+
// Indicates if the sub-commands should be executed concurrently
163+
// +optional
164+
Parallel bool `json:"parallel,omitempty"`
165+
}
166+
167+
// VscodeConfigurationCommandLocationType describes the type of
168+
// the location the configuration is fetched from.
169+
// Only one of the following component type may be specified.
170+
// +kubebuilder:validation:Enum=Uri;Inlined
171+
type VscodeConfigurationCommandLocationType string
172+
173+
const (
174+
UriVscodeConfigurationCommandLocationType VscodeConfigurationCommandLocationType = "Uri"
175+
InlinedVscodeConfigurationCommandLocationType VscodeConfigurationCommandLocationType = "Inlined"
176+
)
177+
178+
// +k8s:openapi-gen=true
179+
// +union
180+
type VscodeConfigurationCommandLocation struct {
181+
// Type of Vscode configuration command location
182+
// +
183+
// +unionDiscriminator
184+
// +optional
185+
LocationType VscodeConfigurationCommandLocationType `json:"locationType,omitempty"`
186+
187+
// Location as an absolute of relative URI
188+
// the VsCode configuration will be fetched from
189+
// +optional
190+
Uri string `json:"uri,omitempty"`
191+
192+
// Inlined content of the VsCode configuration
193+
// +optional
194+
Inlined string `json:"inlined,omitempty"`
195+
}
196+
197+
type VscodeConfigurationCommand struct {
198+
BaseCommand `json:",inline"`
199+
VscodeConfigurationCommandLocation `json:",inline"`
200+
}
201+
202+
type CustomCommand struct {
203+
LabeledCommand `json:",inline"`
204+
205+
// Class of command that the associated implementation component
206+
// should use to process this command with the appropriate logic
207+
CommandClass string `json:"commandClass"`
208+
209+
// Additional free-form configuration for this custom command
210+
// that the implementation component will know how to use
211+
//
212+
// +kubebuilder:pruning:PreserveUnknownFields
213+
// +kubebuilder:validation:EmbeddedResource
214+
EmbeddedResource runtime.RawExtension `json:"embeddedResource"`
215+
}

0 commit comments

Comments
 (0)