tenant events (#1586)

Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
adfost
2022-02-16 14:22:54 -08:00
committed by GitHub
parent f8c397e231
commit 35f9743a10
8 changed files with 613 additions and 0 deletions

View File

@@ -778,6 +778,43 @@ func init() {
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/events": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "Get Events for given Tenant",
"operationId": "GetTenantEvents",
"parameters": [
{
"type": "string",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"name": "tenant",
"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}/log": {
"get": {
"tags": [
@@ -4466,6 +4503,43 @@ func init() {
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/events": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "Get Events for given Tenant",
"operationId": "GetTenantEvents",
"parameters": [
{
"type": "string",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"name": "tenant",
"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}/log": {
"get": {
"tags": [

View File

@@ -114,6 +114,9 @@ func NewOperatorAPI(spec *loads.Document) *OperatorAPI {
OperatorAPIGetResourceQuotaHandler: operator_api.GetResourceQuotaHandlerFunc(func(params operator_api.GetResourceQuotaParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.GetResourceQuota has not yet been implemented")
}),
OperatorAPIGetTenantEventsHandler: operator_api.GetTenantEventsHandlerFunc(func(params operator_api.GetTenantEventsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.GetTenantEvents has not yet been implemented")
}),
OperatorAPIGetTenantLogsHandler: operator_api.GetTenantLogsHandlerFunc(func(params operator_api.GetTenantLogsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.GetTenantLogs has not yet been implemented")
}),
@@ -287,6 +290,8 @@ type OperatorAPI struct {
OperatorAPIGetPodLogsHandler operator_api.GetPodLogsHandler
// OperatorAPIGetResourceQuotaHandler sets the operation handler for the get resource quota operation
OperatorAPIGetResourceQuotaHandler operator_api.GetResourceQuotaHandler
// OperatorAPIGetTenantEventsHandler sets the operation handler for the get tenant events operation
OperatorAPIGetTenantEventsHandler operator_api.GetTenantEventsHandler
// OperatorAPIGetTenantLogsHandler sets the operation handler for the get tenant logs operation
OperatorAPIGetTenantLogsHandler operator_api.GetTenantLogsHandler
// OperatorAPIGetTenantMonitoringHandler sets the operation handler for the get tenant monitoring operation
@@ -479,6 +484,9 @@ func (o *OperatorAPI) Validate() error {
if o.OperatorAPIGetResourceQuotaHandler == nil {
unregistered = append(unregistered, "operator_api.GetResourceQuotaHandler")
}
if o.OperatorAPIGetTenantEventsHandler == nil {
unregistered = append(unregistered, "operator_api.GetTenantEventsHandler")
}
if o.OperatorAPIGetTenantLogsHandler == nil {
unregistered = append(unregistered, "operator_api.GetTenantLogsHandler")
}
@@ -738,6 +746,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}/events"] = operator_api.NewGetTenantEvents(o.context, o.OperatorAPIGetTenantEventsHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/namespaces/{namespace}/tenants/{tenant}/log"] = operator_api.NewGetTenantLogs(o.context, o.OperatorAPIGetTenantLogsHandler)
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"
)
// GetTenantEventsHandlerFunc turns a function with the right signature into a get tenant events handler
type GetTenantEventsHandlerFunc func(GetTenantEventsParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn GetTenantEventsHandlerFunc) Handle(params GetTenantEventsParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// GetTenantEventsHandler interface for that can handle valid get tenant events params
type GetTenantEventsHandler interface {
Handle(GetTenantEventsParams, *models.Principal) middleware.Responder
}
// NewGetTenantEvents creates a new http.Handler for the get tenant events operation
func NewGetTenantEvents(ctx *middleware.Context, handler GetTenantEventsHandler) *GetTenantEvents {
return &GetTenantEvents{Context: ctx, Handler: handler}
}
/* GetTenantEvents swagger:route GET /namespaces/{namespace}/tenants/{tenant}/events OperatorAPI getTenantEvents
Get Events for given Tenant
*/
type GetTenantEvents struct {
Context *middleware.Context
Handler GetTenantEventsHandler
}
func (o *GetTenantEvents) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewGetTenantEventsParams()
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,112 @@
// 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"
)
// NewGetTenantEventsParams creates a new GetTenantEventsParams object
//
// There are no default values defined in the spec.
func NewGetTenantEventsParams() GetTenantEventsParams {
return GetTenantEventsParams{}
}
// GetTenantEventsParams contains all the bound params for the get tenant events operation
// typically these are obtained from a http.Request
//
// swagger:parameters GetTenantEvents
type GetTenantEventsParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
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 NewGetTenantEventsParams() beforehand.
func (o *GetTenantEventsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
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
}
// bindNamespace binds and validates parameter Namespace from path.
func (o *GetTenantEventsParams) 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 *GetTenantEventsParams) 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"
)
// GetTenantEventsOKCode is the HTTP code returned for type GetTenantEventsOK
const GetTenantEventsOKCode int = 200
/*GetTenantEventsOK A successful response.
swagger:response getTenantEventsOK
*/
type GetTenantEventsOK struct {
/*
In: Body
*/
Payload models.EventListWrapper `json:"body,omitempty"`
}
// NewGetTenantEventsOK creates GetTenantEventsOK with default headers values
func NewGetTenantEventsOK() *GetTenantEventsOK {
return &GetTenantEventsOK{}
}
// WithPayload adds the payload to the get tenant events o k response
func (o *GetTenantEventsOK) WithPayload(payload models.EventListWrapper) *GetTenantEventsOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get tenant events o k response
func (o *GetTenantEventsOK) SetPayload(payload models.EventListWrapper) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetTenantEventsOK) 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
}
}
/*GetTenantEventsDefault Generic error response.
swagger:response getTenantEventsDefault
*/
type GetTenantEventsDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewGetTenantEventsDefault creates GetTenantEventsDefault with default headers values
func NewGetTenantEventsDefault(code int) *GetTenantEventsDefault {
if code <= 0 {
code = 500
}
return &GetTenantEventsDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the get tenant events default response
func (o *GetTenantEventsDefault) WithStatusCode(code int) *GetTenantEventsDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the get tenant events default response
func (o *GetTenantEventsDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the get tenant events default response
func (o *GetTenantEventsDefault) WithPayload(payload *models.Error) *GetTenantEventsDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get tenant events default response
func (o *GetTenantEventsDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetTenantEventsDefault) 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,124 @@
// 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"
)
// GetTenantEventsURL generates an URL for the get tenant events operation
type GetTenantEventsURL struct {
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 *GetTenantEventsURL) WithBasePath(bp string) *GetTenantEventsURL {
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 *GetTenantEventsURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *GetTenantEventsURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/namespaces/{namespace}/tenants/{tenant}/events"
namespace := o.Namespace
if namespace != "" {
_path = strings.Replace(_path, "{namespace}", namespace, -1)
} else {
return nil, errors.New("namespace is required on GetTenantEventsURL")
}
tenant := o.Tenant
if tenant != "" {
_path = strings.Replace(_path, "{tenant}", tenant, -1)
} else {
return nil, errors.New("tenant is required on GetTenantEventsURL")
}
_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 *GetTenantEventsURL) 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 *GetTenantEventsURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *GetTenantEventsURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on GetTenantEventsURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on GetTenantEventsURL")
}
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 *GetTenantEventsURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -297,6 +297,14 @@ func registerTenantHandlers(api *operations.OperatorAPI) {
}
return operator_api.NewPutTenantYAMLCreated()
})
// Get Tenant Events
api.OperatorAPIGetTenantEventsHandler = operator_api.GetTenantEventsHandlerFunc(func(params operator_api.GetTenantEventsParams, principal *models.Principal) middleware.Responder {
payload, err := getTenantEventsResponse(principal, params)
if err != nil {
return operator_api.NewGetTenantEventsDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewGetTenantEventsOK().WithPayload(payload)
})
}
// getDeleteTenantResponse gets the output of deleting a minio instance
@@ -2924,3 +2932,37 @@ func getUpdateTenantYAML(session *models.Principal, params operator_api.PutTenan
return nil
}
func getTenantEventsResponse(session *models.Principal, params operator_api.GetTenantEventsParams) (models.EventListWrapper, *models.Error) {
ctx := context.Background()
client, err := cluster.OperatorClient(session.STSSessionToken)
if err != nil {
return nil, prepareError(err)
}
clientset, err := cluster.K8sClient(session.STSSessionToken)
if err != nil {
return nil, prepareError(err)
}
tenant, err := client.MinioV2().Tenants(params.Namespace).Get(ctx, params.Tenant, 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", tenant.UID)})
if err != nil {
return nil, prepareError(err)
}
retval := models.EventListWrapper{}
for _, event := range events.Items {
retval = append(retval, &models.EventListElement{
Namespace: event.Namespace,
LastSeen: event.LastTimestamp.Unix(),
Message: event.Message,
EventType: event.Type,
Reason: event.Reason,
})
}
sort.SliceStable(retval, func(i int, j int) bool {
return retval[i].LastSeen < retval[j].LastSeen
})
return retval, nil
}

View File

@@ -657,6 +657,31 @@ paths:
tags:
- OperatorAPI
/namespaces/{namespace}/tenants/{tenant}/events:
get:
summary: Get Events for given Tenant
operationId: GetTenantEvents
parameters:
- name: namespace
in: path
required: true
type: string
- name: tenant
in: path
required: true
type: string
responses:
200:
description: A successful response.
schema:
$ref: "#/definitions/eventListWrapper"
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- OperatorAPI
/namespaces/{namespace}/tenants/{tenant}/pods/{podName}:
get:
summary: Get Logs for Pod