Set annotations and labels at Tenant level (#279)
on Tenant Creation request api
This commit is contained in:
@@ -72,6 +72,9 @@ type CreateTenantRequest struct {
|
||||
// image registry
|
||||
ImageRegistry *ImageRegistry `json:"image_registry,omitempty"`
|
||||
|
||||
// labels
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
|
||||
// mounth path
|
||||
MounthPath string `json:"mounth_path,omitempty"`
|
||||
|
||||
|
||||
@@ -207,6 +207,9 @@ func (m *Zone) UnmarshalBinary(b []byte) error {
|
||||
// swagger:model ZoneVolumeConfiguration
|
||||
type ZoneVolumeConfiguration struct {
|
||||
|
||||
// annotations
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
|
||||
// labels
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
|
||||
|
||||
@@ -293,12 +293,6 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
|
||||
consoleImage = tenant.Spec.Console.Image
|
||||
}
|
||||
|
||||
if tenant.Spec.Metadata == nil {
|
||||
tenant.Spec.Metadata = &metav1.ObjectMeta{
|
||||
Annotations: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
return &models.Tenant{
|
||||
CreationDate: tenant.ObjectMeta.CreationTimestamp.String(),
|
||||
DeletionDate: deletion,
|
||||
@@ -309,7 +303,7 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
|
||||
Namespace: tenant.ObjectMeta.Namespace,
|
||||
Image: tenant.Spec.Image,
|
||||
ConsoleImage: consoleImage,
|
||||
EnablePrometheus: isPrometheusEnabled(tenant.Spec.Metadata.Annotations),
|
||||
EnablePrometheus: isPrometheusEnabled(tenant.Annotations),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +501,8 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
|
||||
//Construct a MinIO Instance with everything we are getting from parameters
|
||||
minInst := operator.Tenant{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: tenantName,
|
||||
Name: tenantName,
|
||||
Labels: tenantReq.Labels,
|
||||
},
|
||||
Spec: operator.TenantSpec{
|
||||
Image: minioImage,
|
||||
@@ -698,18 +693,14 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
|
||||
}
|
||||
// add annotations
|
||||
var annotations map[string]string
|
||||
if minInst.Spec.Metadata == nil {
|
||||
minInst.Spec.Metadata = &metav1.ObjectMeta{
|
||||
Annotations: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
if len(tenantReq.Annotations) > 0 {
|
||||
annotations = tenantReq.Annotations
|
||||
minInst.Spec.Metadata.Annotations = annotations
|
||||
minInst.Annotations = annotations
|
||||
}
|
||||
// set the zones if they are provided
|
||||
for _, zone := range tenantReq.Zones {
|
||||
zone, err := parseTenantZoneRequest(zone, annotations)
|
||||
zone, err := parseTenantZoneRequest(zone)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
@@ -737,10 +728,10 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
|
||||
}
|
||||
|
||||
// prometheus annotations support
|
||||
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Spec.Metadata != nil && minInst.Spec.Metadata.Annotations != nil {
|
||||
minInst.Spec.Metadata.Annotations[prometheusPath] = "/minio/prometheus/metrics"
|
||||
minInst.Spec.Metadata.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
|
||||
minInst.Spec.Metadata.Annotations[prometheusScrape] = "true"
|
||||
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Annotations != nil {
|
||||
minInst.Annotations[prometheusPath] = "/minio/prometheus/metrics"
|
||||
minInst.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
|
||||
minInst.Annotations[prometheusScrape] = "true"
|
||||
}
|
||||
|
||||
// set console image if provided
|
||||
@@ -875,12 +866,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
|
||||
}
|
||||
|
||||
// Prometheus Annotations
|
||||
if minInst.Spec.Metadata == nil {
|
||||
minInst.Spec.Metadata = &metav1.ObjectMeta{
|
||||
Annotations: map[string]string{},
|
||||
}
|
||||
}
|
||||
currentAnnotations := minInst.Spec.Metadata.Annotations
|
||||
currentAnnotations := minInst.Annotations
|
||||
prometheusAnnotations := map[string]string{
|
||||
prometheusPath: "/minio/prometheus/metrics",
|
||||
prometheusPort: fmt.Sprint(operator.MinIOPort),
|
||||
@@ -888,7 +874,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
|
||||
}
|
||||
if params.Body.EnablePrometheus && minInst.Spec.Metadata != nil && currentAnnotations != nil {
|
||||
// add prometheus annotations to the tenant
|
||||
minInst.Spec.Metadata.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
|
||||
minInst.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
|
||||
// add prometheus annotations to the each zone
|
||||
if minInst.Spec.Zones != nil {
|
||||
for _, zone := range minInst.Spec.Zones {
|
||||
@@ -898,7 +884,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
|
||||
}
|
||||
} else {
|
||||
// remove prometheus annotations to the tenant
|
||||
minInst.Spec.Metadata.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
|
||||
minInst.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
|
||||
// add prometheus annotations from each zone
|
||||
if minInst.Spec.Zones != nil {
|
||||
for _, zone := range minInst.Spec.Zones {
|
||||
@@ -974,7 +960,7 @@ func addTenantZone(ctx context.Context, operatorClient OperatorClientI, params a
|
||||
}
|
||||
|
||||
zoneParams := params.Body
|
||||
zone, err := parseTenantZoneRequest(zoneParams, tenant.ObjectMeta.Annotations)
|
||||
zone, err := parseTenantZoneRequest(zoneParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1062,7 +1048,7 @@ func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenan
|
||||
|
||||
// parseTenantZoneRequest parse zone request and returns the equivalent
|
||||
// operator.Zone object
|
||||
func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]string) (*operator.Zone, error) {
|
||||
func parseTenantZoneRequest(zoneParams *models.Zone) (*operator.Zone, error) {
|
||||
if zoneParams.VolumeConfiguration == nil {
|
||||
return nil, errors.New("a volume configuration must be specified")
|
||||
}
|
||||
@@ -1211,14 +1197,12 @@ func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]stri
|
||||
// Pass annotations to the volume
|
||||
vct := &corev1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "data",
|
||||
Labels: zoneParams.VolumeConfiguration.Labels,
|
||||
Name: "data",
|
||||
Labels: zoneParams.VolumeConfiguration.Labels,
|
||||
Annotations: zoneParams.VolumeConfiguration.Annotations,
|
||||
},
|
||||
Spec: volTemp,
|
||||
}
|
||||
if len(annotations) > 0 {
|
||||
vct.ObjectMeta.Annotations = annotations
|
||||
}
|
||||
|
||||
zone := &operator.Zone{
|
||||
Name: zoneParams.Name,
|
||||
@@ -1512,16 +1496,10 @@ func updateTenantZones(
|
||||
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)
|
||||
zone, err := parseTenantZoneRequest(zone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -331,6 +331,11 @@ func Test_TenantInfo(t *testing.T) {
|
||||
Name: "tenant1",
|
||||
Namespace: "minio-ns",
|
||||
DeletionTimestamp: &testTimeStamp,
|
||||
Annotations: map[string]string{
|
||||
prometheusPath: "some/path",
|
||||
prometheusPort: "other/path",
|
||||
prometheusScrape: "other/path",
|
||||
},
|
||||
},
|
||||
Spec: operator.TenantSpec{
|
||||
Zones: []operator.Zone{
|
||||
@@ -351,13 +356,6 @@ func Test_TenantInfo(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
|
||||
Metadata: &metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
prometheusPath: "some/path",
|
||||
prometheusPort: "other/path",
|
||||
prometheusScrape: "other/path",
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: operator.TenantStatus{
|
||||
CurrentState: "ready",
|
||||
@@ -396,16 +394,14 @@ func Test_TenantInfo(t *testing.T) {
|
||||
CreationTimestamp: testTimeStamp,
|
||||
Name: "tenant1",
|
||||
Namespace: "minio-ns",
|
||||
Annotations: map[string]string{
|
||||
prometheusPath: "some/path",
|
||||
prometheusScrape: "other/path",
|
||||
},
|
||||
},
|
||||
Spec: operator.TenantSpec{
|
||||
Zones: []operator.Zone{},
|
||||
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
|
||||
Metadata: &metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
prometheusPath: "some/path",
|
||||
prometheusScrape: "other/path",
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: operator.TenantStatus{
|
||||
CurrentState: "ready",
|
||||
@@ -430,16 +426,14 @@ func Test_TenantInfo(t *testing.T) {
|
||||
CreationTimestamp: testTimeStamp,
|
||||
Name: "tenant1",
|
||||
Namespace: "minio-ns",
|
||||
Annotations: map[string]string{
|
||||
prometheusPath: "some/path",
|
||||
prometheusScrape: "other/path",
|
||||
},
|
||||
},
|
||||
Spec: operator.TenantSpec{
|
||||
Zones: []operator.Zone{},
|
||||
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
|
||||
Metadata: &metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
prometheusPath: "some/path",
|
||||
prometheusScrape: "other/path",
|
||||
},
|
||||
},
|
||||
Console: &operator.ConsoleConfiguration{
|
||||
Image: "minio/console:master",
|
||||
},
|
||||
|
||||
@@ -2226,6 +2226,12 @@ func init() {
|
||||
"image_registry": {
|
||||
"$ref": "#/definitions/imageRegistry"
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"mounth_path": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -3438,6 +3444,12 @@ func init() {
|
||||
"size"
|
||||
],
|
||||
"properties": {
|
||||
"annotations": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
@@ -6089,6 +6101,12 @@ func init() {
|
||||
"size"
|
||||
],
|
||||
"properties": {
|
||||
"annotations": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
@@ -6382,6 +6400,12 @@ func init() {
|
||||
"image_registry": {
|
||||
"$ref": "#/definitions/imageRegistry"
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"mounth_path": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -7528,6 +7552,12 @@ func init() {
|
||||
"size"
|
||||
],
|
||||
"properties": {
|
||||
"annotations": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
|
||||
34
swagger.yml
34
swagger.yml
@@ -1148,7 +1148,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
put:
|
||||
put:
|
||||
summary: Tenant Update Zones
|
||||
operationId: TenantUpdateZones
|
||||
parameters:
|
||||
@@ -1282,7 +1282,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
|
||||
/cluster/max-allocatable-memory:
|
||||
get:
|
||||
summary: Get maximum allocatable memory for given number of nodes
|
||||
@@ -1908,7 +1908,7 @@ definitions:
|
||||
type: string
|
||||
enable_prometheus:
|
||||
type: boolean
|
||||
|
||||
|
||||
imageRegistry:
|
||||
type: object
|
||||
required:
|
||||
@@ -1922,7 +1922,7 @@ definitions:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
|
||||
|
||||
createTenantRequest:
|
||||
type: object
|
||||
required:
|
||||
@@ -1966,6 +1966,10 @@ definitions:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
labels:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
image_registry:
|
||||
$ref: "#/definitions/imageRegistry"
|
||||
image_pull_secret:
|
||||
@@ -2213,6 +2217,10 @@ definitions:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
annotations:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
resources:
|
||||
$ref: "#/definitions/zoneResources"
|
||||
node_selector:
|
||||
@@ -2263,14 +2271,14 @@ definitions:
|
||||
type: string
|
||||
type: object
|
||||
type: array
|
||||
|
||||
|
||||
zoneTolerationSeconds:
|
||||
description: TolerationSeconds represents the period of
|
||||
time the toleration (which must be of effect NoExecute,
|
||||
otherwise this field is ignored) tolerates the taint.
|
||||
By default, it is not set, which means tolerate the taint
|
||||
forever (do not evict). Zero and negative values will
|
||||
be treated as 0 (evict immediately) by the system.
|
||||
time the toleration (which must be of effect NoExecute,
|
||||
otherwise this field is ignored) tolerates the taint.
|
||||
By default, it is not set, which means tolerate the taint
|
||||
forever (do not evict). Zero and negative values will
|
||||
be treated as 0 (evict immediately) by the system.
|
||||
type: object
|
||||
required:
|
||||
- seconds
|
||||
@@ -2646,13 +2654,13 @@ definitions:
|
||||
used:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
|
||||
deleteTenantRequest:
|
||||
type: object
|
||||
properties:
|
||||
delete_pvcs:
|
||||
type: boolean
|
||||
|
||||
|
||||
zoneUpdateRequest:
|
||||
type: object
|
||||
required:
|
||||
@@ -2662,7 +2670,7 @@ definitions:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/zone"
|
||||
|
||||
|
||||
maxAllocatableMemResponse:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
Reference in New Issue
Block a user