From 0ce308962ed7adad9c117f9d2a27b65300f6f114 Mon Sep 17 00:00:00 2001 From: Nicolas Bigler Date: Tue, 19 Dec 2023 15:55:16 +0100 Subject: [PATCH] f Signed-off-by: Nicolas Bigler --- pkg/exoscale/dbaas.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/exoscale/dbaas.go b/pkg/exoscale/dbaas.go index 7767081..fb4ffb1 100644 --- a/pkg/exoscale/dbaas.go +++ b/pkg/exoscale/dbaas.go @@ -46,6 +46,14 @@ var ( Kind: "KafkaList", }, } + + dbaasTypes = map[string]string{ + "pg": "PostgreSQL", + "mysql": "MySQL", + "opensearch": "OpenSearch", + "redis": "Redis", + "kafka": "Kafka", + } ) // Detail a helper structure for intermediate operations @@ -147,6 +155,7 @@ func findDBaaSDetailInNamespacesMap(ctx context.Context, resource metav1.Partial Kind: gvk.Kind, Namespace: namespace, Organization: organization, + Zone: resource.GetAnnotations()["appcat.vshn.io/cloudzone"], } logger.V(1).Info("Added namespace and organization to DBaaS", "namespace", dbaasDetail.Namespace, "organization", dbaasDetail.Organization) @@ -198,7 +207,10 @@ func (ds *DBaaS) AggregateDBaaS(ctx context.Context, exoscaleDBaaS []*egoscale.D if exists && dbaasDetail.Kind == groupVersionKinds[*dbaasUsage.Type].Kind { logger.V(1).Info("Found exoscale dbaas usage", "instance", dbaasUsage.Name, "instance created", dbaasUsage.CreatedAt) + itemGroup := fmt.Sprintf("APPUiO Managed - Zone: %s / Namespace: %s", ds.clusterId, dbaasDetail.Namespace) + instanceId := fmt.Sprintf("%s/%s", dbaasDetail.Zone, dbaasDetail.DBName) if ds.salesOrder == "" { + itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", ds.clusterId, dbaasDetail.Namespace) ds.salesOrder, err = controlAPI.GetSalesOrder(ctx, ds.controlApiClient, dbaasDetail.Organization) if err != nil { logger.Error(err, "Unable to sync DBaaS, cannot get salesOrder", "namespace", dbaasDetail.Namespace) @@ -209,9 +221,9 @@ func (ds *DBaaS) AggregateDBaaS(ctx context.Context, exoscaleDBaaS []*egoscale.D // TODO zones and namespaces? o := odoo.OdooMeteredBillingRecord{ ProductID: productIdPrefix + fmt.Sprintf("-%s-%s", *dbaasUsage.Type, *dbaasUsage.Plan), - InstanceID: dbaasDetail.DBName, - ItemDescription: "Exoscale DBaaS", - ItemGroupDescription: "AppCat Exoscale DBaaS", + InstanceID: instanceId, + ItemDescription: "Exoscale DBaaS " + dbaasTypes[*dbaasUsage.Type], + ItemGroupDescription: itemGroup, SalesOrder: ds.salesOrder, UnitID: ds.uomMapping[odoo.InstanceHour], ConsumedUnits: 1,