From f6cab5a65b433637e9342a1a2994b34c814a0fd9 Mon Sep 17 00:00:00 2001 From: Javier Adriel Date: Tue, 17 May 2022 19:02:53 -0500 Subject: [PATCH] Add PVC describe API (#2007) --- models/describe_p_v_c_wrapper.go | 217 ++++++++++++++++++ operatorapi/embedded_spec.go | 186 +++++++++++++++ operatorapi/operations/operator_api.go | 12 + .../operator_api/get_p_v_c_describe.go | 88 +++++++ .../get_p_v_c_describe_parameters.go | 136 +++++++++++ .../get_p_v_c_describe_responses.go | 133 +++++++++++ .../get_p_v_c_describe_urlbuilder.go | 132 +++++++++++ operatorapi/volumes.go | 52 +++++ swagger-operator.yml | 63 +++++ 9 files changed, 1019 insertions(+) create mode 100644 models/describe_p_v_c_wrapper.go create mode 100644 operatorapi/operations/operator_api/get_p_v_c_describe.go create mode 100644 operatorapi/operations/operator_api/get_p_v_c_describe_parameters.go create mode 100644 operatorapi/operations/operator_api/get_p_v_c_describe_responses.go create mode 100644 operatorapi/operations/operator_api/get_p_v_c_describe_urlbuilder.go diff --git a/models/describe_p_v_c_wrapper.go b/models/describe_p_v_c_wrapper.go new file mode 100644 index 000000000..47cb99b21 --- /dev/null +++ b/models/describe_p_v_c_wrapper.go @@ -0,0 +1,217 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2022 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 models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// DescribePVCWrapper describe p v c wrapper +// +// swagger:model describePVCWrapper +type DescribePVCWrapper struct { + + // access modes + AccessModes []string `json:"accessModes"` + + // annotations + Annotations []*Annotation `json:"annotations"` + + // capacity + Capacity string `json:"capacity,omitempty"` + + // finalizers + Finalizers []string `json:"finalizers"` + + // labels + Labels []*Label `json:"labels"` + + // name + Name string `json:"name,omitempty"` + + // namespace + Namespace string `json:"namespace,omitempty"` + + // status + Status string `json:"status,omitempty"` + + // storage class + StorageClass string `json:"storageClass,omitempty"` + + // volume + Volume string `json:"volume,omitempty"` + + // volume mode + VolumeMode string `json:"volumeMode,omitempty"` +} + +// Validate validates this describe p v c wrapper +func (m *DescribePVCWrapper) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAnnotations(formats); err != nil { + res = append(res, err) + } + + if err := m.validateLabels(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *DescribePVCWrapper) validateAnnotations(formats strfmt.Registry) error { + if swag.IsZero(m.Annotations) { // not required + return nil + } + + for i := 0; i < len(m.Annotations); i++ { + if swag.IsZero(m.Annotations[i]) { // not required + continue + } + + if m.Annotations[i] != nil { + if err := m.Annotations[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("annotations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("annotations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *DescribePVCWrapper) validateLabels(formats strfmt.Registry) error { + if swag.IsZero(m.Labels) { // not required + return nil + } + + for i := 0; i < len(m.Labels); i++ { + if swag.IsZero(m.Labels[i]) { // not required + continue + } + + if m.Labels[i] != nil { + if err := m.Labels[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("labels" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("labels" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this describe p v c wrapper based on the context it is used +func (m *DescribePVCWrapper) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateAnnotations(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateLabels(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *DescribePVCWrapper) contextValidateAnnotations(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Annotations); i++ { + + if m.Annotations[i] != nil { + if err := m.Annotations[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("annotations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("annotations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *DescribePVCWrapper) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Labels); i++ { + + if m.Labels[i] != nil { + if err := m.Labels[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("labels" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("labels" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *DescribePVCWrapper) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *DescribePVCWrapper) UnmarshalBinary(b []byte) error { + var res DescribePVCWrapper + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/operatorapi/embedded_spec.go b/operatorapi/embedded_spec.go index 7b0e8e13e..69109e86d 100644 --- a/operatorapi/embedded_spec.go +++ b/operatorapi/embedded_spec.go @@ -1485,6 +1485,49 @@ func init() { } } }, + "/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/describe": { + "get": { + "tags": [ + "OperatorAPI" + ], + "summary": "Get Describe output for PVC", + "operationId": "GetPVCDescribe", + "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": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/describePVCWrapper" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events": { "get": { "tags": [ @@ -2352,6 +2395,56 @@ func init() { } } }, + "describePVCWrapper": { + "type": "object", + "properties": { + "accessModes": { + "type": "array", + "items": { + "type": "string" + } + }, + "annotations": { + "type": "array", + "items": { + "$ref": "#/definitions/annotation" + } + }, + "capacity": { + "type": "string" + }, + "finalizers": { + "type": "array", + "items": { + "type": "string" + } + }, + "labels": { + "type": "array", + "items": { + "$ref": "#/definitions/label" + } + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "status": { + "type": "string" + }, + "storageClass": { + "type": "string" + }, + "volume": { + "type": "string" + }, + "volumeMode": { + "type": "string" + } + } + }, "describePodWrapper": { "type": "object", "properties": { @@ -5985,6 +6078,49 @@ func init() { } } }, + "/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/describe": { + "get": { + "tags": [ + "OperatorAPI" + ], + "summary": "Get Describe output for PVC", + "operationId": "GetPVCDescribe", + "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": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/describePVCWrapper" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events": { "get": { "tags": [ @@ -7695,6 +7831,56 @@ func init() { } } }, + "describePVCWrapper": { + "type": "object", + "properties": { + "accessModes": { + "type": "array", + "items": { + "type": "string" + } + }, + "annotations": { + "type": "array", + "items": { + "$ref": "#/definitions/annotation" + } + }, + "capacity": { + "type": "string" + }, + "finalizers": { + "type": "array", + "items": { + "type": "string" + } + }, + "labels": { + "type": "array", + "items": { + "$ref": "#/definitions/label" + } + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "status": { + "type": "string" + }, + "storageClass": { + "type": "string" + }, + "volume": { + "type": "string" + }, + "volumeMode": { + "type": "string" + } + } + }, "describePodWrapper": { "type": "object", "properties": { diff --git a/operatorapi/operations/operator_api.go b/operatorapi/operations/operator_api.go index e10ea93e2..e9c37a71e 100644 --- a/operatorapi/operations/operator_api.go +++ b/operatorapi/operations/operator_api.go @@ -97,6 +97,9 @@ func NewOperatorAPI(spec *loads.Document) *OperatorAPI { OperatorAPIGetMaxAllocatableMemHandler: operator_api.GetMaxAllocatableMemHandlerFunc(func(params operator_api.GetMaxAllocatableMemParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation operator_api.GetMaxAllocatableMem has not yet been implemented") }), + OperatorAPIGetPVCDescribeHandler: operator_api.GetPVCDescribeHandlerFunc(func(params operator_api.GetPVCDescribeParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation operator_api.GetPVCDescribe has not yet been implemented") + }), OperatorAPIGetPVCEventsHandler: operator_api.GetPVCEventsHandlerFunc(func(params operator_api.GetPVCEventsParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation operator_api.GetPVCEvents has not yet been implemented") }), @@ -294,6 +297,8 @@ type OperatorAPI struct { OperatorAPIGetAllocatableResourcesHandler operator_api.GetAllocatableResourcesHandler // OperatorAPIGetMaxAllocatableMemHandler sets the operation handler for the get max allocatable mem operation OperatorAPIGetMaxAllocatableMemHandler operator_api.GetMaxAllocatableMemHandler + // OperatorAPIGetPVCDescribeHandler sets the operation handler for the get p v c describe operation + OperatorAPIGetPVCDescribeHandler operator_api.GetPVCDescribeHandler // OperatorAPIGetPVCEventsHandler sets the operation handler for the get p v c events operation OperatorAPIGetPVCEventsHandler operator_api.GetPVCEventsHandler // OperatorAPIGetParityHandler sets the operation handler for the get parity operation @@ -492,6 +497,9 @@ func (o *OperatorAPI) Validate() error { if o.OperatorAPIGetMaxAllocatableMemHandler == nil { unregistered = append(unregistered, "operator_api.GetMaxAllocatableMemHandler") } + if o.OperatorAPIGetPVCDescribeHandler == nil { + unregistered = append(unregistered, "operator_api.GetPVCDescribeHandler") + } if o.OperatorAPIGetPVCEventsHandler == nil { unregistered = append(unregistered, "operator_api.GetPVCEventsHandler") } @@ -763,6 +771,10 @@ func (o *OperatorAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) } + o.handlers["GET"]["/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/describe"] = operator_api.NewGetPVCDescribe(o.context, o.OperatorAPIGetPVCDescribeHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } o.handlers["GET"]["/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events"] = operator_api.NewGetPVCEvents(o.context, o.OperatorAPIGetPVCEventsHandler) if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) diff --git a/operatorapi/operations/operator_api/get_p_v_c_describe.go b/operatorapi/operations/operator_api/get_p_v_c_describe.go new file mode 100644 index 000000000..1e7c78350 --- /dev/null +++ b/operatorapi/operations/operator_api/get_p_v_c_describe.go @@ -0,0 +1,88 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2022 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" +) + +// GetPVCDescribeHandlerFunc turns a function with the right signature into a get p v c describe handler +type GetPVCDescribeHandlerFunc func(GetPVCDescribeParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetPVCDescribeHandlerFunc) Handle(params GetPVCDescribeParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// GetPVCDescribeHandler interface for that can handle valid get p v c describe params +type GetPVCDescribeHandler interface { + Handle(GetPVCDescribeParams, *models.Principal) middleware.Responder +} + +// NewGetPVCDescribe creates a new http.Handler for the get p v c describe operation +func NewGetPVCDescribe(ctx *middleware.Context, handler GetPVCDescribeHandler) *GetPVCDescribe { + return &GetPVCDescribe{Context: ctx, Handler: handler} +} + +/* GetPVCDescribe swagger:route GET /namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/describe OperatorAPI getPVCDescribe + +Get Describe output for PVC + +*/ +type GetPVCDescribe struct { + Context *middleware.Context + Handler GetPVCDescribeHandler +} + +func (o *GetPVCDescribe) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetPVCDescribeParams() + 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/get_p_v_c_describe_parameters.go b/operatorapi/operations/operator_api/get_p_v_c_describe_parameters.go new file mode 100644 index 000000000..2b9b863ed --- /dev/null +++ b/operatorapi/operations/operator_api/get_p_v_c_describe_parameters.go @@ -0,0 +1,136 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2022 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" +) + +// NewGetPVCDescribeParams creates a new GetPVCDescribeParams object +// +// There are no default values defined in the spec. +func NewGetPVCDescribeParams() GetPVCDescribeParams { + + return GetPVCDescribeParams{} +} + +// GetPVCDescribeParams contains all the bound params for the get p v c describe operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetPVCDescribe +type GetPVCDescribeParams 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 NewGetPVCDescribeParams() beforehand. +func (o *GetPVCDescribeParams) 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 *GetPVCDescribeParams) 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 *GetPVCDescribeParams) 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 *GetPVCDescribeParams) 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/get_p_v_c_describe_responses.go b/operatorapi/operations/operator_api/get_p_v_c_describe_responses.go new file mode 100644 index 000000000..02807f780 --- /dev/null +++ b/operatorapi/operations/operator_api/get_p_v_c_describe_responses.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2022 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" +) + +// GetPVCDescribeOKCode is the HTTP code returned for type GetPVCDescribeOK +const GetPVCDescribeOKCode int = 200 + +/*GetPVCDescribeOK A successful response. + +swagger:response getPVCDescribeOK +*/ +type GetPVCDescribeOK struct { + + /* + In: Body + */ + Payload *models.DescribePVCWrapper `json:"body,omitempty"` +} + +// NewGetPVCDescribeOK creates GetPVCDescribeOK with default headers values +func NewGetPVCDescribeOK() *GetPVCDescribeOK { + + return &GetPVCDescribeOK{} +} + +// WithPayload adds the payload to the get p v c describe o k response +func (o *GetPVCDescribeOK) WithPayload(payload *models.DescribePVCWrapper) *GetPVCDescribeOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get p v c describe o k response +func (o *GetPVCDescribeOK) SetPayload(payload *models.DescribePVCWrapper) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetPVCDescribeOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*GetPVCDescribeDefault Generic error response. + +swagger:response getPVCDescribeDefault +*/ +type GetPVCDescribeDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetPVCDescribeDefault creates GetPVCDescribeDefault with default headers values +func NewGetPVCDescribeDefault(code int) *GetPVCDescribeDefault { + if code <= 0 { + code = 500 + } + + return &GetPVCDescribeDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get p v c describe default response +func (o *GetPVCDescribeDefault) WithStatusCode(code int) *GetPVCDescribeDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get p v c describe default response +func (o *GetPVCDescribeDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get p v c describe default response +func (o *GetPVCDescribeDefault) WithPayload(payload *models.Error) *GetPVCDescribeDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get p v c describe default response +func (o *GetPVCDescribeDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetPVCDescribeDefault) 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/get_p_v_c_describe_urlbuilder.go b/operatorapi/operations/operator_api/get_p_v_c_describe_urlbuilder.go new file mode 100644 index 000000000..aa9eac7ea --- /dev/null +++ b/operatorapi/operations/operator_api/get_p_v_c_describe_urlbuilder.go @@ -0,0 +1,132 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2022 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" +) + +// GetPVCDescribeURL generates an URL for the get p v c describe operation +type GetPVCDescribeURL 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 *GetPVCDescribeURL) WithBasePath(bp string) *GetPVCDescribeURL { + 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 *GetPVCDescribeURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetPVCDescribeURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/describe" + + pVCName := o.PVCName + if pVCName != "" { + _path = strings.Replace(_path, "{PVCName}", pVCName, -1) + } else { + return nil, errors.New("pVCName is required on GetPVCDescribeURL") + } + + namespace := o.Namespace + if namespace != "" { + _path = strings.Replace(_path, "{namespace}", namespace, -1) + } else { + return nil, errors.New("namespace is required on GetPVCDescribeURL") + } + + tenant := o.Tenant + if tenant != "" { + _path = strings.Replace(_path, "{tenant}", tenant, -1) + } else { + return nil, errors.New("tenant is required on GetPVCDescribeURL") + } + + _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 *GetPVCDescribeURL) 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 *GetPVCDescribeURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetPVCDescribeURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetPVCDescribeURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetPVCDescribeURL") + } + + 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 *GetPVCDescribeURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/operatorapi/volumes.go b/operatorapi/volumes.go index 54d55f821..a43aab597 100644 --- a/operatorapi/volumes.go +++ b/operatorapi/volumes.go @@ -77,6 +77,14 @@ func registerVolumesHandlers(api *operations.OperatorAPI) { return operator_api.NewGetPVCEventsOK().WithPayload(payload) }) + + api.OperatorAPIGetPVCDescribeHandler = operator_api.GetPVCDescribeHandlerFunc(func(params operator_api.GetPVCDescribeParams, session *models.Principal) middleware.Responder { + payload, err := getPVCDescribeResponse(session, params) + if err != nil { + return operator_api.NewGetPVCDescribeDefault(int(err.Code)).WithPayload(err) + } + return operator_api.NewGetPVCDescribeOK().WithPayload(payload) + }) } func getPVCsResponse(session *models.Principal, params operator_api.ListPVCsParams) (*models.ListPVCsResponse, *models.Error) { @@ -260,3 +268,47 @@ func getTenantCSResponse(session *models.Principal, params operator_api.ListTena } return retval, nil } + +func getPVCDescribeResponse(session *models.Principal, params operator_api.GetPVCDescribeParams) (*models.DescribePVCWrapper, *models.Error) { + ctx, cancel := context.WithCancel(params.HTTPRequest.Context()) + defer cancel() + clientset, err := cluster.K8sClient(session.STSSessionToken) + if err != nil { + return nil, errors.ErrorWithContext(ctx, err) + } + pvc, err := clientset.CoreV1().PersistentVolumeClaims(params.Namespace).Get(ctx, params.PVCName, metav1.GetOptions{}) + if err != nil { + return nil, errors.ErrorWithContext(ctx, err) + } + accessModes := []string{} + for _, a := range pvc.Status.AccessModes { + accessModes = append(accessModes, string(a)) + } + return &models.DescribePVCWrapper{ + Name: pvc.Name, + Namespace: pvc.Namespace, + StorageClass: *pvc.Spec.StorageClassName, + Status: string(pvc.Status.Phase), + Volume: pvc.Spec.VolumeName, + Labels: castLabels(pvc.Labels), + Annotations: castAnnotations(pvc.Annotations), + Finalizers: pvc.Finalizers, + Capacity: pvc.Status.Capacity.Storage().String(), + AccessModes: accessModes, + VolumeMode: string(*pvc.Spec.VolumeMode), + }, nil +} + +func castLabels(labelsToCast map[string]string) (labels []*models.Label) { + for k, v := range labelsToCast { + labels = append(labels, &models.Label{Key: k, Value: v}) + } + return labels +} + +func castAnnotations(annotationsToCast map[string]string) (annotations []*models.Annotation) { + for k, v := range annotationsToCast { + annotations = append(annotations, &models.Annotation{Key: k, Value: v}) + } + return annotations +} diff --git a/swagger-operator.yml b/swagger-operator.yml index 89ac5ee3b..e856181b7 100644 --- a/swagger-operator.yml +++ b/swagger-operator.yml @@ -1288,6 +1288,35 @@ paths: tags: - OperatorAPI + /namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/describe: + get: + summary: Get Describe output for PVC + operationId: GetPVCDescribe + 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: + 200: + description: A successful response. + schema: + $ref: "#/definitions/describePVCWrapper" + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - OperatorAPI + /nodes/labels: get: summary: List node labels @@ -2962,6 +2991,40 @@ definitions: items: $ref: "#/definitions/toleration" + describePVCWrapper: + type: object + properties: + name: + type: string + namespace: + type: string + storageClass: + type: string + status: + type: string + volume: + type: string + labels: + type: array + items: + $ref: "#/definitions/label" + annotations: + type: array + items: + $ref: "#/definitions/annotation" + finalizers: + type: array + items: + type: string + capacity: + type: string + accessModes: + type: array + items: + type: string + volumeMode: + type: string + container: type: object properties: