2020-07-01 18:03:22 -07:00
|
|
|
// This file is part of MinIO Kubernetes Cloud
|
|
|
|
|
// Copyright (c) 2020 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 restapi
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
"encoding/base64"
|
2020-07-01 18:03:22 -07:00
|
|
|
"encoding/json"
|
2020-07-27 14:06:12 -07:00
|
|
|
"errors"
|
2020-07-01 18:03:22 -07:00
|
|
|
"fmt"
|
|
|
|
|
"log"
|
2020-07-09 12:24:01 -07:00
|
|
|
"net"
|
2020-07-01 18:03:22 -07:00
|
|
|
"net/http"
|
|
|
|
|
"os"
|
2020-07-09 12:24:01 -07:00
|
|
|
"strconv"
|
2020-07-01 18:03:22 -07:00
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2020-07-01 18:03:22 -07:00
|
|
|
|
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
|
|
2020-07-26 00:34:17 -07:00
|
|
|
"github.com/minio/console/cluster"
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2020-07-01 18:03:22 -07:00
|
|
|
|
|
|
|
|
"github.com/go-openapi/runtime/middleware"
|
|
|
|
|
"github.com/go-openapi/swag"
|
2020-07-26 00:34:17 -07:00
|
|
|
"github.com/minio/console/models"
|
|
|
|
|
"github.com/minio/console/restapi/operations"
|
|
|
|
|
"github.com/minio/console/restapi/operations/admin_api"
|
2020-07-25 14:38:16 -07:00
|
|
|
operator "github.com/minio/operator/pkg/apis/minio.min.io/v1"
|
2020-08-04 20:54:59 -07:00
|
|
|
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
|
2020-07-01 18:03:22 -07:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2020-08-04 20:54:59 -07:00
|
|
|
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
2020-07-01 18:03:22 -07:00
|
|
|
)
|
|
|
|
|
|
2020-08-04 20:54:59 -07:00
|
|
|
type imageRegistry struct {
|
|
|
|
|
Auths map[string]imageRegistryCredentials `json:"auths"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type imageRegistryCredentials struct {
|
|
|
|
|
Username string `json:"username"`
|
|
|
|
|
Password string `json:"password"`
|
|
|
|
|
Auth string `json:"auth"`
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-26 00:34:17 -07:00
|
|
|
func registerTenantHandlers(api *operations.ConsoleAPI) {
|
2020-07-01 18:03:22 -07:00
|
|
|
// Add Tenant
|
2020-07-10 19:14:28 -07:00
|
|
|
api.AdminAPICreateTenantHandler = admin_api.CreateTenantHandlerFunc(func(params admin_api.CreateTenantParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
resp, err := getTenantCreatedResponse(session, params)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewCreateTenantDefault(int(err.Code)).WithPayload(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewCreateTenantOK().WithPayload(resp)
|
|
|
|
|
})
|
|
|
|
|
// List All Tenants of all namespaces
|
2020-07-10 19:14:28 -07:00
|
|
|
api.AdminAPIListAllTenantsHandler = admin_api.ListAllTenantsHandlerFunc(func(params admin_api.ListAllTenantsParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
resp, err := getListAllTenantsResponse(session, params)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewListTenantsDefault(int(err.Code)).WithPayload(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewListTenantsOK().WithPayload(resp)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
// List Tenants by namespace
|
2020-07-10 19:14:28 -07:00
|
|
|
api.AdminAPIListTenantsHandler = admin_api.ListTenantsHandlerFunc(func(params admin_api.ListTenantsParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
resp, err := getListTenantsResponse(session, params)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewListTenantsDefault(int(err.Code)).WithPayload(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewListTenantsOK().WithPayload(resp)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
// Detail Tenant
|
2020-07-10 19:14:28 -07:00
|
|
|
api.AdminAPITenantInfoHandler = admin_api.TenantInfoHandlerFunc(func(params admin_api.TenantInfoParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
resp, err := getTenantInfoResponse(session, params)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewTenantInfoDefault(int(err.Code)).WithPayload(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewTenantInfoOK().WithPayload(resp)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Delete Tenant
|
2020-07-10 19:14:28 -07:00
|
|
|
api.AdminAPIDeleteTenantHandler = admin_api.DeleteTenantHandlerFunc(func(params admin_api.DeleteTenantParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
err := getDeleteTenantResponse(session, params)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewTenantInfoDefault(int(err.Code)).WithPayload(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewTenantInfoOK()
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Update Tenant
|
2020-07-10 19:14:28 -07:00
|
|
|
api.AdminAPIUpdateTenantHandler = admin_api.UpdateTenantHandlerFunc(func(params admin_api.UpdateTenantParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
err := getUpdateTenantResponse(session, params)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewUpdateTenantDefault(int(err.Code)).WithPayload(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewUpdateTenantCreated()
|
|
|
|
|
})
|
2020-07-13 20:36:27 -07:00
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
// Add Tenant Zones
|
2020-07-13 20:36:27 -07:00
|
|
|
api.AdminAPITenantAddZoneHandler = admin_api.TenantAddZoneHandlerFunc(func(params admin_api.TenantAddZoneParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
err := getTenantAddZoneResponse(session, params)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewTenantAddZoneDefault(int(err.Code)).WithPayload(err)
|
2020-07-13 20:36:27 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewTenantAddZoneCreated()
|
|
|
|
|
})
|
2020-07-27 14:19:40 -07:00
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
// Get Tenant Usage
|
2020-07-27 14:19:40 -07:00
|
|
|
api.AdminAPIGetTenantUsageHandler = admin_api.GetTenantUsageHandlerFunc(func(params admin_api.GetTenantUsageParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
payload, err := getTenantUsageResponse(session, params)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewGetTenantUsageDefault(int(err.Code)).WithPayload(err)
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewGetTenantUsageOK().WithPayload(payload)
|
|
|
|
|
})
|
2020-08-26 17:12:59 -07:00
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
// Update Tenant Zones
|
2020-08-26 17:12:59 -07:00
|
|
|
api.AdminAPITenantUpdateZonesHandler = admin_api.TenantUpdateZonesHandlerFunc(func(params admin_api.TenantUpdateZonesParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
resp, err := getTenantUpdateZoneResponse(session, params)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return admin_api.NewTenantUpdateZonesDefault(int(err.Code)).WithPayload(err)
|
2020-08-26 17:12:59 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewTenantUpdateZonesOK().WithPayload(resp)
|
|
|
|
|
})
|
2020-09-03 10:20:58 -07:00
|
|
|
|
|
|
|
|
// Update Tenant Certificates
|
|
|
|
|
api.AdminAPITenantUpdateCertificateHandler = admin_api.TenantUpdateCertificateHandlerFunc(func(params admin_api.TenantUpdateCertificateParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
err := getTenantUpdateCertificatesResponse(session, params)
|
|
|
|
|
if err != nil {
|
2020-09-08 12:20:38 -07:00
|
|
|
return admin_api.NewTenantUpdateCertificateDefault(int(err.Code)).WithPayload(err)
|
2020-09-03 10:20:58 -07:00
|
|
|
}
|
|
|
|
|
return admin_api.NewTenantUpdateCertificateCreated()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Update Tenant Encryption Configuration
|
|
|
|
|
api.AdminAPITenantUpdateEncryptionHandler = admin_api.TenantUpdateEncryptionHandlerFunc(func(params admin_api.TenantUpdateEncryptionParams, session *models.Principal) middleware.Responder {
|
|
|
|
|
err := getTenantUpdateEncryptionResponse(session, params)
|
|
|
|
|
if err != nil {
|
2020-09-08 12:20:38 -07:00
|
|
|
return admin_api.NewTenantUpdateEncryptionDefault(int(err.Code)).WithPayload(err)
|
2020-09-03 10:20:58 -07:00
|
|
|
}
|
2020-09-08 12:20:38 -07:00
|
|
|
return admin_api.NewTenantUpdateEncryptionCreated()
|
2020-09-03 10:20:58 -07:00
|
|
|
})
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// getDeleteTenantResponse gets the output of deleting a minio instance
|
2020-09-04 20:32:57 -07:00
|
|
|
func getDeleteTenantResponse(session *models.Principal, params admin_api.DeleteTenantParams) *models.Error {
|
2020-07-10 19:14:28 -07:00
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-19 20:34:43 -07:00
|
|
|
// get Kubernetes Client
|
|
|
|
|
clientset, err := cluster.K8sClient(session.SessionToken)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return prepareError(err)
|
2020-08-19 20:34:43 -07:00
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
2020-08-19 20:34:43 -07:00
|
|
|
deleteTenantPVCs := false
|
|
|
|
|
if params.Body != nil {
|
|
|
|
|
deleteTenantPVCs = params.Body.DeletePvcs
|
|
|
|
|
}
|
2020-09-04 20:32:57 -07:00
|
|
|
if err = deleteTenantAction(context.Background(), opClient, clientset.CoreV1(), params.Namespace, params.Tenant, deleteTenantPVCs); err != nil {
|
|
|
|
|
return prepareError(err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
2020-08-19 20:34:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deleteTenantAction performs the actions of deleting a tenant
|
|
|
|
|
//
|
|
|
|
|
// It also adds the option of deleting the tenant's underlying pvcs if deletePvcs set
|
|
|
|
|
func deleteTenantAction(
|
|
|
|
|
ctx context.Context,
|
2020-09-03 10:20:58 -07:00
|
|
|
operatorClient OperatorClientI,
|
2020-08-19 20:34:43 -07:00
|
|
|
clientset v1.CoreV1Interface,
|
|
|
|
|
namespace, tenantName string,
|
|
|
|
|
deletePvcs bool) error {
|
|
|
|
|
|
|
|
|
|
err := operatorClient.TenantDelete(ctx, namespace, tenantName, metav1.DeleteOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
// try to delete pvc even if the tenant doesn't exist anymore but only if deletePvcs is set to true,
|
|
|
|
|
// else, we return the error
|
|
|
|
|
if (deletePvcs && !k8sErrors.IsNotFound(err)) || !deletePvcs {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if deletePvcs {
|
|
|
|
|
opts := metav1.ListOptions{
|
|
|
|
|
LabelSelector: fmt.Sprintf("%s=%s", operator.TenantLabel, tenantName),
|
|
|
|
|
}
|
2020-08-20 18:57:34 -07:00
|
|
|
err = clientset.PersistentVolumeClaims(namespace).DeleteCollection(ctx, metav1.DeleteOptions{}, opts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
// delete all tenant's secrets only if deletePvcs = true
|
|
|
|
|
return clientset.Secrets(namespace).DeleteCollection(ctx, metav1.DeleteOptions{}, opts)
|
2020-08-19 20:34:43 -07:00
|
|
|
}
|
|
|
|
|
return nil
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-25 14:38:16 -07:00
|
|
|
func getTenantScheme(mi *operator.Tenant) string {
|
2020-07-09 12:24:01 -07:00
|
|
|
scheme := "http"
|
2020-07-23 11:13:05 -07:00
|
|
|
if mi.AutoCert() || mi.ExternalCert() {
|
2020-07-09 12:24:01 -07:00
|
|
|
scheme = "https"
|
|
|
|
|
}
|
|
|
|
|
return scheme
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
func getTenantAdminClient(ctx context.Context, client K8sClientI, namespace, tenantName, serviceName, scheme string, insecure bool) (*madmin.AdminClient, error) {
|
2020-07-09 12:24:01 -07:00
|
|
|
// get admin credentials from secret
|
|
|
|
|
creds, err := client.getSecret(ctx, namespace, fmt.Sprintf("%s-secret", tenantName), metav1.GetOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
accessKey, ok := creds.Data["accesskey"]
|
|
|
|
|
if !ok {
|
|
|
|
|
log.Println("tenant's secret doesn't contain accesskey")
|
|
|
|
|
return nil, errorGeneric
|
|
|
|
|
}
|
|
|
|
|
secretkey, ok := creds.Data["secretkey"]
|
|
|
|
|
if !ok {
|
|
|
|
|
log.Println("tenant's secret doesn't contain secretkey")
|
|
|
|
|
return nil, errorGeneric
|
|
|
|
|
}
|
2020-08-09 14:36:55 -07:00
|
|
|
mAdmin, pErr := NewAdminClientWithInsecure(scheme+"://"+net.JoinHostPort(serviceName, strconv.Itoa(operator.MinIOPort)), string(accessKey), string(secretkey), insecure)
|
2020-07-09 12:24:01 -07:00
|
|
|
if pErr != nil {
|
|
|
|
|
return nil, pErr.Cause
|
|
|
|
|
}
|
|
|
|
|
return mAdmin, nil
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
func getTenant(ctx context.Context, operatorClient OperatorClientI, namespace, tenantName string) (*operator.Tenant, error) {
|
2020-07-25 14:38:16 -07:00
|
|
|
minInst, err := operatorClient.TenantGet(ctx, namespace, tenantName, metav1.GetOptions{})
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2020-07-09 12:24:01 -07:00
|
|
|
return minInst, nil
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
|
2020-09-05 23:48:51 -07:00
|
|
|
func isPrometheusEnabled(annotations map[string]string) bool {
|
|
|
|
|
if annotations == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
// if one of the following prometheus annotations are not present
|
|
|
|
|
// we consider the tenant as not integrated with prometheus
|
|
|
|
|
if _, ok := annotations[prometheusPath]; !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if _, ok := annotations[prometheusPort]; !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if _, ok := annotations[prometheusScrape]; !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 14:19:40 -07:00
|
|
|
func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
|
2020-07-01 18:03:22 -07:00
|
|
|
var zones []*models.Zone
|
2020-09-05 23:48:51 -07:00
|
|
|
consoleImage := ""
|
2020-07-25 14:38:16 -07:00
|
|
|
var totalSize int64
|
|
|
|
|
for _, z := range tenant.Spec.Zones {
|
2020-07-29 01:01:17 -07:00
|
|
|
zones = append(zones, parseTenantZone(&z))
|
2020-07-25 14:38:16 -07:00
|
|
|
zoneSize := int64(z.Servers) * int64(z.VolumesPerServer) * z.VolumeClaimTemplate.Spec.Resources.Requests.Storage().Value()
|
|
|
|
|
totalSize = totalSize + zoneSize
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-09-05 23:37:01 -07:00
|
|
|
var deletion string
|
|
|
|
|
if tenant.ObjectMeta.DeletionTimestamp != nil {
|
|
|
|
|
deletion = tenant.ObjectMeta.DeletionTimestamp.String()
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
|
2020-09-05 23:48:51 -07:00
|
|
|
if tenant.HasConsoleEnabled() {
|
|
|
|
|
consoleImage = tenant.Spec.Console.Image
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if tenant.Spec.Metadata == nil {
|
|
|
|
|
tenant.Spec.Metadata = &metav1.ObjectMeta{
|
|
|
|
|
Annotations: map[string]string{},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
return &models.Tenant{
|
2020-09-05 23:48:51 -07:00
|
|
|
CreationDate: tenant.ObjectMeta.CreationTimestamp.String(),
|
|
|
|
|
DeletionDate: deletion,
|
|
|
|
|
Name: tenant.Name,
|
|
|
|
|
TotalSize: totalSize,
|
|
|
|
|
CurrentState: tenant.Status.CurrentState,
|
|
|
|
|
Zones: zones,
|
|
|
|
|
Namespace: tenant.ObjectMeta.Namespace,
|
|
|
|
|
Image: tenant.Spec.Image,
|
|
|
|
|
ConsoleImage: consoleImage,
|
|
|
|
|
EnablePrometheus: isPrometheusEnabled(tenant.Spec.Metadata.Annotations),
|
2020-07-09 12:24:01 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:32:57 -07:00
|
|
|
func getTenantInfoResponse(session *models.Principal, params admin_api.TenantInfoParams) (*models.Tenant, *models.Error) {
|
2020-07-25 14:38:16 -07:00
|
|
|
// 5 seconds timeout
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
2020-07-09 12:24:01 -07:00
|
|
|
defer cancel()
|
|
|
|
|
|
2020-07-10 19:14:28 -07:00
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
2020-07-09 12:24:01 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-09 12:24:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-25 14:38:16 -07:00
|
|
|
minTenant, err := getTenant(ctx, opClient, params.Namespace, params.Tenant)
|
2020-07-09 12:24:01 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-09 12:24:01 -07:00
|
|
|
}
|
2020-07-25 14:38:16 -07:00
|
|
|
|
2020-07-27 14:19:40 -07:00
|
|
|
info := getTenantInfo(minTenant)
|
2020-07-09 12:24:01 -07:00
|
|
|
return info, nil
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
func listTenants(ctx context.Context, operatorClient OperatorClientI, namespace string, limit *int32) (*models.ListTenantsResponse, error) {
|
2020-07-01 18:03:22 -07:00
|
|
|
listOpts := metav1.ListOptions{
|
|
|
|
|
Limit: 10,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if limit != nil {
|
|
|
|
|
listOpts.Limit = int64(*limit)
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-25 14:38:16 -07:00
|
|
|
minTenants, err := operatorClient.TenantList(ctx, namespace, listOpts)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tenants []*models.TenantList
|
2020-07-27 18:03:47 -07:00
|
|
|
|
2020-07-30 13:55:11 -07:00
|
|
|
for _, tenant := range minTenants.Items {
|
|
|
|
|
var totalSize int64
|
2020-07-01 18:03:22 -07:00
|
|
|
var instanceCount int64
|
|
|
|
|
var volumeCount int64
|
2020-07-30 13:55:11 -07:00
|
|
|
for _, zone := range tenant.Spec.Zones {
|
2020-07-01 18:03:22 -07:00
|
|
|
instanceCount = instanceCount + int64(zone.Servers)
|
2020-07-25 14:38:16 -07:00
|
|
|
volumeCount = volumeCount + int64(zone.Servers*zone.VolumesPerServer)
|
2020-07-27 18:03:47 -07:00
|
|
|
if zone.VolumeClaimTemplate != nil {
|
|
|
|
|
zoneSize := int64(zone.VolumesPerServer) * int64(zone.Servers) * zone.VolumeClaimTemplate.Spec.Resources.Requests.Storage().Value()
|
|
|
|
|
totalSize = totalSize + zoneSize
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-09-05 23:37:01 -07:00
|
|
|
var deletion string
|
|
|
|
|
if tenant.ObjectMeta.DeletionTimestamp != nil {
|
|
|
|
|
deletion = tenant.ObjectMeta.DeletionTimestamp.String()
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
tenants = append(tenants, &models.TenantList{
|
2020-07-30 13:55:11 -07:00
|
|
|
CreationDate: tenant.ObjectMeta.CreationTimestamp.String(),
|
2020-09-05 23:37:01 -07:00
|
|
|
DeletionDate: deletion,
|
2020-07-30 13:55:11 -07:00
|
|
|
Name: tenant.ObjectMeta.Name,
|
|
|
|
|
ZoneCount: int64(len(tenant.Spec.Zones)),
|
2020-07-01 18:03:22 -07:00
|
|
|
InstanceCount: instanceCount,
|
|
|
|
|
VolumeCount: volumeCount,
|
2020-07-30 13:55:11 -07:00
|
|
|
CurrentState: tenant.Status.CurrentState,
|
|
|
|
|
Namespace: tenant.ObjectMeta.Namespace,
|
2020-07-27 18:03:47 -07:00
|
|
|
TotalSize: totalSize,
|
2020-07-01 18:03:22 -07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &models.ListTenantsResponse{
|
|
|
|
|
Tenants: tenants,
|
2020-07-30 13:55:11 -07:00
|
|
|
Total: int64(len(tenants)),
|
2020-07-01 18:03:22 -07:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:32:57 -07:00
|
|
|
func getListAllTenantsResponse(session *models.Principal, params admin_api.ListAllTenantsParams) (*models.ListTenantsResponse, *models.Error) {
|
2020-07-01 18:03:22 -07:00
|
|
|
ctx := context.Background()
|
2020-07-10 19:14:28 -07:00
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
listT, err := listTenants(ctx, opClient, "", params.Limit)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return listT, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// getListTenantsResponse list tenants by namespace
|
2020-09-04 20:32:57 -07:00
|
|
|
func getListTenantsResponse(session *models.Principal, params admin_api.ListTenantsParams) (*models.ListTenantsResponse, *models.Error) {
|
2020-07-01 18:03:22 -07:00
|
|
|
ctx := context.Background()
|
2020-07-10 19:14:28 -07:00
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
listT, err := listTenants(ctx, opClient, params.Namespace, params.Limit)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
return listT, nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:32:57 -07:00
|
|
|
func getTenantCreatedResponse(session *models.Principal, params admin_api.CreateTenantParams) (*models.CreateTenantResponse, *models.Error) {
|
2020-08-04 16:04:04 -07:00
|
|
|
tenantReq := params.Body
|
|
|
|
|
minioImage := tenantReq.Image
|
2020-08-04 20:54:59 -07:00
|
|
|
ctx := context.Background()
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
if minioImage == "" {
|
|
|
|
|
minImg, err := cluster.GetMinioImage()
|
2020-08-11 22:29:33 -07:00
|
|
|
// we can live without figuring out the latest version of MinIO, Operator will use a hardcoded value
|
|
|
|
|
if err == nil {
|
|
|
|
|
minioImage = *minImg
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-30 13:55:11 -07:00
|
|
|
// get Kubernetes Client
|
2020-09-03 10:20:58 -07:00
|
|
|
clientSet, err := cluster.K8sClient(session.SessionToken)
|
|
|
|
|
k8sClient := k8sClient{
|
|
|
|
|
client: clientSet,
|
|
|
|
|
}
|
2020-07-30 13:55:11 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-30 13:55:11 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-04 16:04:04 -07:00
|
|
|
ns := *tenantReq.Namespace
|
2020-07-01 18:03:22 -07:00
|
|
|
|
|
|
|
|
// if access/secret are provided, use them, else create a random pair
|
|
|
|
|
accessKey := RandomCharString(16)
|
|
|
|
|
secretKey := RandomCharString(32)
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-08-04 16:04:04 -07:00
|
|
|
if tenantReq.AccessKey != "" {
|
|
|
|
|
accessKey = tenantReq.AccessKey
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-04 16:04:04 -07:00
|
|
|
if tenantReq.SecretKey != "" {
|
|
|
|
|
secretKey = tenantReq.SecretKey
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-08-20 19:09:13 -07:00
|
|
|
tenantName := *tenantReq.Name
|
|
|
|
|
secretName := fmt.Sprintf("%s-secret", tenantName)
|
2020-07-01 18:03:22 -07:00
|
|
|
imm := true
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
instanceSecret := corev1.Secret{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
Name: secretName,
|
2020-08-20 19:09:13 -07:00
|
|
|
Labels: map[string]string{
|
|
|
|
|
operator.TenantLabel: tenantName,
|
|
|
|
|
},
|
2020-07-01 18:03:22 -07:00
|
|
|
},
|
|
|
|
|
Immutable: &imm,
|
|
|
|
|
Data: map[string][]byte{
|
|
|
|
|
"accesskey": []byte(accessKey),
|
|
|
|
|
"secretkey": []byte(secretKey),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
_, err = clientSet.CoreV1().Secrets(ns).Create(ctx, &instanceSecret, metav1.CreateOptions{})
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-04 22:32:41 -07:00
|
|
|
var envrionmentVariables []corev1.EnvVar
|
|
|
|
|
// Check the Erasure Coding Parity for validity and pass it to Tenant
|
|
|
|
|
if tenantReq.ErasureCodingParity > 0 {
|
|
|
|
|
if tenantReq.ErasureCodingParity < 2 && tenantReq.ErasureCodingParity > 8 {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(errorInvalidErasureCodingValue)
|
2020-08-04 22:32:41 -07:00
|
|
|
}
|
|
|
|
|
envrionmentVariables = append(envrionmentVariables, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_STORAGE_CLASS_STANDARD",
|
2020-08-07 12:28:46 -07:00
|
|
|
Value: fmt.Sprintf("EC:%d", tenantReq.ErasureCodingParity),
|
2020-08-04 22:32:41 -07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
//Construct a MinIO Instance with everything we are getting from parameters
|
2020-07-25 14:38:16 -07:00
|
|
|
minInst := operator.Tenant{
|
2020-07-01 18:03:22 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2020-08-20 19:09:13 -07:00
|
|
|
Name: tenantName,
|
2020-07-01 18:03:22 -07:00
|
|
|
},
|
2020-07-25 14:38:16 -07:00
|
|
|
Spec: operator.TenantSpec{
|
2020-07-01 18:03:22 -07:00
|
|
|
Image: minioImage,
|
|
|
|
|
Mountpath: "/export",
|
|
|
|
|
CredsSecret: &corev1.LocalObjectReference{
|
|
|
|
|
Name: secretName,
|
|
|
|
|
},
|
2020-08-04 22:32:41 -07:00
|
|
|
Env: envrionmentVariables,
|
2020-07-01 18:03:22 -07:00
|
|
|
},
|
|
|
|
|
}
|
2020-08-02 23:45:54 -07:00
|
|
|
idpEnabled := false
|
|
|
|
|
// Enable IDP (Active Directory) for MinIO
|
2020-08-04 16:04:04 -07:00
|
|
|
if tenantReq.Idp != nil && tenantReq.Idp.ActiveDirectory != nil {
|
|
|
|
|
url := *tenantReq.Idp.ActiveDirectory.URL
|
|
|
|
|
userNameFormat := *tenantReq.Idp.ActiveDirectory.UsernameFormat
|
|
|
|
|
userSearchFilter := *tenantReq.Idp.ActiveDirectory.UserSearchFilter
|
2020-08-09 16:08:58 -07:00
|
|
|
tlsSkipVerify := tenantReq.Idp.ActiveDirectory.SkipTLSVerification
|
2020-08-04 16:04:04 -07:00
|
|
|
serverInsecure := tenantReq.Idp.ActiveDirectory.ServerInsecure
|
|
|
|
|
groupSearchDN := tenantReq.Idp.ActiveDirectory.GroupSearchBaseDn
|
|
|
|
|
groupSearchFilter := tenantReq.Idp.ActiveDirectory.GroupSearchFilter
|
|
|
|
|
groupNameAttribute := tenantReq.Idp.ActiveDirectory.GroupNameAttribute
|
2020-08-02 23:45:54 -07:00
|
|
|
if url != "" && userNameFormat != "" && userSearchFilter != "" {
|
|
|
|
|
// CONSOLE_LDAP_ENABLED
|
|
|
|
|
idpEnabled = true
|
|
|
|
|
minInst.Spec.Env = append(minInst.Spec.Env, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_SERVER_ADDR",
|
|
|
|
|
Value: userNameFormat,
|
|
|
|
|
}, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_USERNAME_FORMAT",
|
|
|
|
|
Value: userNameFormat,
|
|
|
|
|
}, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_USERNAME_SEARCH_FILTER",
|
|
|
|
|
Value: userSearchFilter,
|
|
|
|
|
}, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_USERNAME_SEARCH_FILTER",
|
|
|
|
|
Value: userSearchFilter,
|
|
|
|
|
}, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_GROUP_SEARCH_BASE_DN",
|
|
|
|
|
Value: groupSearchDN,
|
|
|
|
|
}, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_GROUP_SEARCH_FILTER",
|
|
|
|
|
Value: groupSearchFilter,
|
|
|
|
|
}, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_GROUP_NAME_ATTRIBUTE",
|
|
|
|
|
Value: groupNameAttribute,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if tlsSkipVerify {
|
|
|
|
|
minInst.Spec.Env = append(minInst.Spec.Env, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_TLS_SKIP_VERIFY",
|
|
|
|
|
Value: "on",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if serverInsecure {
|
|
|
|
|
minInst.Spec.Env = append(minInst.Spec.Env, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_IDENTITY_LDAP_SERVER_INSECURE",
|
|
|
|
|
Value: "on",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-08-09 14:47:06 -07:00
|
|
|
isEncryptionAvailable := false
|
2020-08-09 17:19:39 -07:00
|
|
|
if tenantReq.EnableTLS != nil && *tenantReq.EnableTLS {
|
2020-08-09 14:47:06 -07:00
|
|
|
// If user request autoCert, Operator will generate certificate keypair for MinIO (server), Console (server) and KES (server and app mTLS)
|
|
|
|
|
isEncryptionAvailable = true
|
|
|
|
|
minInst.Spec.RequestAutoCert = *tenantReq.EnableTLS
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-09 14:47:06 -07:00
|
|
|
if !minInst.Spec.RequestAutoCert && tenantReq.TLS != nil && tenantReq.TLS.Minio != nil {
|
|
|
|
|
// User provided TLS certificates for MinIO
|
|
|
|
|
isEncryptionAvailable = true
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
// disable autoCert
|
|
|
|
|
minInst.Spec.RequestAutoCert = false
|
2020-09-03 10:20:58 -07:00
|
|
|
// Certificates used by the MinIO instance
|
|
|
|
|
externalCertSecretName := fmt.Sprintf("%s-instance-external-certificates", secretName)
|
|
|
|
|
externalCertSecret, err := createOrReplaceExternalCertSecret(ctx, &k8sClient, ns, tenantReq.TLS.Minio, externalCertSecretName, tenantName)
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
}
|
2020-09-03 10:20:58 -07:00
|
|
|
minInst.Spec.ExternalCertSecret = externalCertSecret
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-09 14:47:06 -07:00
|
|
|
if tenantReq.Encryption != nil && isEncryptionAvailable {
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
// Enable auto encryption
|
|
|
|
|
minInst.Spec.Env = append(minInst.Spec.Env, corev1.EnvVar{
|
|
|
|
|
Name: "MINIO_KMS_AUTO_ENCRYPTION",
|
|
|
|
|
Value: "on",
|
|
|
|
|
})
|
2020-08-09 14:47:06 -07:00
|
|
|
// KES client mTLSCertificates used by MinIO instance, only if autoCert is not enabled
|
|
|
|
|
if !minInst.Spec.RequestAutoCert {
|
2020-09-03 10:20:58 -07:00
|
|
|
tenantExternalClientCertSecretName := fmt.Sprintf("%s-tenant-external-client-cert", secretName)
|
|
|
|
|
minInst.Spec.ExternalClientCertSecret, err = createOrReplaceExternalCertSecret(ctx, &k8sClient, ns, tenantReq.Encryption.Client, tenantExternalClientCertSecretName, tenantName)
|
2020-08-09 14:47:06 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(errorGeneric)
|
2020-08-09 14:47:06 -07:00
|
|
|
}
|
2020-08-07 20:23:03 -07:00
|
|
|
}
|
|
|
|
|
// KES configuration for Tenant instance
|
2020-09-03 10:20:58 -07:00
|
|
|
minInst.Spec.KES, err = getKESConfiguration(ctx, &k8sClient, ns, tenantReq.Encryption, secretName, tenantName, minInst.Spec.RequestAutoCert)
|
2020-08-07 20:23:03 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(errorGeneric)
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
// optionals are set below
|
2020-07-30 13:55:11 -07:00
|
|
|
var consoleAccess string
|
|
|
|
|
var consoleSecret string
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-08-09 17:19:39 -07:00
|
|
|
enableConsole := true
|
|
|
|
|
if tenantReq.EnableConsole != nil && *tenantReq.EnableConsole {
|
|
|
|
|
enableConsole = *tenantReq.EnableConsole
|
|
|
|
|
}
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
|
2020-07-26 00:34:17 -07:00
|
|
|
if enableConsole {
|
2020-08-20 19:09:13 -07:00
|
|
|
consoleSelector := fmt.Sprintf("%s-console", tenantName)
|
2020-07-26 00:34:17 -07:00
|
|
|
consoleSecretName := fmt.Sprintf("%s-secret", consoleSelector)
|
2020-07-30 13:55:11 -07:00
|
|
|
consoleAccess = RandomCharString(16)
|
|
|
|
|
consoleSecret = RandomCharString(32)
|
2020-07-01 18:03:22 -07:00
|
|
|
imm := true
|
|
|
|
|
instanceSecret := corev1.Secret{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2020-07-26 00:34:17 -07:00
|
|
|
Name: consoleSecretName,
|
2020-08-20 19:09:13 -07:00
|
|
|
Labels: map[string]string{
|
|
|
|
|
operator.TenantLabel: tenantName,
|
|
|
|
|
},
|
2020-07-01 18:03:22 -07:00
|
|
|
},
|
|
|
|
|
Immutable: &imm,
|
|
|
|
|
Data: map[string][]byte{
|
2020-07-26 00:34:17 -07:00
|
|
|
"CONSOLE_HMAC_JWT_SECRET": []byte(RandomCharString(16)),
|
|
|
|
|
"CONSOLE_PBKDF_PASSPHRASE": []byte(RandomCharString(16)),
|
|
|
|
|
"CONSOLE_PBKDF_SALT": []byte(RandomCharString(8)),
|
2020-07-30 13:55:11 -07:00
|
|
|
"CONSOLE_ACCESS_KEY": []byte(consoleAccess),
|
|
|
|
|
"CONSOLE_SECRET_KEY": []byte(consoleSecret),
|
2020-07-01 18:03:22 -07:00
|
|
|
},
|
|
|
|
|
}
|
2020-08-02 23:45:54 -07:00
|
|
|
|
|
|
|
|
// Enable IDP (Open ID Connect) for console
|
2020-08-04 16:04:04 -07:00
|
|
|
if !idpEnabled && tenantReq.Idp != nil && tenantReq.Idp.Oidc != nil {
|
|
|
|
|
url := *tenantReq.Idp.Oidc.URL
|
|
|
|
|
clientID := *tenantReq.Idp.Oidc.ClientID
|
|
|
|
|
secretID := *tenantReq.Idp.Oidc.SecretID
|
2020-08-02 23:45:54 -07:00
|
|
|
if url != "" && clientID != "" && secretID != "" {
|
|
|
|
|
instanceSecret.Data["CONSOLE_IDP_URL"] = []byte(url)
|
|
|
|
|
instanceSecret.Data["CONSOLE_IDP_CLIENT_ID"] = []byte(clientID)
|
|
|
|
|
instanceSecret.Data["CONSOLE_IDP_SECRET"] = []byte(secretID)
|
|
|
|
|
consoleScheme := "http"
|
|
|
|
|
consolePort := 9090
|
|
|
|
|
if minInst.Spec.RequestAutoCert {
|
|
|
|
|
consoleScheme = "https"
|
|
|
|
|
consolePort = 9443
|
|
|
|
|
}
|
|
|
|
|
// https://[HOSTNAME]:9443 will be replaced by javascript in the browser to use the actual hostname
|
|
|
|
|
// assigned to Console, eg: https://localhost:9443
|
|
|
|
|
instanceSecret.Data["CONSOLE_IDP_CALLBACK"] = []byte(fmt.Sprintf("%s://[HOSTNAME]:%d/oauth_callback", consoleScheme, consolePort))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 10:20:58 -07:00
|
|
|
_, err = clientSet.CoreV1().Secrets(ns).Create(ctx, &instanceSecret, metav1.CreateOptions{})
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(errorGeneric)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-09-08 12:28:44 -07:00
|
|
|
const consoleVersion = "minio/console:v0.3.23"
|
2020-07-25 14:38:16 -07:00
|
|
|
minInst.Spec.Console = &operator.ConsoleConfiguration{
|
2020-08-11 18:20:43 -07:00
|
|
|
Replicas: 1,
|
2020-07-25 14:38:16 -07:00
|
|
|
Image: consoleVersion,
|
2020-07-26 00:34:17 -07:00
|
|
|
ConsoleSecret: &corev1.LocalObjectReference{Name: consoleSecretName},
|
2020-08-02 23:04:51 -07:00
|
|
|
Resources: corev1.ResourceRequirements{
|
|
|
|
|
Requests: map[corev1.ResourceName]resource.Quantity{
|
|
|
|
|
"memory": resource.MustParse("64Mi"),
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-09 17:19:39 -07:00
|
|
|
if !minInst.Spec.RequestAutoCert && tenantReq.TLS != nil && tenantReq.TLS.Console != nil {
|
2020-09-03 10:20:58 -07:00
|
|
|
// Certificates used by the console instance
|
|
|
|
|
externalCertSecretName := fmt.Sprintf("%s-console-external-certificates", secretName)
|
|
|
|
|
externalCertSecret, err := createOrReplaceExternalCertSecret(ctx, &k8sClient, ns, tenantReq.TLS.Console, externalCertSecretName, tenantName)
|
2020-08-09 14:47:06 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(errorGeneric)
|
2020-08-09 14:47:06 -07:00
|
|
|
}
|
2020-09-03 10:20:58 -07:00
|
|
|
minInst.Spec.Console.ExternalCertSecret = externalCertSecret
|
2020-08-09 14:47:06 -07:00
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set the service name if provided
|
2020-08-04 16:04:04 -07:00
|
|
|
if tenantReq.ServiceName != "" {
|
|
|
|
|
minInst.Spec.ServiceName = tenantReq.ServiceName
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-05 12:35:41 -07:00
|
|
|
// add annotations
|
|
|
|
|
var annotations map[string]string
|
2020-08-24 15:07:36 -07:00
|
|
|
if minInst.Spec.Metadata == nil {
|
|
|
|
|
minInst.Spec.Metadata = &metav1.ObjectMeta{
|
|
|
|
|
Annotations: map[string]string{},
|
2020-08-05 12:35:41 -07:00
|
|
|
}
|
2020-08-24 15:07:36 -07:00
|
|
|
}
|
|
|
|
|
if len(tenantReq.Annotations) > 0 {
|
2020-08-05 12:35:41 -07:00
|
|
|
annotations = tenantReq.Annotations
|
|
|
|
|
minInst.Spec.Metadata.Annotations = annotations
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
// set the zones if they are provided
|
2020-08-04 16:04:04 -07:00
|
|
|
for _, zone := range tenantReq.Zones {
|
2020-08-05 12:35:41 -07:00
|
|
|
zone, err := parseTenantZoneRequest(zone, annotations)
|
2020-07-29 01:01:17 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-07-29 01:01:17 -07:00
|
|
|
minInst.Spec.Zones = append(minInst.Spec.Zones, *zone)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set Mount Path if provided
|
2020-08-04 16:04:04 -07:00
|
|
|
if tenantReq.MounthPath != "" {
|
|
|
|
|
minInst.Spec.Mountpath = tenantReq.MounthPath
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-04 16:04:04 -07:00
|
|
|
|
2020-08-11 18:20:43 -07:00
|
|
|
// We accept either `image_pull_secret` or the individual details of the `image_registry` but not both
|
|
|
|
|
var imagePullSecret string
|
|
|
|
|
|
|
|
|
|
if tenantReq.ImagePullSecret != "" {
|
|
|
|
|
imagePullSecret = tenantReq.ImagePullSecret
|
2020-09-03 10:20:58 -07:00
|
|
|
} else if imagePullSecret, err = setImageRegistry(ctx, tenantName, tenantReq.ImageRegistry, clientSet.CoreV1(), ns); err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-11 18:20:43 -07:00
|
|
|
// pass the image pull secret to the Tenant
|
|
|
|
|
if imagePullSecret != "" {
|
|
|
|
|
minInst.Spec.ImagePullSecret = corev1.LocalObjectReference{
|
|
|
|
|
Name: imagePullSecret,
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
|
2020-08-24 15:07:36 -07:00
|
|
|
// prometheus annotations support
|
|
|
|
|
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Spec.Metadata != nil && minInst.Spec.Metadata.Annotations != nil {
|
2020-09-05 23:48:51 -07:00
|
|
|
minInst.Spec.Metadata.Annotations[prometheusPath] = "/minio/prometheus/metrics"
|
|
|
|
|
minInst.Spec.Metadata.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
|
|
|
|
|
minInst.Spec.Metadata.Annotations[prometheusScrape] = "true"
|
2020-08-24 15:07:36 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 18:20:43 -07:00
|
|
|
// set console image if provided
|
|
|
|
|
if tenantReq.ConsoleImage != "" {
|
|
|
|
|
minInst.Spec.Console.Image = tenantReq.ConsoleImage
|
2020-08-05 01:21:35 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-10 19:14:28 -07:00
|
|
|
opClient, err := cluster.OperatorClient(session.SessionToken)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-25 14:38:16 -07:00
|
|
|
_, err = opClient.MinioV1().Tenants(ns).Create(context.Background(), &minInst, metav1.CreateOptions{})
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Integratrions
|
|
|
|
|
if os.Getenv("GKE_INTEGRATION") != "" {
|
2020-09-03 10:20:58 -07:00
|
|
|
err := gkeIntegration(clientSet, tenantName, ns, session.SessionToken)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
2020-07-30 13:55:11 -07:00
|
|
|
response := &models.CreateTenantResponse{
|
2020-07-01 18:03:22 -07:00
|
|
|
AccessKey: accessKey,
|
|
|
|
|
SecretKey: secretKey,
|
2020-07-30 13:55:11 -07:00
|
|
|
}
|
|
|
|
|
// Attach Console Credentials
|
|
|
|
|
if enableConsole {
|
2020-08-04 16:04:04 -07:00
|
|
|
response.Console = &models.CreateTenantResponseConsole{
|
|
|
|
|
AccessKey: consoleAccess,
|
|
|
|
|
SecretKey: consoleSecret,
|
|
|
|
|
}
|
2020-07-30 13:55:11 -07:00
|
|
|
}
|
|
|
|
|
return response, nil
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 18:20:43 -07:00
|
|
|
// setImageRegistry creates a secret to store the private registry credentials, if one exist it updates the existing one
|
|
|
|
|
// returns the name of the secret created/updated
|
|
|
|
|
func setImageRegistry(ctx context.Context, tenantName string, req *models.ImageRegistry, clientset v1.CoreV1Interface, namespace string) (string, error) {
|
2020-08-04 20:54:59 -07:00
|
|
|
if req == nil || req.Registry == nil || req.Username == nil || req.Password == nil {
|
2020-08-11 18:20:43 -07:00
|
|
|
return "", nil
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
credentials := make(map[string]imageRegistryCredentials)
|
|
|
|
|
// username:password encoded
|
|
|
|
|
authData := []byte(fmt.Sprintf("%s:%s", *req.Username, *req.Password))
|
|
|
|
|
authStr := base64.StdEncoding.EncodeToString(authData)
|
|
|
|
|
|
|
|
|
|
credentials[*req.Registry] = imageRegistryCredentials{
|
|
|
|
|
Username: *req.Username,
|
|
|
|
|
Password: *req.Password,
|
|
|
|
|
Auth: authStr,
|
|
|
|
|
}
|
|
|
|
|
imRegistry := imageRegistry{
|
|
|
|
|
Auths: credentials,
|
|
|
|
|
}
|
|
|
|
|
imRegistryJSON, err := json.Marshal(imRegistry)
|
|
|
|
|
if err != nil {
|
2020-08-11 18:20:43 -07:00
|
|
|
return "", err
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 18:20:43 -07:00
|
|
|
pullSecretName := fmt.Sprintf("%s-regcred", tenantName)
|
2020-09-06 23:20:27 -07:00
|
|
|
secretCredentials := map[string][]byte{
|
|
|
|
|
corev1.DockerConfigJsonKey: []byte(string(imRegistryJSON)),
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
|
|
|
|
// Get or Create secret if it doesn't exist
|
2020-09-06 23:20:27 -07:00
|
|
|
currentSecret, err := clientset.Secrets(namespace).Get(ctx, pullSecretName, metav1.GetOptions{})
|
2020-08-04 20:54:59 -07:00
|
|
|
if err != nil {
|
|
|
|
|
if k8sErrors.IsNotFound(err) {
|
2020-09-06 23:20:27 -07:00
|
|
|
instanceSecret := corev1.Secret{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
Name: pullSecretName,
|
|
|
|
|
Labels: map[string]string{
|
|
|
|
|
operator.TenantLabel: tenantName,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Data: secretCredentials,
|
|
|
|
|
Type: corev1.SecretTypeDockerConfigJson,
|
|
|
|
|
}
|
2020-08-04 20:54:59 -07:00
|
|
|
_, err = clientset.Secrets(namespace).Create(ctx, &instanceSecret, metav1.CreateOptions{})
|
|
|
|
|
if err != nil {
|
2020-08-11 18:20:43 -07:00
|
|
|
return "", err
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
2020-09-04 17:09:17 -07:00
|
|
|
return pullSecretName, nil
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
2020-08-11 18:20:43 -07:00
|
|
|
return "", err
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
2020-09-06 23:20:27 -07:00
|
|
|
currentSecret.Data = secretCredentials
|
|
|
|
|
_, err = clientset.Secrets(namespace).Update(ctx, currentSecret, metav1.UpdateOptions{})
|
2020-08-04 20:54:59 -07:00
|
|
|
if err != nil {
|
2020-08-11 18:20:43 -07:00
|
|
|
return "", err
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
2020-08-11 18:20:43 -07:00
|
|
|
return pullSecretName, nil
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-25 14:38:16 -07:00
|
|
|
// updateTenantAction does an update on the minioTenant by patching the desired changes
|
2020-09-03 10:20:58 -07:00
|
|
|
func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, clientset v1.CoreV1Interface, httpCl cluster.HTTPClientI, namespace string, params admin_api.UpdateTenantParams) error {
|
2020-07-01 18:03:22 -07:00
|
|
|
imageToUpdate := params.Body.Image
|
2020-08-04 20:54:59 -07:00
|
|
|
imageRegistryReq := params.Body.ImageRegistry
|
|
|
|
|
|
|
|
|
|
minInst, err := operatorClient.TenantGet(ctx, namespace, params.Tenant, metav1.GetOptions{})
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2020-08-11 18:20:43 -07:00
|
|
|
// we can take either the `image_pull_secret` of the `image_registry` but not both
|
|
|
|
|
if params.Body.ImagePullSecret != "" {
|
|
|
|
|
minInst.Spec.ImagePullSecret.Name = params.Body.ImagePullSecret
|
|
|
|
|
} else {
|
|
|
|
|
// update the image pull secret content
|
|
|
|
|
if _, err := setImageRegistry(ctx, params.Tenant, imageRegistryReq, clientset, namespace); err != nil {
|
|
|
|
|
log.Println("error setting image registry secret:", err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update the console image
|
|
|
|
|
if strings.TrimSpace(params.Body.ConsoleImage) != "" && minInst.Spec.Console != nil {
|
|
|
|
|
minInst.Spec.Console.Image = params.Body.ConsoleImage
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
|
|
|
|
|
// if image to update is empty we'll use the latest image by default
|
|
|
|
|
if strings.TrimSpace(imageToUpdate) != "" {
|
2020-08-04 20:54:59 -07:00
|
|
|
minInst.Spec.Image = imageToUpdate
|
2020-07-01 18:03:22 -07:00
|
|
|
} else {
|
|
|
|
|
im, err := cluster.GetLatestMinioImage(httpCl)
|
2020-08-11 18:20:43 -07:00
|
|
|
// if we can't get the MinIO image, we won' auto-update it unless it's explicit by name
|
|
|
|
|
if err == nil {
|
|
|
|
|
minInst.Spec.Image = *im
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 23:48:51 -07:00
|
|
|
// Prometheus Annotations
|
|
|
|
|
if minInst.Spec.Metadata == nil {
|
|
|
|
|
minInst.Spec.Metadata = &metav1.ObjectMeta{
|
|
|
|
|
Annotations: map[string]string{},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
currentAnnotations := minInst.Spec.Metadata.Annotations
|
|
|
|
|
prometheusAnnotations := map[string]string{
|
|
|
|
|
prometheusPath: "/minio/prometheus/metrics",
|
|
|
|
|
prometheusPort: fmt.Sprint(operator.MinIOPort),
|
|
|
|
|
prometheusScrape: "true",
|
|
|
|
|
}
|
|
|
|
|
if params.Body.EnablePrometheus && minInst.Spec.Metadata != nil && currentAnnotations != nil {
|
|
|
|
|
// add prometheus annotations to the tenant
|
|
|
|
|
minInst.Spec.Metadata.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
|
|
|
|
|
// add prometheus annotations to the each zone
|
|
|
|
|
if minInst.Spec.Zones != nil {
|
|
|
|
|
for _, zone := range minInst.Spec.Zones {
|
|
|
|
|
zoneAnnotations := zone.VolumeClaimTemplate.GetObjectMeta().GetAnnotations()
|
|
|
|
|
zone.VolumeClaimTemplate.GetObjectMeta().SetAnnotations(addAnnotations(zoneAnnotations, prometheusAnnotations))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// remove prometheus annotations to the tenant
|
|
|
|
|
minInst.Spec.Metadata.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
|
|
|
|
|
// add prometheus annotations from each zone
|
|
|
|
|
if minInst.Spec.Zones != nil {
|
|
|
|
|
for _, zone := range minInst.Spec.Zones {
|
|
|
|
|
zoneAnnotations := zone.VolumeClaimTemplate.GetObjectMeta().GetAnnotations()
|
|
|
|
|
zone.VolumeClaimTemplate.GetObjectMeta().SetAnnotations(removeAnnotations(zoneAnnotations, prometheusAnnotations))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:03:22 -07:00
|
|
|
payloadBytes, err := json.Marshal(minInst)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2020-08-04 20:54:59 -07:00
|
|
|
_, err = operatorClient.TenantPatch(ctx, namespace, minInst.Name, types.MergePatchType, payloadBytes, metav1.PatchOptions{})
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 23:48:51 -07:00
|
|
|
// addAnnotations will merge two annotation maps
|
|
|
|
|
func addAnnotations(annotationsOne, annotationsTwo map[string]string) map[string]string {
|
|
|
|
|
if annotationsOne == nil {
|
|
|
|
|
annotationsOne = map[string]string{}
|
|
|
|
|
}
|
|
|
|
|
for key, value := range annotationsTwo {
|
|
|
|
|
annotationsOne[key] = value
|
|
|
|
|
}
|
|
|
|
|
return annotationsOne
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// removeAnnotations will remove keys from the first annotations map based on the second one
|
|
|
|
|
func removeAnnotations(annotationsOne, annotationsTwo map[string]string) map[string]string {
|
|
|
|
|
if annotationsOne == nil {
|
|
|
|
|
annotationsOne = map[string]string{}
|
|
|
|
|
}
|
|
|
|
|
for key := range annotationsTwo {
|
|
|
|
|
delete(annotationsOne, key)
|
|
|
|
|
}
|
|
|
|
|
return annotationsOne
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:32:57 -07:00
|
|
|
func getUpdateTenantResponse(session *models.Principal, params admin_api.UpdateTenantParams) *models.Error {
|
2020-07-01 18:03:22 -07:00
|
|
|
ctx := context.Background()
|
2020-07-10 19:14:28 -07:00
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
2020-07-01 18:03:22 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return prepareError(err)
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-08-04 20:54:59 -07:00
|
|
|
// get Kubernetes Client
|
2020-09-04 20:32:57 -07:00
|
|
|
clientSet, err := cluster.K8sClient(session.SessionToken)
|
2020-08-04 20:54:59 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return prepareError(err)
|
2020-08-04 20:54:59 -07:00
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
httpC := &cluster.HTTPClient{
|
|
|
|
|
Client: &http.Client{
|
|
|
|
|
Timeout: 4 * time.Second,
|
|
|
|
|
},
|
|
|
|
|
}
|
2020-09-04 20:32:57 -07:00
|
|
|
if err := updateTenantAction(ctx, opClient, clientSet.CoreV1(), httpC, params.Namespace, params); err != nil {
|
|
|
|
|
return prepareError(err, errors.New("unable to update tenant"))
|
2020-07-01 18:03:22 -07:00
|
|
|
}
|
2020-07-13 20:36:27 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// addTenantZone creates a zone to a defined tenant
|
2020-09-03 10:20:58 -07:00
|
|
|
func addTenantZone(ctx context.Context, operatorClient OperatorClientI, params admin_api.TenantAddZoneParams) error {
|
2020-07-29 01:01:17 -07:00
|
|
|
tenant, err := operatorClient.TenantGet(ctx, params.Namespace, params.Tenant, metav1.GetOptions{})
|
2020-07-13 20:36:27 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 14:06:12 -07:00
|
|
|
zoneParams := params.Body
|
2020-08-05 12:35:41 -07:00
|
|
|
zone, err := parseTenantZoneRequest(zoneParams, tenant.ObjectMeta.Annotations)
|
2020-07-27 14:06:12 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2020-07-29 01:01:17 -07:00
|
|
|
tenant.Spec.Zones = append(tenant.Spec.Zones, *zone)
|
|
|
|
|
payloadBytes, err := json.Marshal(tenant)
|
2020-07-13 20:36:27 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
|
2020-07-29 01:01:17 -07:00
|
|
|
_, err = operatorClient.TenantPatch(ctx, params.Namespace, tenant.Name, types.MergePatchType, payloadBytes, metav1.PatchOptions{})
|
2020-07-13 20:36:27 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:32:57 -07:00
|
|
|
func getTenantAddZoneResponse(session *models.Principal, params admin_api.TenantAddZoneParams) *models.Error {
|
2020-07-13 20:36:27 -07:00
|
|
|
ctx := context.Background()
|
|
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return prepareError(err)
|
2020-07-13 20:36:27 -07:00
|
|
|
}
|
|
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
if err := addTenantZone(ctx, opClient, params); err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return prepareError(err, errors.New("unable to add zone"))
|
2020-07-13 20:36:27 -07:00
|
|
|
}
|
2020-07-01 18:03:22 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
2020-07-27 14:19:40 -07:00
|
|
|
|
|
|
|
|
// getTenantUsageResponse returns the usage of a tenant
|
2020-09-04 20:32:57 -07:00
|
|
|
func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenantUsageParams) (*models.TenantUsage, *models.Error) {
|
2020-07-27 14:19:40 -07:00
|
|
|
// 5 seconds timeout
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err, errorUnableToGetTenantUsage)
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
2020-09-04 20:32:57 -07:00
|
|
|
clientSet, err := cluster.K8sClient(session.SessionToken)
|
2020-07-27 14:19:40 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err, errorUnableToGetTenantUsage)
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
k8sClient := &k8sClient{
|
2020-09-04 20:32:57 -07:00
|
|
|
client: clientSet,
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
minTenant, err := getTenant(ctx, opClient, params.Namespace, params.Tenant)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err, errorUnableToGetTenantUsage)
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
2020-08-09 14:36:55 -07:00
|
|
|
minTenant.EnsureDefaults()
|
2020-07-27 14:19:40 -07:00
|
|
|
tenantScheme := getTenantScheme(minTenant)
|
|
|
|
|
|
2020-08-09 14:36:55 -07:00
|
|
|
svcName := fmt.Sprintf("%s.%s.svc.cluster.local", minTenant.MinIOCIServiceName(), minTenant.Namespace)
|
2020-07-27 14:19:40 -07:00
|
|
|
|
|
|
|
|
mAdmin, err := getTenantAdminClient(
|
|
|
|
|
ctx,
|
|
|
|
|
k8sClient,
|
|
|
|
|
params.Namespace,
|
|
|
|
|
params.Tenant,
|
|
|
|
|
svcName,
|
2020-08-09 14:36:55 -07:00
|
|
|
tenantScheme,
|
|
|
|
|
true)
|
2020-07-27 14:19:40 -07:00
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err, errorUnableToGetTenantUsage)
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
|
|
|
|
// create a minioClient interface implementation
|
|
|
|
|
// defining the client to be used
|
|
|
|
|
adminClient := adminClient{client: mAdmin}
|
|
|
|
|
// serialize output
|
|
|
|
|
adminInfo, err := getAdminInfo(ctx, adminClient)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err, errorUnableToGetTenantUsage)
|
2020-07-27 14:19:40 -07:00
|
|
|
}
|
2020-08-03 12:11:48 -07:00
|
|
|
info := &models.TenantUsage{Used: adminInfo.Usage, DiskUsed: adminInfo.DisksUsage}
|
2020-07-27 14:19:40 -07:00
|
|
|
return info, nil
|
|
|
|
|
}
|
2020-07-29 01:01:17 -07:00
|
|
|
|
|
|
|
|
// parseTenantZoneRequest parse zone request and returns the equivalent
|
|
|
|
|
// operator.Zone object
|
2020-08-05 12:35:41 -07:00
|
|
|
func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]string) (*operator.Zone, error) {
|
2020-07-29 01:01:17 -07:00
|
|
|
if zoneParams.VolumeConfiguration == nil {
|
|
|
|
|
return nil, errors.New("a volume configuration must be specified")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if zoneParams.VolumeConfiguration.Size == nil || *zoneParams.VolumeConfiguration.Size <= int64(0) {
|
|
|
|
|
return nil, errors.New("volume size must be greater than 0")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if zoneParams.Servers == nil || *zoneParams.Servers <= 0 {
|
|
|
|
|
return nil, errors.New("number of servers must be greater than 0")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if zoneParams.VolumesPerServer == nil || *zoneParams.VolumesPerServer <= 0 {
|
|
|
|
|
return nil, errors.New("number of volumes per server must be greater than 0")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volumeSize := resource.NewQuantity(*zoneParams.VolumeConfiguration.Size, resource.DecimalExponent)
|
|
|
|
|
volTemp := corev1.PersistentVolumeClaimSpec{
|
|
|
|
|
AccessModes: []corev1.PersistentVolumeAccessMode{
|
|
|
|
|
corev1.ReadWriteOnce,
|
|
|
|
|
},
|
|
|
|
|
Resources: corev1.ResourceRequirements{
|
|
|
|
|
Requests: corev1.ResourceList{
|
|
|
|
|
corev1.ResourceStorage: *volumeSize,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
if zoneParams.VolumeConfiguration.StorageClassName != "" {
|
|
|
|
|
volTemp.StorageClassName = &zoneParams.VolumeConfiguration.StorageClassName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse resources' requests
|
TLS with user provided certificates and KES support for MinIO (#213)
This PR adds the following features:
- Allow user to provide its own keypair certificates for enable TLS in
MinIO
- Allow user to configure data encryption at rest in MinIO with KES
- Removes JWT schema for login and instead Console authentication will use
encrypted session tokens
Enable TLS between client and MinIO with user provided certificates
Instead of using AutoCert feature now the user can provide `cert` and
`key` via `tls` object, values must be valid `x509.Certificate`
formatted files encoded in `base64`
Enable encryption at rest configuring KES
User can deploy KES via Console/Operator by defining the encryption
object, AutoCert must be enabled or custom certificates for KES must be
provided, KES support 3 KMS backends: `Vault`, `AWS KMS` and `Gemalto`,
previous configuration of the KMS is necessary.
eg of body request for create-tenant
```
{
"name": "honeywell",
"access_key": "minio",
"secret_key": "minio123",
"enable_mcs": false,
"enable_ssl": false,
"service_name": "honeywell",
"zones": [
{
"name": "honeywell-zone-1",
"servers": 1,
"volumes_per_server": 4,
"volume_configuration": {
"size": 256000000,
"storage_class": "vsan-default-storage-policy"
}
}
],
"namespace": "default",
"tls": {
"tls.crt": "",
"tls.key": ""
},
"encryption": {
"server": {
"tls.crt": "",
"tls.key": ""
},
"client": {
"tls.crt": "",
"tls.key": ""
},
"vault": {
"endpoint": "http://vault:8200",
"prefix": "",
"approle": {
"id": "",
"secret": ""
}
}
}
}
```
2020-07-30 17:49:56 -07:00
|
|
|
resourcesRequests := make(corev1.ResourceList)
|
|
|
|
|
resourcesLimits := make(corev1.ResourceList)
|
2020-07-29 01:01:17 -07:00
|
|
|
if zoneParams.Resources != nil {
|
|
|
|
|
for key, val := range zoneParams.Resources.Requests {
|
|
|
|
|
resourcesRequests[corev1.ResourceName(key)] = *resource.NewQuantity(val, resource.BinarySI)
|
|
|
|
|
}
|
|
|
|
|
for key, val := range zoneParams.Resources.Limits {
|
|
|
|
|
resourcesLimits[corev1.ResourceName(key)] = *resource.NewQuantity(val, resource.BinarySI)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse Node Affinity
|
|
|
|
|
nodeSelectorTerms := []corev1.NodeSelectorTerm{}
|
|
|
|
|
preferredSchedulingTerm := []corev1.PreferredSchedulingTerm{}
|
|
|
|
|
if zoneParams.Affinity != nil && zoneParams.Affinity.NodeAffinity != nil {
|
|
|
|
|
if zoneParams.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
|
|
|
|
|
for _, elem := range zoneParams.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
|
|
|
|
|
term := parseModelsNodeSelectorTerm(elem)
|
|
|
|
|
nodeSelectorTerms = append(nodeSelectorTerms, term)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, elem := range zoneParams.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
pst := corev1.PreferredSchedulingTerm{
|
|
|
|
|
Weight: *elem.Weight,
|
|
|
|
|
Preference: parseModelsNodeSelectorTerm(elem.Preference),
|
|
|
|
|
}
|
|
|
|
|
preferredSchedulingTerm = append(preferredSchedulingTerm, pst)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var nodeAffinity *corev1.NodeAffinity
|
|
|
|
|
if len(nodeSelectorTerms) > 0 || len(preferredSchedulingTerm) > 0 {
|
|
|
|
|
nodeAffinity = &corev1.NodeAffinity{
|
|
|
|
|
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
|
|
|
|
|
NodeSelectorTerms: nodeSelectorTerms,
|
|
|
|
|
},
|
|
|
|
|
PreferredDuringSchedulingIgnoredDuringExecution: preferredSchedulingTerm,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse Pod Affinity
|
|
|
|
|
podAffinityTerms := []corev1.PodAffinityTerm{}
|
|
|
|
|
weightedPodAffinityTerms := []corev1.WeightedPodAffinityTerm{}
|
|
|
|
|
if zoneParams.Affinity != nil && zoneParams.Affinity.PodAffinity != nil {
|
|
|
|
|
for _, elem := range zoneParams.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
podAffinityTerms = append(podAffinityTerms, parseModelPodAffinityTerm(elem))
|
|
|
|
|
}
|
|
|
|
|
for _, elem := range zoneParams.Affinity.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
wAffinityTerm := corev1.WeightedPodAffinityTerm{
|
|
|
|
|
Weight: *elem.Weight,
|
|
|
|
|
PodAffinityTerm: parseModelPodAffinityTerm(elem.PodAffinityTerm),
|
|
|
|
|
}
|
|
|
|
|
weightedPodAffinityTerms = append(weightedPodAffinityTerms, wAffinityTerm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var podAffinity *corev1.PodAffinity
|
|
|
|
|
if len(podAffinityTerms) > 0 || len(weightedPodAffinityTerms) > 0 {
|
|
|
|
|
podAffinity = &corev1.PodAffinity{
|
|
|
|
|
RequiredDuringSchedulingIgnoredDuringExecution: podAffinityTerms,
|
|
|
|
|
PreferredDuringSchedulingIgnoredDuringExecution: weightedPodAffinityTerms,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse Pod Anti Affinity
|
|
|
|
|
podAntiAffinityTerms := []corev1.PodAffinityTerm{}
|
|
|
|
|
weightedPodAntiAffinityTerms := []corev1.WeightedPodAffinityTerm{}
|
|
|
|
|
if zoneParams.Affinity != nil && zoneParams.Affinity.PodAntiAffinity != nil {
|
|
|
|
|
for _, elem := range zoneParams.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
podAntiAffinityTerms = append(podAntiAffinityTerms, parseModelPodAffinityTerm(elem))
|
|
|
|
|
}
|
|
|
|
|
for _, elem := range zoneParams.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
wAffinityTerm := corev1.WeightedPodAffinityTerm{
|
|
|
|
|
Weight: *elem.Weight,
|
|
|
|
|
PodAffinityTerm: parseModelPodAffinityTerm(elem.PodAffinityTerm),
|
|
|
|
|
}
|
|
|
|
|
weightedPodAntiAffinityTerms = append(weightedPodAntiAffinityTerms, wAffinityTerm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var podAntiAffinity *corev1.PodAntiAffinity
|
|
|
|
|
if len(podAntiAffinityTerms) > 0 || len(weightedPodAntiAffinityTerms) > 0 {
|
|
|
|
|
podAntiAffinity = &corev1.PodAntiAffinity{
|
|
|
|
|
RequiredDuringSchedulingIgnoredDuringExecution: podAntiAffinityTerms,
|
|
|
|
|
PreferredDuringSchedulingIgnoredDuringExecution: weightedPodAntiAffinityTerms,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var affinity *corev1.Affinity
|
|
|
|
|
if nodeAffinity != nil || podAffinity != nil || podAntiAffinity != nil {
|
|
|
|
|
affinity = &corev1.Affinity{
|
|
|
|
|
NodeAffinity: nodeAffinity,
|
|
|
|
|
PodAffinity: podAffinity,
|
|
|
|
|
PodAntiAffinity: podAntiAffinity,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse tolerations
|
|
|
|
|
tolerations := []corev1.Toleration{}
|
|
|
|
|
for _, elem := range zoneParams.Tolerations {
|
2020-08-07 20:00:16 -07:00
|
|
|
var tolerationSeconds *int64
|
|
|
|
|
if elem.TolerationSeconds != nil {
|
|
|
|
|
// elem.TolerationSeconds.Seconds is allowed to be nil
|
|
|
|
|
tolerationSeconds = elem.TolerationSeconds.Seconds
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-29 01:01:17 -07:00
|
|
|
toleration := corev1.Toleration{
|
|
|
|
|
Key: elem.Key,
|
|
|
|
|
Operator: corev1.TolerationOperator(elem.Operator),
|
|
|
|
|
Value: elem.Value,
|
|
|
|
|
Effect: corev1.TaintEffect(elem.Effect),
|
2020-08-07 20:00:16 -07:00
|
|
|
TolerationSeconds: tolerationSeconds,
|
2020-07-29 01:01:17 -07:00
|
|
|
}
|
|
|
|
|
tolerations = append(tolerations, toleration)
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 12:35:41 -07:00
|
|
|
// Pass annotations to the volume
|
|
|
|
|
vct := &corev1.PersistentVolumeClaim{
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2020-08-20 22:46:07 -07:00
|
|
|
Name: "data",
|
|
|
|
|
Labels: zoneParams.VolumeConfiguration.Labels,
|
2020-07-29 01:01:17 -07:00
|
|
|
},
|
2020-08-05 12:35:41 -07:00
|
|
|
Spec: volTemp,
|
|
|
|
|
}
|
|
|
|
|
if len(annotations) > 0 {
|
|
|
|
|
vct.ObjectMeta.Annotations = annotations
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zone := &operator.Zone{
|
|
|
|
|
Name: zoneParams.Name,
|
|
|
|
|
Servers: int32(*zoneParams.Servers),
|
|
|
|
|
VolumesPerServer: *zoneParams.VolumesPerServer,
|
|
|
|
|
VolumeClaimTemplate: vct,
|
2020-07-29 01:01:17 -07:00
|
|
|
Resources: corev1.ResourceRequirements{
|
|
|
|
|
Requests: resourcesRequests,
|
|
|
|
|
Limits: resourcesLimits,
|
|
|
|
|
},
|
|
|
|
|
NodeSelector: zoneParams.NodeSelector,
|
|
|
|
|
Affinity: affinity,
|
|
|
|
|
Tolerations: tolerations,
|
|
|
|
|
}
|
|
|
|
|
return zone, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseModelPodAffinityTerm(term *models.PodAffinityTerm) corev1.PodAffinityTerm {
|
|
|
|
|
labelMatchExpressions := []metav1.LabelSelectorRequirement{}
|
|
|
|
|
for _, exp := range term.LabelSelector.MatchExpressions {
|
|
|
|
|
labelSelectorReq := metav1.LabelSelectorRequirement{
|
|
|
|
|
Key: *exp.Key,
|
|
|
|
|
Operator: metav1.LabelSelectorOperator(*exp.Operator),
|
|
|
|
|
Values: exp.Values,
|
|
|
|
|
}
|
|
|
|
|
labelMatchExpressions = append(labelMatchExpressions, labelSelectorReq)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
podAffinityTerm := corev1.PodAffinityTerm{
|
|
|
|
|
LabelSelector: &metav1.LabelSelector{
|
|
|
|
|
MatchExpressions: labelMatchExpressions,
|
|
|
|
|
MatchLabels: term.LabelSelector.MatchLabels,
|
|
|
|
|
},
|
|
|
|
|
Namespaces: term.Namespaces,
|
|
|
|
|
TopologyKey: *term.TopologyKey,
|
|
|
|
|
}
|
|
|
|
|
return podAffinityTerm
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseModelsNodeSelectorTerm(elem *models.NodeSelectorTerm) corev1.NodeSelectorTerm {
|
|
|
|
|
var term corev1.NodeSelectorTerm
|
|
|
|
|
for _, matchExpression := range elem.MatchExpressions {
|
|
|
|
|
matchExp := corev1.NodeSelectorRequirement{
|
|
|
|
|
Key: *matchExpression.Key,
|
|
|
|
|
Operator: corev1.NodeSelectorOperator(*matchExpression.Operator),
|
|
|
|
|
Values: matchExpression.Values,
|
|
|
|
|
}
|
|
|
|
|
term.MatchExpressions = append(term.MatchExpressions, matchExp)
|
|
|
|
|
}
|
|
|
|
|
for _, matchField := range elem.MatchFields {
|
|
|
|
|
matchF := corev1.NodeSelectorRequirement{
|
|
|
|
|
Key: *matchField.Key,
|
|
|
|
|
Operator: corev1.NodeSelectorOperator(*matchField.Operator),
|
|
|
|
|
Values: matchField.Values,
|
|
|
|
|
}
|
|
|
|
|
term.MatchFields = append(term.MatchFields, matchF)
|
|
|
|
|
}
|
|
|
|
|
return term
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parseTenantZone operator Zone object and returns the equivalent
|
|
|
|
|
// models.Zone object
|
|
|
|
|
func parseTenantZone(zone *operator.Zone) *models.Zone {
|
|
|
|
|
var size *int64
|
|
|
|
|
var storageClassName string
|
|
|
|
|
if zone.VolumeClaimTemplate != nil {
|
|
|
|
|
size = swag.Int64(zone.VolumeClaimTemplate.Spec.Resources.Requests.Storage().Value())
|
|
|
|
|
if zone.VolumeClaimTemplate.Spec.StorageClassName != nil {
|
|
|
|
|
storageClassName = *zone.VolumeClaimTemplate.Spec.StorageClassName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse resources' requests
|
|
|
|
|
var resources *models.ZoneResources
|
2020-07-29 12:11:48 -07:00
|
|
|
resourcesRequests := make(map[string]int64)
|
|
|
|
|
resourcesLimits := make(map[string]int64)
|
2020-07-29 01:01:17 -07:00
|
|
|
for key, val := range zone.Resources.Requests {
|
|
|
|
|
resourcesRequests[key.String()] = val.Value()
|
|
|
|
|
}
|
|
|
|
|
for key, val := range zone.Resources.Limits {
|
|
|
|
|
resourcesLimits[key.String()] = val.Value()
|
|
|
|
|
}
|
|
|
|
|
if len(resourcesRequests) > 0 || len(resourcesLimits) > 0 {
|
|
|
|
|
resources = &models.ZoneResources{
|
|
|
|
|
Limits: resourcesLimits,
|
|
|
|
|
Requests: resourcesRequests,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse Node Affinity
|
|
|
|
|
nodeSelectorTerms := []*models.NodeSelectorTerm{}
|
|
|
|
|
preferredSchedulingTerm := []*models.ZoneAffinityNodeAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0{}
|
|
|
|
|
|
|
|
|
|
if zone.Affinity != nil && zone.Affinity.NodeAffinity != nil {
|
|
|
|
|
if zone.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
|
|
|
|
|
for _, elem := range zone.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
|
|
|
|
|
term := parseNodeSelectorTerm(&elem)
|
|
|
|
|
nodeSelectorTerms = append(nodeSelectorTerms, term)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, elem := range zone.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
pst := &models.ZoneAffinityNodeAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0{
|
|
|
|
|
Weight: swag.Int32(elem.Weight),
|
|
|
|
|
Preference: parseNodeSelectorTerm(&elem.Preference),
|
|
|
|
|
}
|
|
|
|
|
preferredSchedulingTerm = append(preferredSchedulingTerm, pst)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nodeAffinity *models.ZoneAffinityNodeAffinity
|
|
|
|
|
if len(nodeSelectorTerms) > 0 || len(preferredSchedulingTerm) > 0 {
|
|
|
|
|
nodeAffinity = &models.ZoneAffinityNodeAffinity{
|
|
|
|
|
RequiredDuringSchedulingIgnoredDuringExecution: &models.ZoneAffinityNodeAffinityRequiredDuringSchedulingIgnoredDuringExecution{
|
|
|
|
|
NodeSelectorTerms: nodeSelectorTerms,
|
|
|
|
|
},
|
|
|
|
|
PreferredDuringSchedulingIgnoredDuringExecution: preferredSchedulingTerm,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse Pod Affinity
|
|
|
|
|
podAffinityTerms := []*models.PodAffinityTerm{}
|
|
|
|
|
weightedPodAffinityTerms := []*models.ZoneAffinityPodAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0{}
|
|
|
|
|
|
|
|
|
|
if zone.Affinity != nil && zone.Affinity.PodAffinity != nil {
|
|
|
|
|
for _, elem := range zone.Affinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
podAffinityTerms = append(podAffinityTerms, parsePodAffinityTerm(&elem))
|
|
|
|
|
}
|
|
|
|
|
for _, elem := range zone.Affinity.PodAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
wAffinityTerm := &models.ZoneAffinityPodAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0{
|
|
|
|
|
Weight: swag.Int32(elem.Weight),
|
|
|
|
|
PodAffinityTerm: parsePodAffinityTerm(&elem.PodAffinityTerm),
|
|
|
|
|
}
|
|
|
|
|
weightedPodAffinityTerms = append(weightedPodAffinityTerms, wAffinityTerm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var podAffinity *models.ZoneAffinityPodAffinity
|
|
|
|
|
if len(podAffinityTerms) > 0 || len(weightedPodAffinityTerms) > 0 {
|
|
|
|
|
podAffinity = &models.ZoneAffinityPodAffinity{
|
|
|
|
|
RequiredDuringSchedulingIgnoredDuringExecution: podAffinityTerms,
|
|
|
|
|
PreferredDuringSchedulingIgnoredDuringExecution: weightedPodAffinityTerms,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse Pod Anti Affinity
|
|
|
|
|
podAntiAffinityTerms := []*models.PodAffinityTerm{}
|
|
|
|
|
weightedPodAntiAffinityTerms := []*models.ZoneAffinityPodAntiAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0{}
|
|
|
|
|
|
|
|
|
|
if zone.Affinity != nil && zone.Affinity.PodAntiAffinity != nil {
|
|
|
|
|
for _, elem := range zone.Affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
podAntiAffinityTerms = append(podAntiAffinityTerms, parsePodAffinityTerm(&elem))
|
|
|
|
|
}
|
|
|
|
|
for _, elem := range zone.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution {
|
|
|
|
|
wAffinityTerm := &models.ZoneAffinityPodAntiAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0{
|
|
|
|
|
Weight: swag.Int32(elem.Weight),
|
|
|
|
|
PodAffinityTerm: parsePodAffinityTerm(&elem.PodAffinityTerm),
|
|
|
|
|
}
|
|
|
|
|
weightedPodAntiAffinityTerms = append(weightedPodAntiAffinityTerms, wAffinityTerm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var podAntiAffinity *models.ZoneAffinityPodAntiAffinity
|
|
|
|
|
if len(podAntiAffinityTerms) > 0 || len(weightedPodAntiAffinityTerms) > 0 {
|
|
|
|
|
podAntiAffinity = &models.ZoneAffinityPodAntiAffinity{
|
|
|
|
|
RequiredDuringSchedulingIgnoredDuringExecution: podAntiAffinityTerms,
|
|
|
|
|
PreferredDuringSchedulingIgnoredDuringExecution: weightedPodAntiAffinityTerms,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// build affinity object
|
|
|
|
|
var affinity *models.ZoneAffinity
|
|
|
|
|
if nodeAffinity != nil || podAffinity != nil || podAntiAffinity != nil {
|
|
|
|
|
affinity = &models.ZoneAffinity{
|
|
|
|
|
NodeAffinity: nodeAffinity,
|
|
|
|
|
PodAffinity: podAffinity,
|
|
|
|
|
PodAntiAffinity: podAntiAffinity,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse tolerations
|
|
|
|
|
var tolerations models.ZoneTolerations
|
|
|
|
|
for _, elem := range zone.Tolerations {
|
2020-08-07 20:00:16 -07:00
|
|
|
var tolerationSecs *models.ZoneTolerationSeconds
|
|
|
|
|
if elem.TolerationSeconds != nil {
|
|
|
|
|
tolerationSecs = &models.ZoneTolerationSeconds{
|
|
|
|
|
Seconds: elem.TolerationSeconds,
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-29 01:01:17 -07:00
|
|
|
toleration := &models.ZoneTolerationsItems0{
|
|
|
|
|
Key: elem.Key,
|
|
|
|
|
Operator: string(elem.Operator),
|
|
|
|
|
Value: elem.Value,
|
|
|
|
|
Effect: string(elem.Effect),
|
2020-08-07 20:00:16 -07:00
|
|
|
TolerationSeconds: tolerationSecs,
|
2020-07-29 01:01:17 -07:00
|
|
|
}
|
|
|
|
|
tolerations = append(tolerations, toleration)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zoneModel := &models.Zone{
|
|
|
|
|
Name: zone.Name,
|
|
|
|
|
Servers: swag.Int64(int64(zone.Servers)),
|
|
|
|
|
VolumesPerServer: swag.Int32(zone.VolumesPerServer),
|
|
|
|
|
VolumeConfiguration: &models.ZoneVolumeConfiguration{
|
|
|
|
|
Size: size,
|
|
|
|
|
StorageClassName: storageClassName,
|
|
|
|
|
},
|
|
|
|
|
NodeSelector: zone.NodeSelector,
|
|
|
|
|
Resources: resources,
|
|
|
|
|
Affinity: affinity,
|
|
|
|
|
Tolerations: tolerations,
|
|
|
|
|
}
|
|
|
|
|
return zoneModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parsePodAffinityTerm(term *corev1.PodAffinityTerm) *models.PodAffinityTerm {
|
|
|
|
|
labelMatchExpressions := []*models.PodAffinityTermLabelSelectorMatchExpressionsItems0{}
|
|
|
|
|
for _, exp := range term.LabelSelector.MatchExpressions {
|
|
|
|
|
labelSelectorReq := &models.PodAffinityTermLabelSelectorMatchExpressionsItems0{
|
|
|
|
|
Key: swag.String(exp.Key),
|
|
|
|
|
Operator: swag.String(string(exp.Operator)),
|
|
|
|
|
Values: exp.Values,
|
|
|
|
|
}
|
|
|
|
|
labelMatchExpressions = append(labelMatchExpressions, labelSelectorReq)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
podAffinityTerm := &models.PodAffinityTerm{
|
|
|
|
|
LabelSelector: &models.PodAffinityTermLabelSelector{
|
|
|
|
|
MatchExpressions: labelMatchExpressions,
|
|
|
|
|
MatchLabels: term.LabelSelector.MatchLabels,
|
|
|
|
|
},
|
|
|
|
|
Namespaces: term.Namespaces,
|
|
|
|
|
TopologyKey: swag.String(term.TopologyKey),
|
|
|
|
|
}
|
|
|
|
|
return podAffinityTerm
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseNodeSelectorTerm(term *corev1.NodeSelectorTerm) *models.NodeSelectorTerm {
|
|
|
|
|
var t models.NodeSelectorTerm
|
|
|
|
|
for _, matchExpression := range term.MatchExpressions {
|
|
|
|
|
matchExp := &models.NodeSelectorTermMatchExpressionsItems0{
|
|
|
|
|
Key: swag.String(matchExpression.Key),
|
|
|
|
|
Operator: swag.String(string(matchExpression.Operator)),
|
|
|
|
|
Values: matchExpression.Values,
|
|
|
|
|
}
|
|
|
|
|
t.MatchExpressions = append(t.MatchExpressions, matchExp)
|
|
|
|
|
}
|
|
|
|
|
for _, matchField := range term.MatchFields {
|
|
|
|
|
matchF := &models.NodeSelectorTermMatchFieldsItems0{
|
|
|
|
|
Key: swag.String(matchField.Key),
|
|
|
|
|
Operator: swag.String(string(matchField.Operator)),
|
|
|
|
|
Values: matchField.Values,
|
|
|
|
|
}
|
|
|
|
|
t.MatchFields = append(t.MatchFields, matchF)
|
|
|
|
|
}
|
|
|
|
|
return &t
|
|
|
|
|
}
|
2020-08-07 20:23:03 -07:00
|
|
|
|
2020-09-04 20:32:57 -07:00
|
|
|
func getTenantUpdateZoneResponse(session *models.Principal, params admin_api.TenantUpdateZonesParams) (*models.Tenant, *models.Error) {
|
2020-08-26 17:12:59 -07:00
|
|
|
ctx := context.Background()
|
|
|
|
|
opClientClientSet, err := cluster.OperatorClient(session.SessionToken)
|
|
|
|
|
if err != nil {
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-08-26 17:12:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opClient := &operatorClient{
|
|
|
|
|
client: opClientClientSet,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t, err := updateTenantZones(ctx, opClient, params.Namespace, params.Tenant, params.Body.Zones)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println("error updating Tenant's zones:", err)
|
2020-09-04 20:32:57 -07:00
|
|
|
return nil, prepareError(err)
|
2020-08-26 17:12:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse it to models.Tenant
|
|
|
|
|
tenant := getTenantInfo(t)
|
|
|
|
|
return tenant, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// updateTenantZones Sets the Tenant's zones to the ones provided by the request
|
|
|
|
|
//
|
|
|
|
|
// It does the equivalent to a PUT request on Tenant's zones
|
|
|
|
|
func updateTenantZones(
|
|
|
|
|
ctx context.Context,
|
2020-09-03 10:20:58 -07:00
|
|
|
operatorClient OperatorClientI,
|
2020-08-26 17:12:59 -07:00
|
|
|
namespace string,
|
|
|
|
|
tenantName string,
|
|
|
|
|
zonesReq []*models.Zone) (*operator.Tenant, error) {
|
|
|
|
|
|
|
|
|
|
minInst, err := operatorClient.TenantGet(ctx, namespace, tenantName, metav1.GetOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if minInst.Spec.Metadata == nil {
|
|
|
|
|
minInst.Spec.Metadata = &metav1.ObjectMeta{
|
|
|
|
|
Annotations: map[string]string{},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set the zones if they are provided
|
|
|
|
|
var newZoneArray []operator.Zone
|
|
|
|
|
for _, zone := range zonesReq {
|
|
|
|
|
zone, err := parseTenantZoneRequest(zone, minInst.Spec.Metadata.Annotations)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
newZoneArray = append(newZoneArray, *zone)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// replace zones array
|
|
|
|
|
minInst.Spec.Zones = newZoneArray
|
|
|
|
|
|
|
|
|
|
payloadBytes, err := json.Marshal(minInst)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
tenantUpdated, err := operatorClient.TenantPatch(ctx, namespace, minInst.Name, types.MergePatchType, payloadBytes, metav1.PatchOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return tenantUpdated, nil
|
|
|
|
|
}
|