diff --git a/ododevapispec.yaml b/ododevapispec.yaml index 375a12c712..b40591ec58 100644 --- a/ododevapispec.yaml +++ b/ododevapispec.yaml @@ -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: diff --git a/pkg/apiserver-gen/.openapi-generator/FILES b/pkg/apiserver-gen/.openapi-generator/FILES index 29e9d4766f..32603d8e3a 100644 --- a/pkg/apiserver-gen/.openapi-generator/FILES +++ b/pkg/apiserver-gen/.openapi-generator/FILES @@ -20,6 +20,7 @@ go/model__devstate_exec_command_post_request.go go/model__devstate_image_post_request.go go/model__devstate_quantity_valid_post_request.go go/model__devstate_resource_post_request.go +go/model__devstate_volume__volume_name__patch_request.go go/model__devstate_volume_post_request.go go/model__instance_get_200_response.go go/model_annotation.go diff --git a/pkg/apiserver-gen/go/api.go b/pkg/apiserver-gen/go/api.go index d7361a6f80..e586ae9515 100644 --- a/pkg/apiserver-gen/go/api.go +++ b/pkg/apiserver-gen/go/api.go @@ -53,6 +53,7 @@ type DevstateApiRouter interface { DevstateResourceResourceNameDelete(http.ResponseWriter, *http.Request) DevstateVolumePost(http.ResponseWriter, *http.Request) DevstateVolumeVolumeNameDelete(http.ResponseWriter, *http.Request) + DevstateVolumeVolumeNamePatch(http.ResponseWriter, *http.Request) } // DefaultApiServicer defines the api actions for the DefaultApi service @@ -96,4 +97,5 @@ type DevstateApiServicer interface { DevstateResourceResourceNameDelete(context.Context, string) (ImplResponse, error) DevstateVolumePost(context.Context, DevstateVolumePostRequest) (ImplResponse, error) DevstateVolumeVolumeNameDelete(context.Context, string) (ImplResponse, error) + DevstateVolumeVolumeNamePatch(context.Context, string, DevstateVolumeVolumeNamePatchRequest) (ImplResponse, error) } diff --git a/pkg/apiserver-gen/go/api_devstate.go b/pkg/apiserver-gen/go/api_devstate.go index 4693b12b3b..b3af49df9e 100644 --- a/pkg/apiserver-gen/go/api_devstate.go +++ b/pkg/apiserver-gen/go/api_devstate.go @@ -182,6 +182,12 @@ func (c *DevstateApiController) Routes() Routes { "/api/v1/devstate/volume/{volumeName}", c.DevstateVolumeVolumeNameDelete, }, + { + "DevstateVolumeVolumeNamePatch", + strings.ToUpper("Patch"), + "/api/v1/devstate/volume/{volumeName}", + c.DevstateVolumeVolumeNamePatch, + }, } } @@ -629,3 +635,29 @@ func (c *DevstateApiController) DevstateVolumeVolumeNameDelete(w http.ResponseWr EncodeJSONResponse(result.Body, &result.Code, w) } + +// DevstateVolumeVolumeNamePatch - +func (c *DevstateApiController) DevstateVolumeVolumeNamePatch(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + volumeNameParam := params["volumeName"] + devstateVolumeVolumeNamePatchRequestParam := DevstateVolumeVolumeNamePatchRequest{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&devstateVolumeVolumeNamePatchRequestParam); err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + if err := AssertDevstateVolumeVolumeNamePatchRequestRequired(devstateVolumeVolumeNamePatchRequestParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + result, err := c.service.DevstateVolumeVolumeNamePatch(r.Context(), volumeNameParam, devstateVolumeVolumeNamePatchRequestParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + EncodeJSONResponse(result.Body, &result.Code, w) + +} diff --git a/pkg/apiserver-gen/go/model__devstate_volume__volume_name__patch_request.go b/pkg/apiserver-gen/go/model__devstate_volume__volume_name__patch_request.go new file mode 100644 index 0000000000..806d944d6f --- /dev/null +++ b/pkg/apiserver-gen/go/model__devstate_volume__volume_name__patch_request.go @@ -0,0 +1,36 @@ +/* + * odo dev + * + * API interface for 'odo dev' + * + * API version: 0.1 + * Generated by: OpenAPI Generator (https://openapi-generator.tech) + */ + +package openapi + +type DevstateVolumeVolumeNamePatchRequest struct { + + // Minimal size of the volume + Size string `json:"size,omitempty"` + + // True if the Volume is Ephemeral + Ephemeral bool `json:"ephemeral,omitempty"` +} + +// AssertDevstateVolumeVolumeNamePatchRequestRequired checks if the required fields are not zero-ed +func AssertDevstateVolumeVolumeNamePatchRequestRequired(obj DevstateVolumeVolumeNamePatchRequest) error { + return nil +} + +// AssertRecurseDevstateVolumeVolumeNamePatchRequestRequired recursively checks if required fields are not zero-ed in a nested slice. +// Accepts only nested slice of DevstateVolumeVolumeNamePatchRequest (e.g. [][]DevstateVolumeVolumeNamePatchRequest), otherwise ErrTypeAssertionError is thrown. +func AssertRecurseDevstateVolumeVolumeNamePatchRequestRequired(objSlice interface{}) error { + return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error { + aDevstateVolumeVolumeNamePatchRequest, ok := obj.(DevstateVolumeVolumeNamePatchRequest) + if !ok { + return ErrTypeAssertionError + } + return AssertDevstateVolumeVolumeNamePatchRequestRequired(aDevstateVolumeVolumeNamePatchRequest) + }) +} diff --git a/pkg/apiserver-impl/devstate.go b/pkg/apiserver-impl/devstate.go index 686154364c..2395ecbda2 100644 --- a/pkg/apiserver-impl/devstate.go +++ b/pkg/apiserver-impl/devstate.go @@ -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 + +} diff --git a/pkg/apiserver-impl/devstate/components.go b/pkg/apiserver-impl/devstate/components.go index 97f6bc67a5..2d210f0521 100644 --- a/pkg/apiserver-impl/devstate/components.go +++ b/pkg/apiserver-impl/devstate/components.go @@ -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) diff --git a/pkg/apiserver-impl/swagger-ui/swagger.yaml b/pkg/apiserver-impl/swagger-ui/swagger.yaml index 375a12c712..b40591ec58 100644 --- a/pkg/apiserver-impl/swagger-ui/swagger.yaml +++ b/pkg/apiserver-impl/swagger-ui/swagger.yaml @@ -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: diff --git a/pkg/apiserver-impl/ui/index.html b/pkg/apiserver-impl/ui/index.html index f19249a75d..a988efec2f 100644 --- a/pkg/apiserver-impl/ui/index.html +++ b/pkg/apiserver-impl/ui/index.html @@ -11,6 +11,6 @@