Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] Set AutoBuild and DeployByDefault #7051

Merged
34 changes: 34 additions & 0 deletions ododevapispec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ paths:
type: boolean
uri:
type: string
autoBuild:
type: string
enum:
- never
- undefined
- always
responses:
'200':
description: image was successfully added to the devfile
Expand Down Expand Up @@ -769,6 +775,12 @@ paths:
type: string
uri:
type: string
deployByDefault:
type: string
enum:
- never
- undefined
- always
responses:
'200':
description: resource was successfully added to the devfile
Expand Down Expand Up @@ -1699,6 +1711,8 @@ components:
- buildContext
- rootRequired
- uri
- autoBuild
- orphan
properties:
name:
type: string
Expand All @@ -1714,17 +1728,37 @@ components:
type: boolean
uri:
type: string
autoBuild:
type: string
enum:
- never
- undefined
- always
orphan:
description: true if the image is not referenced in any command
type: boolean
Resource:
type: object
required:
- name
- deployByDefault
- orphan
properties:
name:
type: string
inlined:
type: string
uri:
type: string
deployByDefault:
type: string
enum:
- never
- undefined
- always
orphan:
description: true if the resource is not referenced in any command
type: boolean
Volume:
type: object
required:
Expand Down
2 changes: 2 additions & 0 deletions pkg/apiserver-gen/go/model__devstate_image_post_request.go

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

2 changes: 2 additions & 0 deletions pkg/apiserver-gen/go/model__devstate_resource_post_request.go

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

7 changes: 7 additions & 0 deletions pkg/apiserver-gen/go/model_image.go

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

9 changes: 8 additions & 1 deletion pkg/apiserver-gen/go/model_resource.go

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

