From 9997afeedc13b3a788bf062e7296d2b766a9e87f Mon Sep 17 00:00:00 2001 From: adfost Date: Tue, 11 Jan 2022 12:28:15 -0800 Subject: [PATCH] Delete PVC API commit (#1378) * Delete PVC API commit * Delete install_nvm.sh --- operatorapi/embedded_spec.go | 80 +++++++++++ operatorapi/operations/operator_api.go | 12 ++ .../operations/operator_api/delete_p_v_c.go | 88 ++++++++++++ .../operator_api/delete_p_v_c_parameters.go | 136 ++++++++++++++++++ .../operator_api/delete_p_v_c_responses.go | 113 +++++++++++++++ .../operator_api/delete_p_v_c_urlbuilder.go | 132 +++++++++++++++++ operatorapi/operator_volumes.go | 25 ++++ swagger-operator.yml | 27 ++++ 8 files changed, 613 insertions(+) create mode 100644 operatorapi/operations/operator_api/delete_p_v_c.go create mode 100644 operatorapi/operations/operator_api/delete_p_v_c_parameters.go create mode 100644 operatorapi/operations/operator_api/delete_p_v_c_responses.go create mode 100644 operatorapi/operations/operator_api/delete_p_v_c_urlbuilder.go diff --git a/operatorapi/embedded_spec.go b/operatorapi/embedded_spec.go index a1c8cba65..0e6937079 100644 --- a/operatorapi/embedded_spec.go +++ b/operatorapi/embedded_spec.go @@ -1030,6 +1030,46 @@ func init() { } } }, + "/namespaces/{namespace}/tenants/{tenant}/pvc/{PVCName}": { + "delete": { + "tags": [ + "OperatorAPI" + ], + "summary": "Delete PVC", + "operationId": "DeletePVC", + "parameters": [ + { + "type": "string", + "name": "namespace", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "tenant", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "PVCName", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "A successful response." + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/tenants/{tenant}/pvcs": { "get": { "tags": [ @@ -4401,6 +4441,46 @@ func init() { } } }, + "/namespaces/{namespace}/tenants/{tenant}/pvc/{PVCName}": { + "delete": { + "tags": [ + "OperatorAPI" + ], + "summary": "Delete PVC", + "operationId": "DeletePVC", + "parameters": [ + { + "type": "string", + "name": "namespace", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "tenant", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "PVCName", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "A successful response." + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/tenants/{tenant}/pvcs": { "get": { "tags": [ diff --git a/operatorapi/operations/operator_api.go b/operatorapi/operations/operator_api.go index aefaa9180..23c57b724 100644 --- a/operatorapi/operations/operator_api.go +++ b/operatorapi/operations/operator_api.go @@ -69,6 +69,9 @@ func NewOperatorAPI(spec *loads.Document) *OperatorAPI { OperatorAPICreateTenantHandler: operator_api.CreateTenantHandlerFunc(func(params operator_api.CreateTenantParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation operator_api.CreateTenant has not yet been implemented") }), + OperatorAPIDeletePVCHandler: operator_api.DeletePVCHandlerFunc(func(params operator_api.DeletePVCParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation operator_api.DeletePVC has not yet been implemented") + }), OperatorAPIDeletePodHandler: operator_api.DeletePodHandlerFunc(func(params operator_api.DeletePodParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation operator_api.DeletePod has not yet been implemented") }), @@ -239,6 +242,8 @@ type OperatorAPI struct { OperatorAPICreateNamespaceHandler operator_api.CreateNamespaceHandler // OperatorAPICreateTenantHandler sets the operation handler for the create tenant operation OperatorAPICreateTenantHandler operator_api.CreateTenantHandler + // OperatorAPIDeletePVCHandler sets the operation handler for the delete p v c operation + OperatorAPIDeletePVCHandler operator_api.DeletePVCHandler // OperatorAPIDeletePodHandler sets the operation handler for the delete pod operation OperatorAPIDeletePodHandler operator_api.DeletePodHandler // OperatorAPIDeleteTenantHandler sets the operation handler for the delete tenant operation @@ -404,6 +409,9 @@ func (o *OperatorAPI) Validate() error { if o.OperatorAPICreateTenantHandler == nil { unregistered = append(unregistered, "operator_api.CreateTenantHandler") } + if o.OperatorAPIDeletePVCHandler == nil { + unregistered = append(unregistered, "operator_api.DeletePVCHandler") + } if o.OperatorAPIDeletePodHandler == nil { unregistered = append(unregistered, "operator_api.DeletePodHandler") } @@ -630,6 +638,10 @@ func (o *OperatorAPI) initHandlerCache() { if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) } + o.handlers["DELETE"]["/namespaces/{namespace}/tenants/{tenant}/pvc/{PVCName}"] = operator_api.NewDeletePVC(o.context, o.OperatorAPIDeletePVCHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } o.handlers["DELETE"]["/namespaces/{namespace}/tenants/{tenant}/pods/{podName}"] = operator_api.NewDeletePod(o.context, o.OperatorAPIDeletePodHandler) if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) diff --git a/operatorapi/operations/operator_api/delete_p_v_c.go b/operatorapi/operations/operator_api/delete_p_v_c.go new file mode 100644 index 000000000..5803c35f1 --- /dev/null +++ b/operatorapi/operations/operator_api/delete_p_v_c.go @@ -0,0 +1,88 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package operator_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" + + "github.com/minio/console/models" +) + +// DeletePVCHandlerFunc turns a function with the right signature into a delete p v c handler +type DeletePVCHandlerFunc func(DeletePVCParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeletePVCHandlerFunc) Handle(params DeletePVCParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// DeletePVCHandler interface for that can handle valid delete p v c params +type DeletePVCHandler interface { + Handle(DeletePVCParams, *models.Principal) middleware.Responder +} + +// NewDeletePVC creates a new http.Handler for the delete p v c operation +func NewDeletePVC(ctx *middleware.Context, handler DeletePVCHandler) *DeletePVC { + return &DeletePVC{Context: ctx, Handler: handler} +} + +/* DeletePVC swagger:route DELETE /namespaces/{namespace}/tenants/{tenant}/pvc/{PVCName} OperatorAPI deletePVC + +Delete PVC + +*/ +type DeletePVC struct { + Context *middleware.Context + Handler DeletePVCHandler +} + +func (o *DeletePVC) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeletePVCParams() + uprinc, aCtx, err := o.Context.Authorize(r, route) + if err != nil { + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + if aCtx != nil { + *r = *aCtx + } + var principal *models.Principal + if uprinc != nil { + principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise + } + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params, principal) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/operatorapi/operations/operator_api/delete_p_v_c_parameters.go b/operatorapi/operations/operator_api/delete_p_v_c_parameters.go new file mode 100644 index 000000000..67bd89459 --- /dev/null +++ b/operatorapi/operations/operator_api/delete_p_v_c_parameters.go @@ -0,0 +1,136 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package operator_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewDeletePVCParams creates a new DeletePVCParams object +// +// There are no default values defined in the spec. +func NewDeletePVCParams() DeletePVCParams { + + return DeletePVCParams{} +} + +// DeletePVCParams contains all the bound params for the delete p v c operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeletePVC +type DeletePVCParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + PVCName string + /* + Required: true + In: path + */ + Namespace string + /* + Required: true + In: path + */ + Tenant string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeletePVCParams() beforehand. +func (o *DeletePVCParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rPVCName, rhkPVCName, _ := route.Params.GetOK("PVCName") + if err := o.bindPVCName(rPVCName, rhkPVCName, route.Formats); err != nil { + res = append(res, err) + } + + rNamespace, rhkNamespace, _ := route.Params.GetOK("namespace") + if err := o.bindNamespace(rNamespace, rhkNamespace, route.Formats); err != nil { + res = append(res, err) + } + + rTenant, rhkTenant, _ := route.Params.GetOK("tenant") + if err := o.bindTenant(rTenant, rhkTenant, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindPVCName binds and validates parameter PVCName from path. +func (o *DeletePVCParams) bindPVCName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.PVCName = raw + + return nil +} + +// bindNamespace binds and validates parameter Namespace from path. +func (o *DeletePVCParams) bindNamespace(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Namespace = raw + + return nil +} + +// bindTenant binds and validates parameter Tenant from path. +func (o *DeletePVCParams) bindTenant(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Tenant = raw + + return nil +} diff --git a/operatorapi/operations/operator_api/delete_p_v_c_responses.go b/operatorapi/operations/operator_api/delete_p_v_c_responses.go new file mode 100644 index 000000000..7a35ad6e8 --- /dev/null +++ b/operatorapi/operations/operator_api/delete_p_v_c_responses.go @@ -0,0 +1,113 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package operator_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/minio/console/models" +) + +// DeletePVCNoContentCode is the HTTP code returned for type DeletePVCNoContent +const DeletePVCNoContentCode int = 204 + +/*DeletePVCNoContent A successful response. + +swagger:response deletePVCNoContent +*/ +type DeletePVCNoContent struct { +} + +// NewDeletePVCNoContent creates DeletePVCNoContent with default headers values +func NewDeletePVCNoContent() *DeletePVCNoContent { + + return &DeletePVCNoContent{} +} + +// WriteResponse to the client +func (o *DeletePVCNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +/*DeletePVCDefault Generic error response. + +swagger:response deletePVCDefault +*/ +type DeletePVCDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeletePVCDefault creates DeletePVCDefault with default headers values +func NewDeletePVCDefault(code int) *DeletePVCDefault { + if code <= 0 { + code = 500 + } + + return &DeletePVCDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the delete p v c default response +func (o *DeletePVCDefault) WithStatusCode(code int) *DeletePVCDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the delete p v c default response +func (o *DeletePVCDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the delete p v c default response +func (o *DeletePVCDefault) WithPayload(payload *models.Error) *DeletePVCDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete p v c default response +func (o *DeletePVCDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeletePVCDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/operatorapi/operations/operator_api/delete_p_v_c_urlbuilder.go b/operatorapi/operations/operator_api/delete_p_v_c_urlbuilder.go new file mode 100644 index 000000000..703c0902d --- /dev/null +++ b/operatorapi/operations/operator_api/delete_p_v_c_urlbuilder.go @@ -0,0 +1,132 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2021 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package operator_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeletePVCURL generates an URL for the delete p v c operation +type DeletePVCURL struct { + PVCName string + Namespace string + Tenant string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeletePVCURL) WithBasePath(bp string) *DeletePVCURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeletePVCURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeletePVCURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/namespaces/{namespace}/tenants/{tenant}/pvc/{PVCName}" + + pVCName := o.PVCName + if pVCName != "" { + _path = strings.Replace(_path, "{PVCName}", pVCName, -1) + } else { + return nil, errors.New("pVCName is required on DeletePVCURL") + } + + namespace := o.Namespace + if namespace != "" { + _path = strings.Replace(_path, "{namespace}", namespace, -1) + } else { + return nil, errors.New("namespace is required on DeletePVCURL") + } + + tenant := o.Tenant + if tenant != "" { + _path = strings.Replace(_path, "{tenant}", tenant, -1) + } else { + return nil, errors.New("tenant is required on DeletePVCURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/api/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeletePVCURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeletePVCURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeletePVCURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeletePVCURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeletePVCURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeletePVCURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/operatorapi/operator_volumes.go b/operatorapi/operator_volumes.go index cf3e4785a..1a4ac9b21 100644 --- a/operatorapi/operator_volumes.go +++ b/operatorapi/operator_volumes.go @@ -50,6 +50,14 @@ func registerVolumesHandlers(api *operations.OperatorAPI) { return operator_api.NewListPVCsForTenantOK().WithPayload(payload) }) + + api.OperatorAPIDeletePVCHandler = operator_api.DeletePVCHandlerFunc(func(params operator_api.DeletePVCParams, session *models.Principal) middleware.Responder { + err := getDeletePVCResponse(session, params) + if err != nil { + return operator_api.NewDeletePVCDefault(int(err.Code)).WithPayload(err) + } + return nil + }) } func getPVCsResponse(session *models.Principal) (*models.ListPVCsResponse, *models.Error) { @@ -137,3 +145,20 @@ func getPVCsForTenantResponse(session *models.Principal, params operator_api.Lis return &PVCsResponse, nil } + +func getDeletePVCResponse(session *models.Principal, params operator_api.DeletePVCParams) *models.Error { + ctx := context.Background() + // get Kubernetes Client + clientset, err := cluster.K8sClient(session.STSSessionToken) + if err != nil { + return prepareError(err) + } + listOpts := metav1.ListOptions{ + LabelSelector: fmt.Sprintf("v1.min.io/tenant=%s", params.Tenant), + FieldSelector: fmt.Sprintf("metadata.name=%s", params.PVCName), + } + if err = clientset.CoreV1().PersistentVolumeClaims(params.Namespace).DeleteCollection(ctx, metav1.DeleteOptions{}, listOpts); err != nil { + return prepareError(err) + } + return nil +} diff --git a/swagger-operator.yml b/swagger-operator.yml index 775cadef2..a51b44dab 100644 --- a/swagger-operator.yml +++ b/swagger-operator.yml @@ -980,6 +980,33 @@ paths: tags: - OperatorAPI + /namespaces/{namespace}/tenants/{tenant}/pvc/{PVCName}: + delete: + summary: Delete PVC + operationId: DeletePVC + parameters: + - name: namespace + in: path + required: true + type: string + - name: tenant + in: path + required: true + type: string + - name: PVCName + in: path + required: true + type: string + responses: + 204: + description: A successful response. + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - OperatorAPI + /nodes/labels: get: summary: List node labels