Skip to content

Commit

Permalink
feat billing with app/type/ns (#3963)
Browse files Browse the repository at this point in the history
* feat billing with app/type/ns

* optimize transfer saver && delete accountbalance cr

* init billingInfoquery crd to replace namespaceshistory, costcenter query

* add deploy.yaml.tmpl query crd

* query with order_id

* set resources.DefaultPropertyTypeLS
  • Loading branch information
bxy4543 authored Sep 22, 2023
1 parent c8aaeb7 commit 07abd93
Show file tree
Hide file tree
Showing 32 changed files with 1,854 additions and 962 deletions.
17 changes: 9 additions & 8 deletions controllers/account/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ resources:
kind: Payment
path: github.com/labring/sealos/controllers/account/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
domain: sealos.io
group: account
kind: AccountBalance
path: github.com/labring/sealos/controllers/account/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
Expand Down Expand Up @@ -92,4 +84,13 @@ resources:
kind: NamespaceBillingHistory
path: github.com/labring/sealos/controllers/account/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: sealos.io
group: account
kind: BillingInfoQuery
path: github.com/labring/sealos/controllers/account/api/v1
version: v1
version: "3"
27 changes: 24 additions & 3 deletions controllers/account/api/v1/account_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ import (
)

const (
ChargeStatusCharging = "charging"
ChargeStatusClosed = "closed"
ChargeStatusTimeOUT = "timeout"
AccountSystemNamespaceEnv = "ACCOUNT_SYSTEM_NAMESPACE"
)

type (
Status string
Type int
)

const (
// Consumption 消费
Consumption Type = iota
// Recharge 充值
Recharge
TransferIn
TransferOut
)

const QueryAllType Type = -1

const (
Completed Status = "completed"
Create Status = "create"
Failed Status = "failed"
)

type Costs map[string]int64

const (
Name = "name"
Owner = "owner"
Expand Down
92 changes: 0 additions & 92 deletions controllers/account/api/v1/accountbalance_types.go

This file was deleted.

78 changes: 78 additions & 0 deletions controllers/account/api/v1/billinginfoquery_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
QueryTypeNamespacesHistory = "NamespacesHistory"
QueryTypeProperties = "Properties"
QueryTypeAppType = "AppType"
)

// BillingInfoQuerySpec defines the desired state of BillingInfoQuery
type BillingInfoQuerySpec struct {
QueryType string `json:"queryType"`
Args map[string]string `json:"args,omitempty"`
}

// BillingInfoQueryStatus defines the observed state of BillingInfoQuery
type BillingInfoQueryStatus struct {
Result string `json:"result"`
Status Status `json:"status"`
StatusDetails string `json:"statusDetails"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// BillingInfoQuery is the Schema for the billinginfoqueries API
type BillingInfoQuery struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BillingInfoQuerySpec `json:"spec,omitempty"`
Status BillingInfoQueryStatus `json:"status,omitempty"`
}

type BillingPropertiesForQuery struct {
}

type PropertyQuery struct {
Name string `json:"name" bson:"name"`
Alias string `json:"alias" bson:"alias"`
UnitPrice int64 `json:"unit_price" bson:"unit_price"`
Unit string `json:"unit" bson:"unit"`
}

//+kubebuilder:object:root=true

// BillingInfoQueryList contains a list of BillingInfoQuery
type BillingInfoQueryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BillingInfoQuery `json:"items"`
}

func init() {
SchemeBuilder.Register(&BillingInfoQuery{}, &BillingInfoQueryList{})
}
28 changes: 22 additions & 6 deletions controllers/account/api/v1/billingrecordquery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,34 @@ type BillingRecordQuerySpec struct {
EndTime metav1.Time `json:"endTime"`
OrderID string `json:"orderID,omitempty"`
Type Type `json:"type"`
AppType string `json:"appType,omitempty"`
}

// BillingRecordQueryStatus defines the observed state of BillingRecordQuery
type BillingRecordQueryStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
TotalCount int `json:"totalCount"`
PageLength int `json:"pageLength"`
RechargeAmount int64 `json:"rechargeAmount"`
DeductionAmount Costs `json:"deductionAmount,omitempty"`
Items []AccountBalanceSpec `json:"item,omitempty"`
Status string `json:"status"`
TotalCount int `json:"totalCount"`
PageLength int `json:"pageLength"`
RechargeAmount int64 `json:"rechargeAmount"`
DeductionAmount Costs `json:"deductionAmount,omitempty"`
Items []BillingRecordQueryItem `json:"item,omitempty"`
Status string `json:"status"`
}

type BillingRecordQueryItem struct {
Time metav1.Time `json:"time" bson:"time"`
BillingRecordQueryItemInline `json:",inline"`
}

type BillingRecordQueryItemInline struct {
Name string `json:"name,omitempty" bson:"name,omitempty"`
OrderID string `json:"order_id" bson:"order_id"`
Namespace string `json:"namespace,omitempty" bson:"namespace,omitempty"`
Type Type `json:"type" bson:"type"`
AppType string `json:"appType,omitempty" bson:"appType,omitempty"`
Costs Costs `json:"costs,omitempty" bson:"costs,omitempty"`
Amount int64 `json:"amount,omitempty" bson:"amount"`
}

//+kubebuilder:object:root=true
Expand Down
Loading

0 comments on commit 07abd93

Please sign in to comment.