Skip to content

Commit

Permalink
Restore v1alpha1 DevWorkspace CRD
Browse files Browse the repository at this point in the history
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 <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Jan 20, 2022
1 parent b317254 commit 12d4ebe
Show file tree
Hide file tree
Showing 54 changed files with 27,759 additions and 7,401 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ generator/build/generator "interfaces" "paths=./pkg/apis/workspaces/v1alpha2"

echo "Generating K8S CRDs"

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

echo "Generating DeepCopy implementations"

generator/build/generator "deepcopy" "paths=./pkg/apis/workspaces/v1alpha2;"
generator/build/generator "deepcopy" "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1"

echo "Generating JsonSchemas"

Expand Down
11,737 changes: 7,937 additions & 3,800 deletions crds/workspace.devfile.io_devworkspaces.v1beta1.yaml

Large diffs are not rendered by default.

4,082 changes: 4,082 additions & 0 deletions crds/workspace.devfile.io_devworkspaces.yaml

Large diffs are not rendered by default.

11,107 changes: 7,519 additions & 3,588 deletions crds/workspace.devfile.io_devworkspacetemplates.v1beta1.yaml

Large diffs are not rendered by default.

3,875 changes: 3,875 additions & 0 deletions crds/workspace.devfile.io_devworkspacetemplates.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions devfile.api.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"mode": "auto",
"program": "${workspaceFolder:generator}",
"env": { "GOMOD": "${workspaceFolder:generator}/go.mod"},
"args": [ "crds", "paths=./pkg/apis/workspaces/v1alpha2;", "output:crds:artifacts:config=crds" ],
"args": [ "crds", "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1", "output:crds:artifacts:config=crds" ],
"cwd": "${workspaceFolder:api}"
},
{
Expand All @@ -75,7 +75,7 @@
"mode": "auto",
"program": "${workspaceFolder:generator}",
"env": { "GOMOD": "${workspaceFolder:generator}/go.mod"},
"args": [ "deepcopy", "paths=./pkg/apis/workspaces/v1alpha2;" ],
"args": [ "deepcopy", "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1" ],
"cwd": "${workspaceFolder:api}"
},
{
Expand All @@ -85,7 +85,7 @@
"mode": "auto",
"program": "${workspaceFolder:generator}",
"env": { "GOMOD": "${workspaceFolder:generator}/go.mod"},
"args": [ "schemas", "paths=./pkg/apis/workspaces/v1alpha2;", "output:schemas:artifacts:config=schemas" ],
"args": [ "schemas", "paths=./pkg/apis/workspaces/v1alpha2;./pkg/apis/workspaces/v1alpha1", "output:schemas:artifacts:config=schemas" ],
"cwd": "${workspaceFolder:api}"
},
{
Expand Down
1 change: 0 additions & 1 deletion generator/crds/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion generator/getters/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion generator/interfaces/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion generator/overrides/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion generator/schemas/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion generator/validate/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ go 1.13

require (
github.com/ghodss/yaml v1.0.0
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/go-cmp v0.5.5
github.com/google/gofuzz v1.2.0
github.com/hashicorp/go-multierror v1.1.0
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb
github.com/mitchellh/reflectwalk v1.0.1
Expand Down
40 changes: 40 additions & 0 deletions pkg/apis/workspaces/v1alpha1/attributes_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v1alpha1

import (
"fmt"

"github.com/devfile/api/v2/pkg/attributes"
)

func convertAttributesTo_v1alpha2(src map[string]string, dest *attributes.Attributes) {
dest.FromStringMap(src)
}

func convertAttributesFrom_v1alpha2(src *attributes.Attributes, dest map[string]string) error {
if dest == nil {
return fmt.Errorf("trying to insert into a nil map")
}
var err error
stringAttributes := src.Strings(&err)
if err != nil {
return err
}
for k, v := range stringAttributes {
dest[k] = v
}
return nil
}

func getCommandAttributes(command *Command) map[string]string {
switch {
case command.Exec != nil:
return command.Exec.Attributes
case command.Apply != nil:
return command.Apply.Attributes
case command.Composite != nil:
return command.Composite.Attributes
case command.Custom != nil:
return command.Custom.Attributes
}
return nil
}
215 changes: 215 additions & 0 deletions pkg/apis/workspaces/v1alpha1/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
package v1alpha1

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;Apply;VscodeTask;VscodeLaunch;Composite;Custom
type CommandType string

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

// CommandGroupKind describes the kind of command group.
// +kubebuilder:validation:Enum=build;run;test;debug
type CommandGroupKind string

const (
BuildCommandGroupKind CommandGroupKind = "build"
RunCommandGroupKind CommandGroupKind = "run"
TestCommandGroupKind CommandGroupKind = "test"
DebugCommandGroupKind CommandGroupKind = "debug"
)

type CommandGroup struct {
// Kind of group the command is part of
Kind CommandGroupKind `json:"kind"`

// +optional
// Identifies the default command for a given group kind
IsDefault bool `json:"isDefault,omitempty"`
}

type BaseCommand struct {
// Mandatory identifier that allows referencing
// this command in composite commands, from
// a parent, or in events.
Id string `json:"id"`

// +optional
// Defines the group this command is part of
Group *CommandGroup `json:"group,omitempty"`

// Optional map of free-form additional command attributes
Attributes map[string]string `json:"attributes,omitempty"`
}

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

// +optional
// Optional label that provides a label for this command
// to be used in Editor UI menus for example
Label string `json:"label,omitempty"`
}

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

// CLI Command executed in an existing component container
// +optional
Exec *ExecCommand `json:"exec,omitempty"`

// Command that consists in applying a given component definition,
// typically bound to a workspace event.
//
// For example, when an `apply` command is bound to a `preStart` event,
// and references a `container` component, it will start the container as a
// K8S initContainer in the workspace POD, unless the component has its
// `dedicatedPod` field set to `true`.
//
// When no `apply` command exist for a given component,
// it is assumed the component will be applied at workspace start
// by default.
// +optional
Apply *ApplyCommand `json:"apply,omitempty"`

// Command providing the definition of a VsCode Task
//
// Deprecated; removed in v1alpha2
// +optional
VscodeTask *VscodeConfigurationCommand `json:"vscodeTask,omitempty"`

// Command providing the definition of a VsCode launch action
//
// Deprecated; removed in v1alpha2
// +optional
VscodeLaunch *VscodeConfigurationCommand `json:"vscodeLaunch,omitempty"`

// Composite command that allows executing several sub-commands
// either sequentially or concurrently
// +optional
Composite *CompositeCommand `json:"composite,omitempty"`

// Custom command whose logic is implementation-dependant
// and should be provided by the user
// possibly through some dedicated plugin
// +optional
Custom *CustomCommand `json:"custom,omitempty"`
}

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

