diff --git a/pkg/cloudscale/objectstorage.go b/pkg/cloudscale/objectstorage.go index c5a150f..834710a 100644 --- a/pkg/cloudscale/objectstorage.go +++ b/pkg/cloudscale/objectstorage.go @@ -28,6 +28,7 @@ type ObjectStorage struct { controlApiClient k8s.Client salesOrder string clusterId string + cloudZone string uomMapping map[string]string } @@ -35,13 +36,14 @@ const ( namespaceLabel = "crossplane.io/claim-namespace" ) -func NewObjectStorage(client *cloudscale.Client, k8sClient k8s.Client, controlApiClient k8s.Client, salesOrder, clusterId string, uomMapping map[string]string) (*ObjectStorage, error) { +func NewObjectStorage(client *cloudscale.Client, k8sClient k8s.Client, controlApiClient k8s.Client, salesOrder, clusterId string, cloudZone string, uomMapping map[string]string) (*ObjectStorage, error) { return &ObjectStorage{ client: client, k8sClient: k8sClient, controlApiClient: controlApiClient, salesOrder: salesOrder, clusterId: clusterId, + cloudZone: cloudZone, uomMapping: uomMapping, }, nil } @@ -125,9 +127,9 @@ func (o *ObjectStorage) createOdooRecord(bucketMetricsData cloudscale.BucketMetr itemGroup := "" if appuioManaged { - itemGroup = fmt.Sprintf("APPUiO Managed - Zone: %s / Namespace: %s", o.clusterId, b.Namespace) + itemGroup = fmt.Sprintf("APPUiO Managed - Cluster: %s / Namespace: %s", o.clusterId, b.Namespace) } else { - itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", o.clusterId, b.Namespace) + itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", o.cloudZone, b.Namespace) } instanceId := fmt.Sprintf("%s/%s", b.Zone, bucketMetricsData.Subject.BucketName) diff --git a/pkg/cmd/cloudscale.go b/pkg/cmd/cloudscale.go index 56c2eb7..3470e0d 100644 --- a/pkg/cmd/cloudscale.go +++ b/pkg/cmd/cloudscale.go @@ -34,6 +34,7 @@ func CloudscaleCmds() *cli.Command { odooClientSecret string salesOrder string clusterId string + cloudZone string uom string ) return &cli.Command{ @@ -62,6 +63,8 @@ func CloudscaleCmds() *cli.Command { EnvVars: []string{"APPUIO_MANAGED_SALES_ORDER"}, Destination: &salesOrder, Required: false, DefaultText: defaultTextForOptionalFlags}, &cli.StringFlag{Name: "cluster-id", Usage: "The cluster id to save in the billing record", EnvVars: []string{"CLUSTER_ID"}, Destination: &clusterId, Required: true, DefaultText: defaultTextForRequiredFlags}, + &cli.StringFlag{Name: "cluster-zone", Usage: "The cluster zone to save in the billing record", + EnvVars: []string{"CLOUD_ZONE"}, Destination: &cloudZone, Required: false, DefaultText: defaultTextForOptionalFlags}, &cli.StringFlag{Name: "uom", Usage: "Unit of measure mapping between cloud services and Odoo16 in json format", EnvVars: []string{"UOM"}, Destination: &uom, Required: true, DefaultText: defaultTextForRequiredFlags}, &cli.IntFlag{Name: "collect-interval", Usage: "How often to collect the metrics from the Cloud Service in hours - 1-23", @@ -106,7 +109,7 @@ func CloudscaleCmds() *cli.Command { return fmt.Errorf("load loaction: %w", err) } - o, err := cs.NewObjectStorage(cloudscaleClient, k8sClient, k8sControlClient, salesOrder, clusterId, mapping) + o, err := cs.NewObjectStorage(cloudscaleClient, k8sClient, k8sControlClient, salesOrder, clusterId, cloudZone, mapping) if err != nil { return fmt.Errorf("object storage: %w", err) } diff --git a/pkg/cmd/exoscale.go b/pkg/cmd/exoscale.go index 2ac7eab..bb8c6b4 100644 --- a/pkg/cmd/exoscale.go +++ b/pkg/cmd/exoscale.go @@ -32,6 +32,7 @@ func ExoscaleCmds() *cli.Command { odooClientSecret string salesOrder string clusterId string + cloudZone string uom string // For dbaas in minutes // For objectstorage in hours @@ -69,6 +70,8 @@ func ExoscaleCmds() *cli.Command { EnvVars: []string{"BILLING_HOUR"}, Destination: &billingHour, Required: false, DefaultText: defaultTextForOptionalFlags}, &cli.StringFlag{Name: "cluster-id", Usage: "The cluster id to save in the billing record", EnvVars: []string{"CLUSTER_ID"}, Destination: &clusterId, Required: true, DefaultText: defaultTextForRequiredFlags}, + &cli.StringFlag{Name: "cluster-zone", Usage: "The cluster zone to save in the billing record", + EnvVars: []string{"CLOUD_ZONE"}, Destination: &cloudZone, Required: false, DefaultText: defaultTextForOptionalFlags}, &cli.StringFlag{Name: "uom", Usage: "Unit of measure mapping between cloud services and Odoo16 in json format", EnvVars: []string{"UOM"}, Destination: &uom, Required: true, DefaultText: defaultTextForRequiredFlags}, }, @@ -116,7 +119,7 @@ func ExoscaleCmds() *cli.Command { collectInterval = 23 } - o, err := exoscale.NewObjectStorage(exoscaleClient, k8sClient, k8sControlClient, salesOrder, clusterId, mapping) + o, err := exoscale.NewObjectStorage(exoscaleClient, k8sClient, k8sControlClient, salesOrder, clusterId, cloudZone, mapping) if err != nil { return fmt.Errorf("objectbucket service: %w", err) } @@ -196,7 +199,7 @@ func ExoscaleCmds() *cli.Command { collectInterval = 1 } - d, err := exoscale.NewDBaaS(exoscaleClient, k8sClient, k8sControlClient, collectInterval, salesOrder, clusterId, mapping) + d, err := exoscale.NewDBaaS(exoscaleClient, k8sClient, k8sControlClient, collectInterval, salesOrder, clusterId, cloudZone, mapping) if err != nil { return fmt.Errorf("dbaas service: %w", err) } diff --git a/pkg/exoscale/dbaas.go b/pkg/exoscale/dbaas.go index 92dfeb5..1201e85 100644 --- a/pkg/exoscale/dbaas.go +++ b/pkg/exoscale/dbaas.go @@ -68,18 +68,20 @@ type DBaaS struct { controlApiClient k8s.Client salesOrder string clusterId string + cloudZone string collectInterval int uomMapping map[string]string } // NewDBaaS creates a Service with the initial setup -func NewDBaaS(exoscaleClient *egoscale.Client, k8sClient k8s.Client, controlApiClient k8s.Client, collectInterval int, salesOrder, clusterId string, uomMapping map[string]string) (*DBaaS, error) { +func NewDBaaS(exoscaleClient *egoscale.Client, k8sClient k8s.Client, controlApiClient k8s.Client, collectInterval int, salesOrder, clusterId string, cloudZone string, uomMapping map[string]string) (*DBaaS, error) { return &DBaaS{ exoscaleClient: exoscaleClient, k8sClient: k8sClient, controlApiClient: controlApiClient, salesOrder: salesOrder, clusterId: clusterId, + cloudZone: cloudZone, collectInterval: collectInterval, uomMapping: uomMapping, }, nil @@ -207,11 +209,11 @@ 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) + itemGroup := fmt.Sprintf("APPUiO Managed - Cluster: %s / Namespace: %s", ds.clusterId, dbaasDetail.Namespace) instanceId := fmt.Sprintf("%s/%s", dbaasDetail.Zone, dbaasDetail.DBName) salesOrder := ds.salesOrder if salesOrder == "" { - itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", ds.clusterId, dbaasDetail.Namespace) + itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", ds.cloudZone, dbaasDetail.Namespace) 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) diff --git a/pkg/exoscale/dbaas_test.go b/pkg/exoscale/dbaas_test.go index 33066b5..6e8bd87 100644 --- a/pkg/exoscale/dbaas_test.go +++ b/pkg/exoscale/dbaas_test.go @@ -22,7 +22,7 @@ func TestDBaaS_aggregatedDBaaS(t *testing.T) { ProductID: "appcat-exoscale-pg-hobbyist-2", InstanceID: "ch-gva-2/postgres-abc", ItemDescription: "Exoscale DBaaS PostgreSQL", - ItemGroupDescription: "APPUiO Managed - Zone: c-test1 / Namespace: vshn-xyz", + ItemGroupDescription: "APPUiO Managed - Cluster: c-test1 / Namespace: vshn-xyz", SalesOrder: "1234", UnitID: "", ConsumedUnits: 1, @@ -35,7 +35,7 @@ func TestDBaaS_aggregatedDBaaS(t *testing.T) { ProductID: "appcat-exoscale-pg-business-128", InstanceID: "ch-gva-2/postgres-def", ItemDescription: "Exoscale DBaaS PostgreSQL", - ItemGroupDescription: "APPUiO Managed - Zone: c-test1 / Namespace: vshn-uvw", + ItemGroupDescription: "APPUiO Managed - Cluster: c-test1 / Namespace: vshn-uvw", SalesOrder: "1234", UnitID: "", ConsumedUnits: 1, diff --git a/pkg/exoscale/objectstorage.go b/pkg/exoscale/objectstorage.go index 6fc17ac..8ef5104 100644 --- a/pkg/exoscale/objectstorage.go +++ b/pkg/exoscale/objectstorage.go @@ -26,6 +26,7 @@ type ObjectStorage struct { controlApiClient k8s.Client salesOrder string clusterId string + cloudZone string uomMapping map[string]string } @@ -35,13 +36,14 @@ type BucketDetail struct { } // NewObjectStorage creates an ObjectStorage with the initial setup -func NewObjectStorage(exoscaleClient *egoscale.Client, k8sClient k8s.Client, controlApiClient k8s.Client, salesOrder, clusterId string, uomMapping map[string]string) (*ObjectStorage, error) { +func NewObjectStorage(exoscaleClient *egoscale.Client, k8sClient k8s.Client, controlApiClient k8s.Client, salesOrder, clusterId string, cloudZone string, uomMapping map[string]string) (*ObjectStorage, error) { return &ObjectStorage{ k8sClient: k8sClient, exoscaleClient: exoscaleClient, controlApiClient: controlApiClient, salesOrder: salesOrder, clusterId: clusterId, + cloudZone: cloudZone, uomMapping: uomMapping, }, nil } @@ -110,11 +112,11 @@ func (o *ObjectStorage) getOdooMeteredBillingRecords(ctx context.Context, sosBuc return nil, err } - itemGroup := fmt.Sprintf("APPUiO Managed - Zone: %s / Namespace: %s", o.clusterId, bucketDetail.Namespace) + itemGroup := fmt.Sprintf("APPUiO Managed - Cluster: %s / Namespace: %s", o.clusterId, bucketDetail.Namespace) instanceId := fmt.Sprintf("%s/%s", bucketDetail.Zone, bucketDetail.BucketName) salesOrder := o.salesOrder if salesOrder == "" { - itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", o.clusterId, bucketDetail.Namespace) + itemGroup = fmt.Sprintf("APPUiO Cloud - Zone: %s / Namespace: %s", o.cloudZone, bucketDetail.Namespace) salesOrder, err = controlAPI.GetSalesOrder(ctx, o.controlApiClient, bucketDetail.Organization) if err != nil { logger.Error(err, "unable to sync bucket", "namespace", bucketDetail.Namespace)