Skip to content

Commit

Permalink
[ui] Edit volumes (#7061)
Browse files Browse the repository at this point in the history
* Update volumes

* Proxy use ipv4

* Static ui files

* e2e tests
  • Loading branch information
feloy authored Aug 31, 2023
1 parent 9089f9a commit 7ff38b7
Show file tree
Hide file tree
Showing 21 changed files with 387 additions and 14 deletions.
41 changes: 41 additions & 0 deletions ododevapispec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,47 @@ paths:
example:
message: "Error deleting the volume"

patch:
tags:
- devstate
description: "Update a volume"
parameters:
- name: volumeName
in: path
description: Volume name to update
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
size:
description: Minimal size of the volume
type: string
ephemeral:
description: True if the Volume is Ephemeral
type: boolean
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralSuccess'
example:
message: "Volume has been updated"
description: "Volume has been updated"
'500':
description: Error updating the volume
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "Error updating the volume"

/devstate/applyCommand:
post:
tags:
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver-gen/.openapi-generator/FILES

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/api.go

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

32 changes: 32 additions & 0 deletions pkg/apiserver-gen/go/api_devstate.go

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

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

15 changes: 15 additions & 0 deletions pkg/apiserver-impl/devstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,18 @@ func (s *DevstateApiService) DevstateDevfileDelete(context.Context) (openapi.Imp
}
return openapi.Response(http.StatusOK, newContent), nil
}

func (s *DevstateApiService) DevstateVolumeVolumeNamePatch(ctx context.Context, name string, patch openapi.DevstateVolumeVolumeNamePatchRequest) (openapi.ImplResponse, error) {
newContent, err := s.devfileState.PatchVolume(
name,
patch.Ephemeral,
patch.Size,
)
if err != nil {
return openapi.Response(http.StatusInternalServerError, openapi.GeneralError{
Message: fmt.Sprintf("Error updating the volume: %s", err),
}), nil
}
return openapi.Response(http.StatusOK, newContent), nil

}
26 changes: 25 additions & 1 deletion pkg/apiserver-impl/devstate/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,32 @@ func (o *DevfileState) AddVolume(name string, ephemeral bool, size string) (Devf
return o.GetContent()
}

func (o *DevfileState) DeleteVolume(name string) (DevfileContent, error) {
func (o *DevfileState) PatchVolume(name string, ephemeral bool, size string) (DevfileContent, error) {
found, err := o.Devfile.Data.GetComponents(common.DevfileOptions{
ComponentOptions: common.ComponentOptions{
ComponentType: v1alpha2.VolumeComponentType,
},
FilterByName: name,
})
if err != nil {
return DevfileContent{}, err
}
if len(found) != 1 {
return DevfileContent{}, fmt.Errorf("%d Volume found with name %q", len(found), name)
}

volume := found[0]
volume.Volume.Ephemeral = &ephemeral
volume.Volume.Size = size

err = o.Devfile.Data.UpdateComponent(volume)
if err != nil {
return DevfileContent{}, err
}
return o.GetContent()
}

func (o *DevfileState) DeleteVolume(name string) (DevfileContent, error) {
err := o.checkVolumeUsed(name)
if err != nil {
return DevfileContent{}, fmt.Errorf("error deleting volume %q: %w", name, err)
Expand Down
41 changes: 41 additions & 0 deletions pkg/apiserver-impl/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,47 @@ paths:
example:
message: "Error deleting the volume"

patch:
tags:
- devstate
description: "Update a volume"
parameters:
- name: volumeName
in: path
description: Volume name to update
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
size:
description: Minimal size of the volume
type: string
ephemeral:
description: True if the Volume is Ephemeral
type: boolean
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralSuccess'
example:
message: "Volume has been updated"
description: "Volume has been updated"
'500':
description: Error updating the volume
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "Error updating the volume"

/devstate/applyCommand:
post:
tags:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver-impl/ui/index.html

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

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions ui/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ describe('devfile editor spec', () => {
.should('contain.text', 'Yes')
});

it('displays a modified volume', () => {
cy.init();

cy.selectTab(TAB_VOLUMES);
cy.getByDataCy('volume-name').type('created-volume');
cy.getByDataCy('volume-size').type('512Mi');
cy.getByDataCy('volume-ephemeral').click();
cy.getByDataCy('volume-create').click();

cy.getByDataCy('volume-info').first()
.should('contain.text', 'created-volume')
.should('contain.text', '512Mi')
.should('contain.text', 'Yes');

cy.getByDataCy('volume-edit').click();
cy.getByDataCy('volume-size').type('{selectAll}{del}1Gi');
cy.getByDataCy('volume-ephemeral').click();
cy.getByDataCy('volume-save').click();

cy.getByDataCy('volume-info').first()
.should('contain.text', 'created-volume')
.should('contain.text', '1Gi')
.should('contain.text', 'No');
});

it('creates an exec command with a new container', () => {
cy.init();

Expand Down
1 change: 1 addition & 0 deletions ui/src/app/api-gen/.openapi-generator/FILES

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

71 changes: 71 additions & 0 deletions ui/src/app/api-gen/api/devstate.service.ts

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

Loading

0 comments on commit 7ff38b7

Please sign in to comment.