Skip to content

Commit 089a480

Browse files
Dockerfile Outerloop Support (#580)
* Add Image Comp, add Deploy Cmd Kind & handle conversion to v1alpha1 Signed-off-by: Maysun J Faisal <[email protected]> * Move GitLocation into Git project source Moves GitLocation in DockerfileImage Image component type under the Git struct to make clear that this field is intended only for use when specifying a git repo. (Files not regenerated for readability) Signed-off-by: Angel Misevski <[email protected]> * Address PR reviews, update src Signed-off-by: Maysun J Faisal <[email protected]> * Add variable subs for image component Signed-off-by: Maysun J Faisal <[email protected]> * Add more tests for the new image component Signed-off-by: Maysun J Faisal <[email protected]> * Apply Outerloop PR feedback Signed-off-by: Maysun J Faisal <[email protected]> * Review feedback: Update var name, nesting and test coverage Signed-off-by: Maysun J Faisal <[email protected]> Co-authored-by: Angel Misevski <[email protected]>
1 parent 1ed13db commit 089a480

File tree

64 files changed

+9312
-539
lines changed

Some content is hidden

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

64 files changed

+9312
-539
lines changed

crds/workspace.devfile.io_devworkspaces.v1beta1.yaml

Lines changed: 505 additions & 8 deletions
Large diffs are not rendered by default.

crds/workspace.devfile.io_devworkspaces.yaml

Lines changed: 505 additions & 8 deletions
Large diffs are not rendered by default.

crds/workspace.devfile.io_devworkspacetemplates.v1beta1.yaml

Lines changed: 488 additions & 8 deletions
Large diffs are not rendered by default.

crds/workspace.devfile.io_devworkspacetemplates.yaml

Lines changed: 488 additions & 8 deletions
Large diffs are not rendered by default.

pkg/apis/workspaces/v1alpha1/commands_conversion.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,36 @@ func convertCommandTo_v1alpha2(src *Command, dest *v1alpha2.Command) error {
4040
return nil
4141
}
4242

43+
// getGroup returns the group the command belongs to
44+
func getGroup(dc v1alpha2.Command) *v1alpha2.CommandGroup {
45+
switch {
46+
case dc.Composite != nil:
47+
return dc.Composite.Group
48+
case dc.Exec != nil:
49+
return dc.Exec.Group
50+
case dc.Apply != nil:
51+
return dc.Apply.Group
52+
case dc.Custom != nil:
53+
return dc.Custom.Group
54+
55+
default:
56+
return nil
57+
}
58+
}
59+
4360
func convertCommandFrom_v1alpha2(src *v1alpha2.Command, dest *Command) error {
61+
if src == nil {
62+
return nil
63+
}
64+
4465
id := src.Key()
66+
67+
srcCmdGroup := getGroup(*src)
68+
if srcCmdGroup != nil && srcCmdGroup.Kind == v1alpha2.DeployCommandGroupKind {
69+
// skip converting deploy kind commands as deploy kind commands are not supported in v1alpha1
70+
return nil
71+
}
72+
4573
jsonCommand, err := json.Marshal(src)
4674
if err != nil {
4775
return err

pkg/apis/workspaces/v1alpha1/commands_conversion_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,30 @@ func TestCommandConversion_v1alpha1(t *testing.T) {
3333
}
3434
}
3535
}
36+
37+
func TestCommandConversionFrom_v1alpha2(t *testing.T) {
38+
39+
src := &v1alpha2.Command{
40+
Id: "test1",
41+
CommandUnion: v1alpha2.CommandUnion{
42+
Exec: &v1alpha2.ExecCommand{
43+
LabeledCommand: v1alpha2.LabeledCommand{
44+
BaseCommand: v1alpha2.BaseCommand{
45+
Group: &v1alpha2.CommandGroup{
46+
Kind: v1alpha2.DeployCommandGroupKind,
47+
},
48+
},
49+
},
50+
},
51+
},
52+
}
53+
54+
output := &Command{}
55+
56+
err := convertCommandFrom_v1alpha2(src, output)
57+
if !assert.NoError(t, err, "Should not return error when converting from v1alpha2") {
58+
return
59+
}
60+
61+
assert.Equal(t, &Command{}, output, "Conversion from v1alpha2 should be skipped for deploy kind command")
62+
}

pkg/apis/workspaces/v1alpha1/components_conversion.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func convertComponentFrom_v1alpha2(src *v1alpha2.Component, dest *Component) err
3131
if src.Plugin != nil {
3232
// Need to handle plugin components separately.
3333
return convertPluginComponentFrom_v1alpha2(src, dest)
34+
} else if src.Image != nil {
35+
// Skip converting an Image component since v1alpha1 does not have an Image component
36+
return nil
3437
}
3538
name := src.Key()
3639
jsonComponent, err := json.Marshal(src)

pkg/apis/workspaces/v1alpha1/components_conversion_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,25 @@ func TestComponentConversion_v1alpha1(t *testing.T) {
3636
}
3737
}
3838
}
39+
40+
func TestComponentConversionFrom_v1alpha2(t *testing.T) {
41+
42+
src := &v1alpha2.Component{
43+
Name: "test1",
44+
ComponentUnion: v1alpha2.ComponentUnion{
45+
Image: &v1alpha2.ImageComponent{
46+
Image: v1alpha2.Image{
47+
ImageName: "image:latest",
48+
},
49+
},
50+
},
51+
}
52+
output := &Component{}
53+
54+
err := convertComponentFrom_v1alpha2(src, output)
55+
if !assert.NoError(t, err, "Should not return error when converting from v1alpha2") {
56+
return
57+
}
58+
59+
assert.Equal(t, &Component{}, output, "Conversion from v1alpha2 should be skipped for Image Component")
60+
}