// The actual command-line string
//
// Special variables that can be used:
//
// - `$PROJECTS_ROOT`: A path where projects sources are mounted
//
// - `$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.
CommandLine string `json:"commandLine,omitempty"`

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

// Working directory where the command should be executed
//
// Special variables that can be used:
//
// - `${PROJECTS_ROOT}`: A path where projects sources are mounted
//
// - `${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.
WorkingDir string `json:"workingDir,omitempty"`

// +optional
// Optional list of environment variables that have to be set
// before running the command
Env []EnvVar `json:"env,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// +optional
// Whether the command is capable to reload itself when source code changes.
// If set to `true` the command won't be restarted and it is expected to handle file changes on its own.
//
// Default value is `false`
HotReloadCapable bool `json:"hotReloadCapable,omitempty"`
}

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

// Describes component that will be applied
Component string `json:"component,omitempty"`
}

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

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

// Indicates if the sub-commands should be executed concurrently
// +optional
Parallel bool `json:"parallel,omitempty"`
}

// VscodeConfigurationCommandLocationType describes the type of
// the location the configuration is fetched from.
// Only one of the following component type may be specified.
// +kubebuilder:validation:Enum=Uri;Inlined
type VscodeConfigurationCommandLocationType string

const (
UriVscodeConfigurationCommandLocationType VscodeConfigurationCommandLocationType = "Uri"
InlinedVscodeConfigurationCommandLocationType VscodeConfigurationCommandLocationType = "Inlined"
)

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

// Location as an absolute of relative URI
// the VsCode configuration will be fetched from
// +optional
Uri string `json:"uri,omitempty"`

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

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

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

// Class of command that the associated implementation component
// should use to process this command with the appropriate logic
CommandClass string `json:"commandClass"`

// Additional free-form configuration for this custom command
// that the implementation component will know how to use
//
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:EmbeddedResource
EmbeddedResource runtime.RawExtension `json:"embeddedResource"`
}
Loading

0 comments on commit 12d4ebe

Please sign in to comment.