2 changes: 2 additions & 0 deletions pkg/apiserver-impl/devstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *DevstateApiService) DevstateImagePost(ctx context.Context, image openap
image.BuildContext,
image.RootRequired,
image.Uri,
image.AutoBuild,
)
if err != nil {
return openapi.Response(http.StatusInternalServerError, openapi.GeneralError{
Expand All @@ -77,6 +78,7 @@ func (s *DevstateApiService) DevstateResourcePost(ctx context.Context, resource
resource.Name,
resource.Inlined,
resource.Uri,
resource.DeployByDefault,
)
if err != nil {
return openapi.Response(http.StatusInternalServerError, openapi.GeneralError{
Expand Down
3 changes: 2 additions & 1 deletion pkg/apiserver-impl/devstate/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestDevfileState_AddApplyCommand(t *testing.T) {
_, err := state.AddImage(
"an-image",
"an-image-name",
nil, "/context", false, "",
nil, "/context", false, "", "undefined",
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -198,6 +198,7 @@ schemaVersion: 2.2.0
Name: "an-image",
ImageName: "an-image-name",
BuildContext: "/context",
AutoBuild: "undefined",
},
},
Resources: []Resource{},
Expand Down
16 changes: 14 additions & 2 deletions pkg/apiserver-impl/devstate/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
. "github.com/redhat-developer/odo/pkg/apiserver-gen/go"
"k8s.io/utils/pointer"
)

func (o *DevfileState) AddContainer(
Expand Down Expand Up @@ -129,7 +130,7 @@ func (o *DevfileState) checkContainerUsed(name string) error {
return nil
}

func (o *DevfileState) AddImage(name string, imageName string, args []string, buildContext string, rootRequired bool, uri string) (DevfileContent, error) {
func (o *DevfileState) AddImage(name string, imageName string, args []string, buildContext string, rootRequired bool, uri string, autoBuild string) (DevfileContent, error) {
container := v1alpha2.Component{
Name: name,
ComponentUnion: v1alpha2.ComponentUnion{
Expand All @@ -152,6 +153,11 @@ func (o *DevfileState) AddImage(name string, imageName string, args []string, bu
},
},
}
if autoBuild == "never" {
container.Image.AutoBuild = pointer.Bool(false)
} else if autoBuild == "always" {
container.Image.AutoBuild = pointer.Bool(true)
}
err := o.Devfile.Data.AddComponents([]v1alpha2.Component{container})
if err != nil {
return DevfileContent{}, err
Expand Down Expand Up @@ -192,7 +198,7 @@ func (o *DevfileState) checkImageUsed(name string) error {
return nil
}

func (o *DevfileState) AddResource(name string, inlined string, uri string) (DevfileContent, error) {
func (o *DevfileState) AddResource(name string, inlined string, uri string, deployByDefault string) (DevfileContent, error) {
if inlined != "" && uri != "" {
return DevfileContent{}, errors.New("both inlined and uri cannot be set at the same time")
}
Expand All @@ -209,6 +215,12 @@ func (o *DevfileState) AddResource(name string, inlined string, uri string) (Dev
},
},
}
if deployByDefault == "never" {
container.Kubernetes.DeployByDefault = pointer.Bool(false)
} else if deployByDefault == "always" {
container.Kubernetes.DeployByDefault = pointer.Bool(true)
}

err := o.Devfile.Data.AddComponents([]v1alpha2.Component{container})
if err != nil {
return DevfileContent{}, err
Expand Down
31 changes: 22 additions & 9 deletions pkg/apiserver-impl/devstate/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func TestDevfileState_AddImage(t *testing.T) {
buildContext string
rootRequired bool
uri string
autoBuild string
}
tests := []struct {
name string
Expand All @@ -331,6 +332,7 @@ func TestDevfileState_AddImage(t *testing.T) {
buildContext: "path/to/context",
rootRequired: true,
uri: "an-uri",
autoBuild: "undefined",
},
want: DevfileContent{
Content: `components:
Expand All @@ -357,6 +359,8 @@ schemaVersion: 2.2.0
BuildContext: "path/to/context",
RootRequired: true,
Uri: "an-uri",
Orphan: true,
AutoBuild: "undefined",
},
},
Resources: []Resource{},
Expand All @@ -369,7 +373,7 @@ schemaVersion: 2.2.0
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := tt.state()
got, err := o.AddImage(tt.args.name, tt.args.imageName, tt.args.args, tt.args.buildContext, tt.args.rootRequired, tt.args.uri)
got, err := o.AddImage(tt.args.name, tt.args.imageName, tt.args.args, tt.args.buildContext, tt.args.rootRequired, tt.args.uri, tt.args.autoBuild)
if (err != nil) != tt.wantErr {
t.Errorf("DevfileState.AddImage() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down Expand Up @@ -406,6 +410,7 @@ func TestDevfileState_DeleteImage(t *testing.T) {
"path/to/context",
true,
"an-uri",
"undefined",
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -438,6 +443,7 @@ schemaVersion: 2.2.0
"path/to/context",
true,
"an-uri",
"undefined",
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -472,9 +478,10 @@ schemaVersion: 2.2.0

func TestDevfileState_AddResource(t *testing.T) {
type args struct {
name string
inline string
uri string
name string
inline string
uri string
deployByDefault string
}
tests := []struct {
name string
Expand Down Expand Up @@ -505,8 +512,10 @@ schemaVersion: 2.2.0
Images: []Image{},
Resources: []Resource{
{
Name: "a-name",
Uri: "an-uri",
Name: "a-name",
Uri: "an-uri",
Orphan: true,
DeployByDefault: "undefined",
},
},
Volumes: []Volume{},
Expand Down Expand Up @@ -535,8 +544,10 @@ schemaVersion: 2.2.0
Images: []Image{},
Resources: []Resource{
{
Name: "a-name",
Inlined: "inline resource...",
Name: "a-name",
Inlined: "inline resource...",
Orphan: true,
DeployByDefault: "undefined",
},
},
Volumes: []Volume{},
Expand All @@ -548,7 +559,7 @@ schemaVersion: 2.2.0
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := tt.state()
got, err := o.AddResource(tt.args.name, tt.args.inline, tt.args.uri)
got, err := o.AddResource(tt.args.name, tt.args.inline, tt.args.uri, tt.args.deployByDefault)
if (err != nil) != tt.wantErr {
t.Errorf("DevfileState.AddResource() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down Expand Up @@ -582,6 +593,7 @@ func TestDevfileState_Deleteresource(t *testing.T) {
"a-name",
"",
"an-uri",
"undefined",
)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -611,6 +623,7 @@ schemaVersion: 2.2.0
"a-name",
"",
"an-uri",
"undefined",
)
if err != nil {
t.Fatal(err)
Expand Down
Loading