pkg/apis/workspaces/v1alpha2/commands.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ const (
1818
)
1919

2020
// CommandGroupKind describes the kind of command group.
21-
// +kubebuilder:validation:Enum=build;run;test;debug
21+
// +kubebuilder:validation:Enum=build;run;test;debug;deploy
2222
type CommandGroupKind string
2323

2424
const (
25-
BuildCommandGroupKind CommandGroupKind = "build"
26-
RunCommandGroupKind CommandGroupKind = "run"
27-
TestCommandGroupKind CommandGroupKind = "test"
28-
DebugCommandGroupKind CommandGroupKind = "debug"
25+
BuildCommandGroupKind CommandGroupKind = "build"
26+
RunCommandGroupKind CommandGroupKind = "run"
27+
TestCommandGroupKind CommandGroupKind = "test"
28+
DebugCommandGroupKind CommandGroupKind = "debug"
29+
DeployCommandGroupKind CommandGroupKind = "deploy"
2930
)
3031

3132
type CommandGroup struct {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package v1alpha2
2+
3+
// ImageType describes the type of image.
4+
// Only one of the following image type may be specified.
5+
// +kubebuilder:validation:Enum=Dockerfile
6+
type ImageType string
7+
8+
const (
9+
DockerfileImageType ImageType = "Dockerfile"
10+
)
11+
12+
type BaseImage struct {
13+
}
14+
15+
// Component that allows the developer to build a runtime image for outerloop
16+
type ImageComponent struct {
17+
BaseComponent `json:",inline"`
18+
Image `json:",inline"`
19+
}
20+
21+
type Image struct {
22+
// Name of the image for the resulting outerloop build
23+
ImageName string `json:"imageName"`
24+
ImageUnion `json:",inline"`
25+
}
26+
27+
// +union
28+
type ImageUnion struct {
29+
// Type of image
30+
//
31+
// +unionDiscriminator
32+
// +optional
33+
ImageType ImageType `json:"imageType,omitempty"`
34+
35+
// Allows specifying dockerfile type build
36+
// +optional
37+
Dockerfile *DockerfileImage `json:"dockerfile,omitempty"`
38+
}

0 commit comments

Comments
 (0)