From 4541b4de03b73fd15411a13b248e9107aefc810e Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Thu, 14 Apr 2022 00:42:38 -0600 Subject: [PATCH] Added domains item in create tenant & get tenant requests (#1841) --- models/create_tenant_request.go | 46 ++++++++++++++++++++++ models/domains_configuration.go | 70 +++++++++++++++++++++++++++++++++ models/tenant.go | 46 ++++++++++++++++++++++ models/tenant_list.go | 46 ++++++++++++++++++++++ operatorapi/embedded_spec.go | 50 +++++++++++++++++++++++ operatorapi/tenant_add.go | 19 +++++++++ operatorapi/tenant_get.go | 11 ++++++ operatorapi/tenants.go | 10 +++++ swagger-operator.yml | 17 ++++++++ 9 files changed, 315 insertions(+) create mode 100644 models/domains_configuration.go diff --git a/models/create_tenant_request.go b/models/create_tenant_request.go index bf947fedf..98d1253da 100644 --- a/models/create_tenant_request.go +++ b/models/create_tenant_request.go @@ -43,6 +43,9 @@ type CreateTenantRequest struct { // annotations Annotations map[string]string `json:"annotations,omitempty"` + // domains + Domains *DomainsConfiguration `json:"domains,omitempty"` + // enable console EnableConsole *bool `json:"enable_console,omitempty"` @@ -112,6 +115,10 @@ type CreateTenantRequest struct { func (m *CreateTenantRequest) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateDomains(formats); err != nil { + res = append(res, err) + } + if err := m.validateEncryption(formats); err != nil { res = append(res, err) } @@ -154,6 +161,25 @@ func (m *CreateTenantRequest) Validate(formats strfmt.Registry) error { return nil } +func (m *CreateTenantRequest) validateDomains(formats strfmt.Registry) error { + if swag.IsZero(m.Domains) { // not required + return nil + } + + if m.Domains != nil { + if err := m.Domains.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("domains") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("domains") + } + return err + } + } + + return nil +} + func (m *CreateTenantRequest) validateEncryption(formats strfmt.Registry) error { if swag.IsZero(m.Encryption) { // not required return nil @@ -321,6 +347,10 @@ func (m *CreateTenantRequest) validateTLS(formats strfmt.Registry) error { func (m *CreateTenantRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error + if err := m.contextValidateDomains(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateEncryption(ctx, formats); err != nil { res = append(res, err) } @@ -355,6 +385,22 @@ func (m *CreateTenantRequest) ContextValidate(ctx context.Context, formats strfm return nil } +func (m *CreateTenantRequest) contextValidateDomains(ctx context.Context, formats strfmt.Registry) error { + + if m.Domains != nil { + if err := m.Domains.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("domains") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("domains") + } + return err + } + } + + return nil +} + func (m *CreateTenantRequest) contextValidateEncryption(ctx context.Context, formats strfmt.Registry) error { if m.Encryption != nil { diff --git a/models/domains_configuration.go b/models/domains_configuration.go new file mode 100644 index 000000000..b9e1f84d0 --- /dev/null +++ b/models/domains_configuration.go @@ -0,0 +1,70 @@ +// 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" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// DomainsConfiguration domains configuration +// +// swagger:model domainsConfiguration +type DomainsConfiguration struct { + + // console + Console string `json:"console,omitempty"` + + // minio + Minio []string `json:"minio"` +} + +// Validate validates this domains configuration +func (m *DomainsConfiguration) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this domains configuration based on context it is used +func (m *DomainsConfiguration) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *DomainsConfiguration) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *DomainsConfiguration) UnmarshalBinary(b []byte) error { + var res DomainsConfiguration + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/tenant.go b/models/tenant.go index b6fcae381..c6ef70dd2 100644 --- a/models/tenant.go +++ b/models/tenant.go @@ -45,6 +45,9 @@ type Tenant struct { // deletion date DeletionDate string `json:"deletion_date,omitempty"` + // domains + Domains *DomainsConfiguration `json:"domains,omitempty"` + // enable prometheus EnablePrometheus bool `json:"enable_prometheus,omitempty"` @@ -95,6 +98,10 @@ type Tenant struct { func (m *Tenant) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateDomains(formats); err != nil { + res = append(res, err) + } + if err := m.validateEndpoints(formats); err != nil { res = append(res, err) } @@ -117,6 +124,25 @@ func (m *Tenant) Validate(formats strfmt.Registry) error { return nil } +func (m *Tenant) validateDomains(formats strfmt.Registry) error { + if swag.IsZero(m.Domains) { // not required + return nil + } + + if m.Domains != nil { + if err := m.Domains.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("domains") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("domains") + } + return err + } + } + + return nil +} + func (m *Tenant) validateEndpoints(formats strfmt.Registry) error { if swag.IsZero(m.Endpoints) { // not required return nil @@ -204,6 +230,10 @@ func (m *Tenant) validateSubnetLicense(formats strfmt.Registry) error { func (m *Tenant) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error + if err := m.contextValidateDomains(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateEndpoints(ctx, formats); err != nil { res = append(res, err) } @@ -226,6 +256,22 @@ func (m *Tenant) ContextValidate(ctx context.Context, formats strfmt.Registry) e return nil } +func (m *Tenant) contextValidateDomains(ctx context.Context, formats strfmt.Registry) error { + + if m.Domains != nil { + if err := m.Domains.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("domains") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("domains") + } + return err + } + } + + return nil +} + func (m *Tenant) contextValidateEndpoints(ctx context.Context, formats strfmt.Registry) error { if m.Endpoints != nil { diff --git a/models/tenant_list.go b/models/tenant_list.go index 4caacb08a..7bc41096c 100644 --- a/models/tenant_list.go +++ b/models/tenant_list.go @@ -57,6 +57,9 @@ type TenantList struct { // deletion date DeletionDate string `json:"deletion_date,omitempty"` + // domains + Domains *DomainsConfiguration `json:"domains,omitempty"` + // health status HealthStatus string `json:"health_status,omitempty"` @@ -86,6 +89,10 @@ type TenantList struct { func (m *TenantList) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateDomains(formats); err != nil { + res = append(res, err) + } + if err := m.validateTiers(formats); err != nil { res = append(res, err) } @@ -96,6 +103,25 @@ func (m *TenantList) Validate(formats strfmt.Registry) error { return nil } +func (m *TenantList) validateDomains(formats strfmt.Registry) error { + if swag.IsZero(m.Domains) { // not required + return nil + } + + if m.Domains != nil { + if err := m.Domains.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("domains") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("domains") + } + return err + } + } + + return nil +} + func (m *TenantList) validateTiers(formats strfmt.Registry) error { if swag.IsZero(m.Tiers) { // not required return nil @@ -126,6 +152,10 @@ func (m *TenantList) validateTiers(formats strfmt.Registry) error { func (m *TenantList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error + if err := m.contextValidateDomains(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateTiers(ctx, formats); err != nil { res = append(res, err) } @@ -136,6 +166,22 @@ func (m *TenantList) ContextValidate(ctx context.Context, formats strfmt.Registr return nil } +func (m *TenantList) contextValidateDomains(ctx context.Context, formats strfmt.Registry) error { + + if m.Domains != nil { + if err := m.Domains.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("domains") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("domains") + } + return err + } + } + + return nil +} + func (m *TenantList) contextValidateTiers(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.Tiers); i++ { diff --git a/operatorapi/embedded_spec.go b/operatorapi/embedded_spec.go index 0093b6af6..9d7e85bbe 100644 --- a/operatorapi/embedded_spec.go +++ b/operatorapi/embedded_spec.go @@ -2000,6 +2000,10 @@ func init() { "type": "string" } }, + "domains": { + "type": "object", + "$ref": "#/definitions/domainsConfiguration" + }, "enable_console": { "type": "boolean", "default": true @@ -2158,6 +2162,20 @@ func init() { } } }, + "domainsConfiguration": { + "type": "object", + "properties": { + "console": { + "type": "string" + }, + "minio": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "encryptionConfiguration": { "allOf": [ { @@ -3430,6 +3448,9 @@ func init() { "deletion_date": { "type": "string" }, + "domains": { + "$ref": "#/definitions/domainsConfiguration" + }, "enable_prometheus": { "type": "boolean" }, @@ -3517,6 +3538,10 @@ func init() { "deletion_date": { "type": "string" }, + "domains": { + "type": "object", + "$ref": "#/definitions/domainsConfiguration" + }, "health_status": { "type": "string" }, @@ -6837,6 +6862,10 @@ func init() { "type": "string" } }, + "domains": { + "type": "object", + "$ref": "#/definitions/domainsConfiguration" + }, "enable_console": { "type": "boolean", "default": true @@ -6995,6 +7024,20 @@ func init() { } } }, + "domainsConfiguration": { + "type": "object", + "properties": { + "console": { + "type": "string" + }, + "minio": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "encryptionConfiguration": { "allOf": [ { @@ -8120,6 +8163,9 @@ func init() { "deletion_date": { "type": "string" }, + "domains": { + "$ref": "#/definitions/domainsConfiguration" + }, "enable_prometheus": { "type": "boolean" }, @@ -8207,6 +8253,10 @@ func init() { "deletion_date": { "type": "string" }, + "domains": { + "type": "object", + "$ref": "#/definitions/domainsConfiguration" + }, "health_status": { "type": "string" }, diff --git a/operatorapi/tenant_add.go b/operatorapi/tenant_add.go index cda1533d6..5ba5dbdd3 100644 --- a/operatorapi/tenant_add.go +++ b/operatorapi/tenant_add.go @@ -430,6 +430,7 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre if (diskSpaceFromAPI / humanize.GiByte) < int64(auditMaxCap) { auditMaxCap = int(diskSpaceFromAPI / humanize.GiByte) } + // default activate lgo search and prometheus minInst.Spec.Log = &miniov2.LogConfig{ Audit: &miniov2.AuditConfig{DiskCapacityGB: swag.Int(auditMaxCap)}, @@ -541,6 +542,24 @@ func getTenantCreatedResponse(session *models.Principal, params operator_api.Cre } minInst.Spec.Configuration = &corev1.LocalObjectReference{Name: tenantConfigurationName} + if tenantReq.Domains != nil { + var features miniov2.Features + var domains miniov2.TenantDomains + + // tenant domains + if tenantReq.Domains.Console != "" { + domains.Console = tenantReq.Domains.Console + } + + if tenantReq.Domains.Minio != nil { + domains.Minio = tenantReq.Domains.Minio + } + + features.Domains = &domains + + minInst.Spec.Features = &features + } + opClient, err := cluster.OperatorClient(session.STSSessionToken) if err != nil { return nil, prepareError(err) diff --git a/operatorapi/tenant_get.go b/operatorapi/tenant_get.go index 7c7074101..e12857d3b 100644 --- a/operatorapi/tenant_get.go +++ b/operatorapi/tenant_get.go @@ -150,5 +150,16 @@ func getTenantDetailsResponse(session *models.Principal, params operator_api.Ten } } + var domains models.DomainsConfiguration + + if minTenant.Spec.Features != nil && minTenant.Spec.Features.Domains != nil { + domains = models.DomainsConfiguration{ + Console: minTenant.Spec.Features.Domains.Console, + Minio: minTenant.Spec.Features.Domains.Minio, + } + } + + info.Domains = &domains + return info, nil } diff --git a/operatorapi/tenants.go b/operatorapi/tenants.go index da3cee77a..70e76e96e 100644 --- a/operatorapi/tenants.go +++ b/operatorapi/tenants.go @@ -1073,6 +1073,15 @@ func listTenants(ctx context.Context, operatorClient OperatorClientI, namespace tiers = append(tiers, tierItem) } + var domains models.DomainsConfiguration + + if tenant.Spec.Features != nil && tenant.Spec.Features.Domains != nil { + domains = models.DomainsConfiguration{ + Console: tenant.Spec.Features.Domains.Console, + Minio: tenant.Spec.Features.Domains.Minio, + } + } + tenants = append(tenants, &models.TenantList{ CreationDate: tenant.ObjectMeta.CreationTimestamp.Format(time.RFC3339), DeletionDate: deletion, @@ -1089,6 +1098,7 @@ func listTenants(ctx context.Context, operatorClient OperatorClientI, namespace Capacity: tenant.Status.Usage.Capacity, CapacityUsage: tenant.Status.Usage.Usage, Tiers: tiers, + Domains: &domains, }) } diff --git a/swagger-operator.yml b/swagger-operator.yml index 2ba4f263a..fa13c0005 100644 --- a/swagger-operator.yml +++ b/swagger-operator.yml @@ -1426,6 +1426,8 @@ definitions: $ref: "#/definitions/tenantStatus" minioTLS: type: boolean + domains: + $ref: "#/definitions/domainsConfiguration" tenantUsage: type: object @@ -1476,6 +1478,9 @@ definitions: type: array items: $ref: "#/definitions/tenantTierElement" + domains: + type: object + $ref: "#/definitions/domainsConfiguration" listTenantsResponse: type: object @@ -1581,6 +1586,9 @@ definitions: type: boolean expose_console: type: boolean + domains: + type: object + $ref: "#/definitions/domainsConfiguration" metadataFields: type: object @@ -2925,3 +2933,12 @@ definitions: size: type: integer format: int64 + domainsConfiguration: + type: object + properties: + minio: + type: array + items: + type: string + console: + type: string