Configure tenant monitoring tab (#1295)

* Configure tenant monitoring tab rework on new branch

* Removed unneeded code

* Fixed empty value bug

* rebased to master

* Configure tenant monitoring tab rework on new branch

* Removed unneded imports, commented lines

* Removed endpoints.go

* Rebased to master and modified to work without endpoints.go

* Removed unused function
This commit is contained in:
jinapurapu
2022-01-03 16:43:41 -08:00
committed by GitHub
parent 0cfa6f774b
commit dd781dc6da
27 changed files with 3193 additions and 3 deletions

View File

@@ -704,6 +704,83 @@ func init() {
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/monitoring": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "Get Prometheus Monitoring config info For The Tenant",
"operationId": "GetTenantMonitoring",
"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/tenantMonitoringInfo"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
},
"put": {
"tags": [
"OperatorAPI"
],
"summary": "Set Prometheus monitoring fields for tenant",
"operationId": "SetTenantMonitoring",
"parameters": [
{
"type": "string",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"name": "tenant",
"in": "path",
"required": true
},
{
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/tenantMonitoringInfo"
}
}
],
"responses": {
"201": {
"description": "A successful response."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/pods": {
"get": {
"tags": [
@@ -1434,6 +1511,17 @@ func init() {
}
}
},
"annotation": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"awsConfiguration": {
"type": "object",
"required": [
@@ -1537,6 +1625,14 @@ func init() {
}
}
},
"configureTenantRequest": {
"type": "object",
"properties": {
"prometheusEnabled": {
"type": "boolean"
}
}
},
"createTenantRequest": {
"type": "object",
"required": [
@@ -2091,6 +2187,17 @@ func init() {
}
}
},
"label": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"license": {
"type": "object",
"properties": {
@@ -2294,6 +2401,17 @@ func init() {
}
}
},
"nodeSelector": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"nodeSelectorTerm": {
"description": "A null or empty node selector term matches no objects. The requirements of them are ANDed. The TopologySelectorTerm type implements a subset of the NodeSelectorTerm.",
"type": "object",
@@ -2965,6 +3083,53 @@ func init() {
}
}
},
"tenantMonitoringInfo": {
"type": "object",
"properties": {
"annotations": {
"type": "array",
"items": {
"$ref": "#/definitions/annotation"
}
},
"diskCapacityGB": {
"type": "string"
},
"image": {
"type": "string"
},
"initImage": {
"type": "string"
},
"labels": {
"type": "array",
"items": {
"$ref": "#/definitions/label"
}
},
"nodeSelector": {
"type": "array",
"items": {
"$ref": "#/definitions/nodeSelector"
}
},
"prometheusEnabled": {
"type": "boolean"
},
"serviceAccountName": {
"type": "string"
},
"sidecarImage": {
"type": "string"
},
"storageClassName": {
"type": "string"
},
"toggle": {
"type": "boolean"
}
}
},
"tenantPod": {
"type": "object",
"required": [
@@ -3910,6 +4075,83 @@ func init() {
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/monitoring": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "Get Prometheus Monitoring config info For The Tenant",
"operationId": "GetTenantMonitoring",
"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/tenantMonitoringInfo"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
},
"put": {
"tags": [
"OperatorAPI"
],
"summary": "Set Prometheus monitoring fields for tenant",
"operationId": "SetTenantMonitoring",
"parameters": [
{
"type": "string",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"name": "tenant",
"in": "path",
"required": true
},
{
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/tenantMonitoringInfo"
}
}
],
"responses": {
"201": {
"description": "A successful response."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/namespaces/{namespace}/tenants/{tenant}/pods": {
"get": {
"tags": [
@@ -5365,6 +5607,17 @@ func init() {
}
}
},
"annotation": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"awsConfiguration": {
"type": "object",
"required": [
@@ -5468,6 +5721,14 @@ func init() {
}
}
},
"configureTenantRequest": {
"type": "object",
"properties": {
"prometheusEnabled": {
"type": "boolean"
}
}
},
"createTenantRequest": {
"type": "object",
"required": [
@@ -6010,6 +6271,17 @@ func init() {
}
}
},
"label": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"license": {
"type": "object",
"properties": {
@@ -6213,6 +6485,17 @@ func init() {
}
}
},
"nodeSelector": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
},
"nodeSelectorTerm": {
"description": "A null or empty node selector term matches no objects. The requirements of them are ANDed. The TopologySelectorTerm type implements a subset of the NodeSelectorTerm.",
"type": "object",
@@ -6749,6 +7032,53 @@ func init() {
}
}
},
"tenantMonitoringInfo": {
"type": "object",
"properties": {
"annotations": {
"type": "array",
"items": {
"$ref": "#/definitions/annotation"
}
},
"diskCapacityGB": {
"type": "string"
},
"image": {
"type": "string"
},
"initImage": {
"type": "string"
},
"labels": {
"type": "array",
"items": {
"$ref": "#/definitions/label"
}
},
"nodeSelector": {
"type": "array",
"items": {
"$ref": "#/definitions/nodeSelector"
}
},
"prometheusEnabled": {
"type": "boolean"
},
"serviceAccountName": {
"type": "string"
},
"sidecarImage": {
"type": "string"
},
"storageClassName": {
"type": "string"
},
"toggle": {
"type": "boolean"
}
}
},
"tenantPod": {
"type": "object",
"required": [

View File

@@ -102,6 +102,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")
}),
OperatorAPIGetTenantMonitoringHandler: operator_api.GetTenantMonitoringHandlerFunc(func(params operator_api.GetTenantMonitoringParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.GetTenantMonitoring has not yet been implemented")
}),
OperatorAPIGetTenantPodsHandler: operator_api.GetTenantPodsHandlerFunc(func(params operator_api.GetTenantPodsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.GetTenantPods has not yet been implemented")
}),
@@ -144,6 +147,9 @@ func NewOperatorAPI(spec *loads.Document) *OperatorAPI {
UserAPISessionCheckHandler: user_api.SessionCheckHandlerFunc(func(params user_api.SessionCheckParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.SessionCheck has not yet been implemented")
}),
OperatorAPISetTenantMonitoringHandler: operator_api.SetTenantMonitoringHandlerFunc(func(params operator_api.SetTenantMonitoringParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.SetTenantMonitoring has not yet been implemented")
}),
OperatorAPISubscriptionActivateHandler: operator_api.SubscriptionActivateHandlerFunc(func(params operator_api.SubscriptionActivateParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.SubscriptionActivate has not yet been implemented")
}),
@@ -255,6 +261,8 @@ type OperatorAPI struct {
OperatorAPIGetPodLogsHandler operator_api.GetPodLogsHandler
// OperatorAPIGetResourceQuotaHandler sets the operation handler for the get resource quota operation
OperatorAPIGetResourceQuotaHandler operator_api.GetResourceQuotaHandler
// OperatorAPIGetTenantMonitoringHandler sets the operation handler for the get tenant monitoring operation
OperatorAPIGetTenantMonitoringHandler operator_api.GetTenantMonitoringHandler
// OperatorAPIGetTenantPodsHandler sets the operation handler for the get tenant pods operation
OperatorAPIGetTenantPodsHandler operator_api.GetTenantPodsHandler
// OperatorAPIGetTenantUsageHandler sets the operation handler for the get tenant usage operation
@@ -283,6 +291,8 @@ type OperatorAPI struct {
OperatorAPIPutTenantYAMLHandler operator_api.PutTenantYAMLHandler
// UserAPISessionCheckHandler sets the operation handler for the session check operation
UserAPISessionCheckHandler user_api.SessionCheckHandler
// OperatorAPISetTenantMonitoringHandler sets the operation handler for the set tenant monitoring operation
OperatorAPISetTenantMonitoringHandler operator_api.SetTenantMonitoringHandler
// OperatorAPISubscriptionActivateHandler sets the operation handler for the subscription activate operation
OperatorAPISubscriptionActivateHandler operator_api.SubscriptionActivateHandler
// OperatorAPISubscriptionInfoHandler sets the operation handler for the subscription info operation
@@ -427,6 +437,9 @@ func (o *OperatorAPI) Validate() error {
if o.OperatorAPIGetResourceQuotaHandler == nil {
unregistered = append(unregistered, "operator_api.GetResourceQuotaHandler")
}
if o.OperatorAPIGetTenantMonitoringHandler == nil {
unregistered = append(unregistered, "operator_api.GetTenantMonitoringHandler")
}
if o.OperatorAPIGetTenantPodsHandler == nil {
unregistered = append(unregistered, "operator_api.GetTenantPodsHandler")
}
@@ -469,6 +482,9 @@ func (o *OperatorAPI) Validate() error {
if o.UserAPISessionCheckHandler == nil {
unregistered = append(unregistered, "user_api.SessionCheckHandler")
}
if o.OperatorAPISetTenantMonitoringHandler == nil {
unregistered = append(unregistered, "operator_api.SetTenantMonitoringHandler")
}
if o.OperatorAPISubscriptionActivateHandler == nil {
unregistered = append(unregistered, "operator_api.SubscriptionActivateHandler")
}
@@ -658,6 +674,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}/monitoring"] = operator_api.NewGetTenantMonitoring(o.context, o.OperatorAPIGetTenantMonitoringHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/namespaces/{namespace}/tenants/{tenant}/pods"] = operator_api.NewGetTenantPods(o.context, o.OperatorAPIGetTenantPodsHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
@@ -711,6 +731,10 @@ func (o *OperatorAPI) initHandlerCache() {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/session"] = user_api.NewSessionCheck(o.context, o.UserAPISessionCheckHandler)
if o.handlers["PUT"] == nil {
o.handlers["PUT"] = make(map[string]http.Handler)
}
o.handlers["PUT"]["/namespaces/{namespace}/tenants/{tenant}/monitoring"] = operator_api.NewSetTenantMonitoring(o.context, o.OperatorAPISetTenantMonitoringHandler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = 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"
)
// GetTenantMonitoringHandlerFunc turns a function with the right signature into a get tenant monitoring handler
type GetTenantMonitoringHandlerFunc func(GetTenantMonitoringParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn GetTenantMonitoringHandlerFunc) Handle(params GetTenantMonitoringParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// GetTenantMonitoringHandler interface for that can handle valid get tenant monitoring params
type GetTenantMonitoringHandler interface {
Handle(GetTenantMonitoringParams, *models.Principal) middleware.Responder
}
// NewGetTenantMonitoring creates a new http.Handler for the get tenant monitoring operation
func NewGetTenantMonitoring(ctx *middleware.Context, handler GetTenantMonitoringHandler) *GetTenantMonitoring {
return &GetTenantMonitoring{Context: ctx, Handler: handler}
}
/* GetTenantMonitoring swagger:route GET /namespaces/{namespace}/tenants/{tenant}/monitoring OperatorAPI getTenantMonitoring
Get Prometheus Monitoring config info For The Tenant
*/
type GetTenantMonitoring struct {
Context *middleware.Context
Handler GetTenantMonitoringHandler
}
func (o *GetTenantMonitoring) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewGetTenantMonitoringParams()
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"
)
// NewGetTenantMonitoringParams creates a new GetTenantMonitoringParams object
//
// There are no default values defined in the spec.
func NewGetTenantMonitoringParams() GetTenantMonitoringParams {
return GetTenantMonitoringParams{}
}
// GetTenantMonitoringParams contains all the bound params for the get tenant monitoring operation
// typically these are obtained from a http.Request
//
// swagger:parameters GetTenantMonitoring
type GetTenantMonitoringParams 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 NewGetTenantMonitoringParams() beforehand.
func (o *GetTenantMonitoringParams) 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 *GetTenantMonitoringParams) 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 *GetTenantMonitoringParams) 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,133 @@
// 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"
)
// GetTenantMonitoringOKCode is the HTTP code returned for type GetTenantMonitoringOK
const GetTenantMonitoringOKCode int = 200
/*GetTenantMonitoringOK A successful response.
swagger:response getTenantMonitoringOK
*/
type GetTenantMonitoringOK struct {
/*
In: Body
*/
Payload *models.TenantMonitoringInfo `json:"body,omitempty"`
}
// NewGetTenantMonitoringOK creates GetTenantMonitoringOK with default headers values
func NewGetTenantMonitoringOK() *GetTenantMonitoringOK {
return &GetTenantMonitoringOK{}
}
// WithPayload adds the payload to the get tenant monitoring o k response
func (o *GetTenantMonitoringOK) WithPayload(payload *models.TenantMonitoringInfo) *GetTenantMonitoringOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get tenant monitoring o k response
func (o *GetTenantMonitoringOK) SetPayload(payload *models.TenantMonitoringInfo) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetTenantMonitoringOK) 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
}
}
}
/*GetTenantMonitoringDefault Generic error response.
swagger:response getTenantMonitoringDefault
*/
type GetTenantMonitoringDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewGetTenantMonitoringDefault creates GetTenantMonitoringDefault with default headers values
func NewGetTenantMonitoringDefault(code int) *GetTenantMonitoringDefault {
if code <= 0 {
code = 500
}
return &GetTenantMonitoringDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the get tenant monitoring default response
func (o *GetTenantMonitoringDefault) WithStatusCode(code int) *GetTenantMonitoringDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the get tenant monitoring default response
func (o *GetTenantMonitoringDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the get tenant monitoring default response
func (o *GetTenantMonitoringDefault) WithPayload(payload *models.Error) *GetTenantMonitoringDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get tenant monitoring default response
func (o *GetTenantMonitoringDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetTenantMonitoringDefault) 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"
)
// GetTenantMonitoringURL generates an URL for the get tenant monitoring operation
type GetTenantMonitoringURL 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 *GetTenantMonitoringURL) WithBasePath(bp string) *GetTenantMonitoringURL {
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 *GetTenantMonitoringURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *GetTenantMonitoringURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/namespaces/{namespace}/tenants/{tenant}/monitoring"
namespace := o.Namespace
if namespace != "" {
_path = strings.Replace(_path, "{namespace}", namespace, -1)
} else {
return nil, errors.New("namespace is required on GetTenantMonitoringURL")
}
tenant := o.Tenant
if tenant != "" {
_path = strings.Replace(_path, "{tenant}", tenant, -1)
} else {
return nil, errors.New("tenant is required on GetTenantMonitoringURL")
}
_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 *GetTenantMonitoringURL) 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 *GetTenantMonitoringURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *GetTenantMonitoringURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on GetTenantMonitoringURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on GetTenantMonitoringURL")
}
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 *GetTenantMonitoringURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

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"
)
// SetTenantMonitoringHandlerFunc turns a function with the right signature into a set tenant monitoring handler
type SetTenantMonitoringHandlerFunc func(SetTenantMonitoringParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn SetTenantMonitoringHandlerFunc) Handle(params SetTenantMonitoringParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// SetTenantMonitoringHandler interface for that can handle valid set tenant monitoring params
type SetTenantMonitoringHandler interface {
Handle(SetTenantMonitoringParams, *models.Principal) middleware.Responder
}
// NewSetTenantMonitoring creates a new http.Handler for the set tenant monitoring operation
func NewSetTenantMonitoring(ctx *middleware.Context, handler SetTenantMonitoringHandler) *SetTenantMonitoring {
return &SetTenantMonitoring{Context: ctx, Handler: handler}
}
/* SetTenantMonitoring swagger:route PUT /namespaces/{namespace}/tenants/{tenant}/monitoring OperatorAPI setTenantMonitoring
Set Prometheus monitoring fields for tenant
*/
type SetTenantMonitoring struct {
Context *middleware.Context
Handler SetTenantMonitoringHandler
}
func (o *SetTenantMonitoring) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewSetTenantMonitoringParams()
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,151 @@
// 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 (
"context"
"io"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"
"github.com/minio/console/models"
)
// NewSetTenantMonitoringParams creates a new SetTenantMonitoringParams object
//
// There are no default values defined in the spec.
func NewSetTenantMonitoringParams() SetTenantMonitoringParams {
return SetTenantMonitoringParams{}
}
// SetTenantMonitoringParams contains all the bound params for the set tenant monitoring operation
// typically these are obtained from a http.Request
//
// swagger:parameters SetTenantMonitoring
type SetTenantMonitoringParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: body
*/
Data *models.TenantMonitoringInfo
/*
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 NewSetTenantMonitoringParams() beforehand.
func (o *SetTenantMonitoringParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if runtime.HasBody(r) {
defer r.Body.Close()
var body models.TenantMonitoringInfo
if err := route.Consumer.Consume(r.Body, &body); err != nil {
if err == io.EOF {
res = append(res, errors.Required("data", "body", ""))
} else {
res = append(res, errors.NewParseError("data", "body", "", err))
}
} else {
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
ctx := validate.WithOperationRequest(context.Background())
if err := body.ContextValidate(ctx, route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Data = &body
}
}
} else {
res = append(res, errors.Required("data", "body", ""))
}
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 *SetTenantMonitoringParams) 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 *SetTenantMonitoringParams) 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,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 <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"
)
// SetTenantMonitoringCreatedCode is the HTTP code returned for type SetTenantMonitoringCreated
const SetTenantMonitoringCreatedCode int = 201
/*SetTenantMonitoringCreated A successful response.
swagger:response setTenantMonitoringCreated
*/
type SetTenantMonitoringCreated struct {
}
// NewSetTenantMonitoringCreated creates SetTenantMonitoringCreated with default headers values
func NewSetTenantMonitoringCreated() *SetTenantMonitoringCreated {
return &SetTenantMonitoringCreated{}
}
// WriteResponse to the client
func (o *SetTenantMonitoringCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(201)
}
/*SetTenantMonitoringDefault Generic error response.
swagger:response setTenantMonitoringDefault
*/
type SetTenantMonitoringDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewSetTenantMonitoringDefault creates SetTenantMonitoringDefault with default headers values
func NewSetTenantMonitoringDefault(code int) *SetTenantMonitoringDefault {
if code <= 0 {
code = 500
}
return &SetTenantMonitoringDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the set tenant monitoring default response
func (o *SetTenantMonitoringDefault) WithStatusCode(code int) *SetTenantMonitoringDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the set tenant monitoring default response
func (o *SetTenantMonitoringDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the set tenant monitoring default response
func (o *SetTenantMonitoringDefault) WithPayload(payload *models.Error) *SetTenantMonitoringDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the set tenant monitoring default response
func (o *SetTenantMonitoringDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *SetTenantMonitoringDefault) 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"
)
// SetTenantMonitoringURL generates an URL for the set tenant monitoring operation
type SetTenantMonitoringURL 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 *SetTenantMonitoringURL) WithBasePath(bp string) *SetTenantMonitoringURL {
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 *SetTenantMonitoringURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *SetTenantMonitoringURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/namespaces/{namespace}/tenants/{tenant}/monitoring"
namespace := o.Namespace
if namespace != "" {
_path = strings.Replace(_path, "{namespace}", namespace, -1)
} else {
return nil, errors.New("namespace is required on SetTenantMonitoringURL")
}
tenant := o.Tenant
if tenant != "" {
_path = strings.Replace(_path, "{tenant}", tenant, -1)
} else {
return nil, errors.New("tenant is required on SetTenantMonitoringURL")
}
_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 *SetTenantMonitoringURL) 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 *SetTenantMonitoringURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *SetTenantMonitoringURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on SetTenantMonitoringURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on SetTenantMonitoringURL")
}
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 *SetTenantMonitoringURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -201,6 +201,23 @@ func registerTenantHandlers(api *operations.OperatorAPI) {
return operator_api.NewGetPodEventsOK().WithPayload(payload)
})
//Get tenant monitoring info
api.OperatorAPIGetTenantMonitoringHandler = operator_api.GetTenantMonitoringHandlerFunc(func(params operator_api.GetTenantMonitoringParams, session *models.Principal) middleware.Responder {
payload, err := getTenantMonitoringResponse(session, params)
if err != nil {
return operator_api.NewGetTenantMonitoringDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewGetTenantMonitoringOK().WithPayload(payload)
})
//Set configuration fields for Prometheus monitoring on a tenant
api.OperatorAPISetTenantMonitoringHandler = operator_api.SetTenantMonitoringHandlerFunc(func(params operator_api.SetTenantMonitoringParams, session *models.Principal) middleware.Responder {
_, err := setTenantMonitoringResponse(session, params)
if err != nil {
return operator_api.NewSetTenantMonitoringDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewSetTenantMonitoringCreated()
})
// Update Tenant Pools
api.OperatorAPITenantUpdatePoolsHandler = operator_api.TenantUpdatePoolsHandlerFunc(func(params operator_api.TenantUpdatePoolsParams, session *models.Principal) middleware.Responder {
resp, err := getTenantUpdatePoolResponse(session, params)
@@ -1773,6 +1790,152 @@ func getPodEventsResponse(session *models.Principal, params operator_api.GetPodE
return retval, nil
}
//get values for prometheus metrics
func getTenantMonitoringResponse(session *models.Principal, params operator_api.GetTenantMonitoringParams) (*models.TenantMonitoringInfo, *models.Error) {
ctx := context.Background()
opClientClientSet, err := cluster.OperatorClient(session.STSSessionToken)
if err != nil {
return nil, prepareError(err)
}
opClient := &operatorClient{
client: opClientClientSet,
}
minInst, err := opClient.TenantGet(ctx, params.Namespace, params.Tenant, metav1.GetOptions{})
if err != nil {
return nil, prepareError(err)
}
var storageClassName string
monitoringInfo := &models.TenantMonitoringInfo{}
if minInst.Spec.Prometheus == nil {
monitoringInfo := &models.TenantMonitoringInfo{
PrometheusEnabled: (false),
}
return monitoringInfo, nil
}
if minInst.Spec.Prometheus.StorageClassName != nil {
storageClassName = *minInst.Spec.Prometheus.StorageClassName
}
mLabels := []*models.Label{}
for k, v := range minInst.Spec.Prometheus.Labels {
mLabels = append(mLabels, &models.Label{Key: k, Value: v})
}
mAnnotations := []*models.Annotation{}
for k, v := range minInst.Spec.Prometheus.Annotations {
mAnnotations = append(mAnnotations, &models.Annotation{Key: k, Value: v})
}
mNodeSelector := []*models.NodeSelector{}
for k, v := range minInst.Spec.Prometheus.NodeSelector {
mNodeSelector = append(mNodeSelector, &models.NodeSelector{Key: k, Value: v})
}
if minInst.Spec.Prometheus != nil {
monitoringInfo = &models.TenantMonitoringInfo{
PrometheusEnabled: (true),
Annotations: mAnnotations,
DiskCapacityGB: strconv.Itoa(*minInst.Spec.Prometheus.DiskCapacityDB),
Image: minInst.Spec.Prometheus.Image,
InitImage: minInst.Spec.Prometheus.InitImage,
Labels: mLabels,
NodeSelector: mNodeSelector,
ServiceAccountName: minInst.Spec.Prometheus.ServiceAccountName,
SidecarImage: minInst.Spec.Prometheus.SideCarImage,
StorageClassName: storageClassName,
}
return monitoringInfo, nil
}
return monitoringInfo, nil
}
//sets tenant Prometheus monitoring cofiguration fields to values provided
func setTenantMonitoringResponse(session *models.Principal, params operator_api.SetTenantMonitoringParams) (bool, *models.Error) {
// 30 seconds timeout
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
opClientClientSet, err := cluster.OperatorClient(session.STSSessionToken)
if err != nil {
return false, prepareError(err, errorUnableToGetTenantUsage)
}
opClient := &operatorClient{
client: opClientClientSet,
}
minTenant, err := getTenant(ctx, opClient, params.Namespace, params.Tenant)
if err != nil {
return false, prepareError(err, errorUnableToGetTenantUsage)
}
if params.Data.Toggle {
if params.Data.PrometheusEnabled {
minTenant.Spec.Prometheus = nil
} else {
promDiskSpaceGB := 5
promImage := ""
minTenant.Spec.Prometheus = &miniov2.PrometheusConfig{
DiskCapacityDB: swag.Int(promDiskSpaceGB),
Image: promImage,
}
}
_, err = opClient.TenantUpdate(ctx, minTenant, metav1.UpdateOptions{})
if err != nil {
return false, prepareError(err)
}
return true, nil
}
var labels = make(map[string]string)
for i := 0; i < len(params.Data.Labels); i++ {
if params.Data.Labels[i] != nil {
labels[params.Data.Labels[i].Key] = params.Data.Labels[i].Value
}
}
var annotations = make(map[string]string)
for i := 0; i < len(params.Data.Annotations); i++ {
if params.Data.Annotations[i] != nil {
annotations[params.Data.Annotations[i].Key] = params.Data.Annotations[i].Value
}
}
var nodeSelector = make(map[string]string)
for i := 0; i < len(params.Data.NodeSelector); i++ {
if params.Data.NodeSelector[i] != nil {
nodeSelector[params.Data.NodeSelector[i].Key] = params.Data.NodeSelector[i].Value
}
}
var storageClassName string
if &params.Data.StorageClassName != nil {
storageClassName = params.Data.StorageClassName
}
minTenant.Spec.Prometheus.Labels = labels
minTenant.Spec.Prometheus.Annotations = annotations
minTenant.Spec.Prometheus.NodeSelector = nodeSelector
minTenant.Spec.Prometheus.Image = params.Data.Image
minTenant.Spec.Prometheus.SideCarImage = params.Data.SidecarImage
minTenant.Spec.Prometheus.InitImage = params.Data.InitImage
minTenant.Spec.Prometheus.StorageClassName = &storageClassName
diskCapacityGB, err := strconv.Atoi(params.Data.DiskCapacityGB)
if err == nil {
*minTenant.Spec.Prometheus.DiskCapacityDB = diskCapacityGB
}
minTenant.Spec.Prometheus.ServiceAccountName = params.Data.ServiceAccountName
_, err = opClient.TenantUpdate(ctx, minTenant, metav1.UpdateOptions{})
if err != nil {
return false, prepareError(err)
}
return true, nil
}
// parseTenantPoolRequest parse pool request and returns the equivalent
// miniov2.Pool object
func parseTenantPoolRequest(poolParams *models.Pool) (*miniov2.Pool, error) {