PVC Events API (#1409)

Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com>
This commit is contained in:
adfost
2022-01-24 17:07:32 -08:00
committed by GitHub
parent d1d3c96777
commit 9e7874cc04
8 changed files with 661 additions and 0 deletions

View File

@@ -1261,6 +1261,49 @@ func init() {
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "Get Events for PVC",
"operationId": "GetPVCEvents",
"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/eventListWrapper"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/security": {
"get": {
"tags": [
@@ -4891,6 +4934,49 @@ func init() {
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "Get Events for PVC",
"operationId": "GetPVCEvents",
"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/eventListWrapper"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/security": {
"get": {
"tags": [

View File

@@ -99,6 +99,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")
}),
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")
}),
OperatorAPIGetParityHandler: operator_api.GetParityHandlerFunc(func(params operator_api.GetParityParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.GetParity has not yet been implemented")
}),
@@ -274,6 +277,8 @@ type OperatorAPI struct {
OperatorAPIGetDirectCSIVolumeListHandler operator_api.GetDirectCSIVolumeListHandler
// OperatorAPIGetMaxAllocatableMemHandler sets the operation handler for the get max allocatable mem operation
OperatorAPIGetMaxAllocatableMemHandler operator_api.GetMaxAllocatableMemHandler
// 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
OperatorAPIGetParityHandler operator_api.GetParityHandler
// OperatorAPIGetPodEventsHandler sets the operation handler for the get pod events operation
@@ -459,6 +464,9 @@ func (o *OperatorAPI) Validate() error {
if o.OperatorAPIGetMaxAllocatableMemHandler == nil {
unregistered = append(unregistered, "operator_api.GetMaxAllocatableMemHandler")
}
if o.OperatorAPIGetPVCEventsHandler == nil {
unregistered = append(unregistered, "operator_api.GetPVCEventsHandler")
}
if o.OperatorAPIGetParityHandler == nil {
unregistered = append(unregistered, "operator_api.GetParityHandler")
}
@@ -710,6 +718,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}/events"] = operator_api.NewGetPVCEvents(o.context, o.OperatorAPIGetPVCEventsHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/get-parity/{nodes}/{disksPerNode}"] = operator_api.NewGetParity(o.context, o.OperatorAPIGetParityHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)

View File

@@ -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 <http://www.gnu.org/licenses/>.
//
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"
)
// GetPVCEventsHandlerFunc turns a function with the right signature into a get p v c events handler
type GetPVCEventsHandlerFunc func(GetPVCEventsParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn GetPVCEventsHandlerFunc) Handle(params GetPVCEventsParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// GetPVCEventsHandler interface for that can handle valid get p v c events params
type GetPVCEventsHandler interface {
Handle(GetPVCEventsParams, *models.Principal) middleware.Responder
}
// NewGetPVCEvents creates a new http.Handler for the get p v c events operation
func NewGetPVCEvents(ctx *middleware.Context, handler GetPVCEventsHandler) *GetPVCEvents {
return &GetPVCEvents{Context: ctx, Handler: handler}
}
/* GetPVCEvents swagger:route GET /namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events OperatorAPI getPVCEvents
Get Events for PVC
*/
type GetPVCEvents struct {
Context *middleware.Context
Handler GetPVCEventsHandler
}
func (o *GetPVCEvents) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewGetPVCEventsParams()
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)
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
//
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"
)
// NewGetPVCEventsParams creates a new GetPVCEventsParams object
//
// There are no default values defined in the spec.
func NewGetPVCEventsParams() GetPVCEventsParams {
return GetPVCEventsParams{}
}
// GetPVCEventsParams contains all the bound params for the get p v c events operation
// typically these are obtained from a http.Request
//
// swagger:parameters GetPVCEvents
type GetPVCEventsParams 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 NewGetPVCEventsParams() beforehand.
func (o *GetPVCEventsParams) 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 *GetPVCEventsParams) 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 *GetPVCEventsParams) 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 *GetPVCEventsParams) 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
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
//
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"
)
// GetPVCEventsOKCode is the HTTP code returned for type GetPVCEventsOK
const GetPVCEventsOKCode int = 200
/*GetPVCEventsOK A successful response.
swagger:response getPVCEventsOK
*/
type GetPVCEventsOK struct {
/*
In: Body
*/
Payload models.EventListWrapper `json:"body,omitempty"`
}
// NewGetPVCEventsOK creates GetPVCEventsOK with default headers values
func NewGetPVCEventsOK() *GetPVCEventsOK {
return &GetPVCEventsOK{}
}
// WithPayload adds the payload to the get p v c events o k response
func (o *GetPVCEventsOK) WithPayload(payload models.EventListWrapper) *GetPVCEventsOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get p v c events o k response
func (o *GetPVCEventsOK) SetPayload(payload models.EventListWrapper) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetPVCEventsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
payload := o.Payload
if payload == nil {
// return empty array
payload = models.EventListWrapper{}
}
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
/*GetPVCEventsDefault Generic error response.
swagger:response getPVCEventsDefault
*/
type GetPVCEventsDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewGetPVCEventsDefault creates GetPVCEventsDefault with default headers values
func NewGetPVCEventsDefault(code int) *GetPVCEventsDefault {
if code <= 0 {
code = 500
}
return &GetPVCEventsDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the get p v c events default response
func (o *GetPVCEventsDefault) WithStatusCode(code int) *GetPVCEventsDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the get p v c events default response
func (o *GetPVCEventsDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the get p v c events default response
func (o *GetPVCEventsDefault) WithPayload(payload *models.Error) *GetPVCEventsDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get p v c events default response
func (o *GetPVCEventsDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetPVCEventsDefault) 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
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
//
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"
)
// GetPVCEventsURL generates an URL for the get p v c events operation
type GetPVCEventsURL 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 *GetPVCEventsURL) WithBasePath(bp string) *GetPVCEventsURL {
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 *GetPVCEventsURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *GetPVCEventsURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/namespaces/{namespace}/tenants/{tenant}/pvcs/{PVCName}/events"
pVCName := o.PVCName
if pVCName != "" {
_path = strings.Replace(_path, "{PVCName}", pVCName, -1)
} else {
return nil, errors.New("pVCName is required on GetPVCEventsURL")
}
namespace := o.Namespace
if namespace != "" {
_path = strings.Replace(_path, "{namespace}", namespace, -1)
} else {
return nil, errors.New("namespace is required on GetPVCEventsURL")
}
tenant := o.Tenant
if tenant != "" {
_path = strings.Replace(_path, "{tenant}", tenant, -1)
} else {
return nil, errors.New("tenant is required on GetPVCEventsURL")
}
_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 *GetPVCEventsURL) 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 *GetPVCEventsURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *GetPVCEventsURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on GetPVCEventsURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on GetPVCEventsURL")
}
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 *GetPVCEventsURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -19,6 +19,7 @@ package operatorapi
import (
"context"
"fmt"
"sort"
miniov1 "github.com/minio/operator/pkg/apis/minio.min.io/v1"
@@ -58,6 +59,17 @@ func registerVolumesHandlers(api *operations.OperatorAPI) {
}
return nil
})
api.OperatorAPIGetPVCEventsHandler = operator_api.GetPVCEventsHandlerFunc(func(params operator_api.GetPVCEventsParams, session *models.Principal) middleware.Responder {
payload, err := getPVCEventsResponse(session, params)
if err != nil {
return operator_api.NewGetPVCEventsDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewGetPVCEventsOK().WithPayload(payload)
})
}
func getPVCsResponse(session *models.Principal) (*models.ListPVCsResponse, *models.Error) {
@@ -162,3 +174,33 @@ func getDeletePVCResponse(session *models.Principal, params operator_api.DeleteP
}
return nil
}
func getPVCEventsResponse(session *models.Principal, params operator_api.GetPVCEventsParams) (models.EventListWrapper, *models.Error) {
ctx := context.Background()
clientset, err := cluster.K8sClient(session.STSSessionToken)
if err != nil {
return nil, prepareError(err)
}
PVC, err := clientset.CoreV1().PersistentVolumeClaims(params.Namespace).Get(ctx, params.PVCName, metav1.GetOptions{})
if err != nil {
return nil, prepareError(err)
}
events, err := clientset.CoreV1().Events(params.Namespace).List(ctx, metav1.ListOptions{FieldSelector: fmt.Sprintf("involvedObject.uid=%s", PVC.UID)})
if err != nil {
return nil, prepareError(err)
}
retval := models.EventListWrapper{}
for i := 0; i < len(events.Items); i++ {
retval = append(retval, &models.EventListElement{
Namespace: events.Items[i].Namespace,
LastSeen: events.Items[i].LastTimestamp.Unix(),
Message: events.Items[i].Message,
EventType: events.Items[i].Type,
Reason: events.Items[i].Reason,
})
}
sort.SliceStable(retval, func(i int, j int) bool {
return retval[i].LastSeen < retval[j].LastSeen
})
return retval, nil
}