Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from labring:main #673

Merged
merged 142 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
7268c17
Fix doc platform-components relative link. (#4896)
zzjin Jul 15, 2024
d1193f7
fix: bg file ext (#4895)
zijiren233 Jul 15, 2024
26604f9
opt: desktop default config (#4876)
zijiren233 Jul 15, 2024
d2ea1ed
refactor: enhance i18n type annotations for better developer experien…
zjy365 Jul 16, 2024
4a36317
fix: update work order status to pending (#4899)
zjy365 Jul 16, 2024
4fd0ebc
feat: use dumb-init as the init system for Docker container (#4901)
zjy365 Jul 17, 2024
e9087cf
dep: upgrade controllers client-go and controller-runtime (#4898)
lingdie Jul 18, 2024
e292b84
update:dbprovider Pause Hint message (#4902)
zjy365 Jul 19, 2024
2baac37
update:docs announcementBar (#4906)
zjy365 Jul 19, 2024
e210fd8
fix:update copywriting (#4905)
xudaotutou Jul 19, 2024
c1d447f
fix: download exit and status_code check (#4908)
zijiren233 Jul 19, 2024
ee997b2
Remove registry with no more needed. (#4910)
zzjin Jul 19, 2024
3d4b3fe
feat: Add .gitignore file and i18n.md documentation (#4911)
zjy365 Jul 19, 2024
d59fd4a
change svc version to 1.22 (#4916)
bxy4543 Jul 22, 2024
a541722
i18n: update i18n for template provider (#4917)
yangchuansheng Jul 22, 2024
95c5a7d
feat: resource quota add object storage size (#4874)
nowinkeyy Jul 22, 2024
a284f3b
Doc: update video (#4915)
zuoFeng59556 Jul 22, 2024
80c052f
refactor: improve i18n in dbprovider for better developer experience …
zjy365 Jul 23, 2024
9468f7f
Forward compatibility terminal label. (#4921)
zzjin Jul 23, 2024
3127c81
Replace gomail/gomail with wneessen/go-mail in email mail utility (#4…
wneessen Jul 24, 2024
93c5a9a
docs:update scripts (#4925)
zjy365 Jul 25, 2024
86823ab
fix: db quota check (#4927)
zijiren233 Jul 26, 2024
d2cfd46
update:desktop add scripts & workorder closedBy (#4928)
zjy365 Jul 26, 2024
1d82b3f
rollback email package (#4929)
bxy4543 Jul 29, 2024
73c3919
fix read notice cause panic (#4930)
bxy4543 Jul 30, 2024
9a7bcba
feat(desktop): add realname auth (#4931)
HUAHUAI23 Jul 31, 2024
f488b6f
Fix: Resolve bug introduced by launchpad JSON patching (#4935)
zjy365 Jul 31, 2024
fa8ba1e
feat:dbprovider support reconfigure (#4926)
zjy365 Aug 1, 2024
c544506
update self-deployment (#4938)
bearslyricattack Aug 1, 2024
ce47655
fix: desktop right-click menu issue (#4939)
zjy365 Aug 2, 2024
8c21c37
fix(desktop) add phone number bind logic to realname auth (#4940)
HUAHUAI23 Aug 2, 2024
738bd0b
fix: load env before fetching app details in launchpad (#4943)
zjy365 Aug 5, 2024
0109752
fix(desktop): fix realname auth multi notify (#4944)
HUAHUAI23 Aug 6, 2024
594f3af
CostCenter api update (#4932)
bxy4543 Aug 6, 2024
1fe875a
feat: add desktop tooltip for improved user experience (#4945)
zjy365 Aug 6, 2024
eb83860
feat:launchpad update container status reason (#4947)
zjy365 Aug 7, 2024
f4be739
Add pausing kb cluster database in namespace controller & fix get cos…
bxy4543 Aug 8, 2024
f54fc3a
feat(desktop): add signup user sem info (#4949)
HUAHUAI23 Aug 9, 2024
3515cdb
perf(desktop): reduce network traffic overhead (#4948)
zjy365 Aug 9, 2024
9caf45a
feat:docs add 's' parameter for user source tracking (#4958)
zjy365 Aug 12, 2024
525b4dd
Update feishu notification (#4920)
wallyxjh Aug 12, 2024
04d823c
feat(template): add translations for app content (#4961)
zjy365 Aug 13, 2024
b75c85f
fix(docs):header title translation (#4963)
zjy365 Aug 13, 2024
e2f66e5
DB backup monitoring (#4950)
bxy4543 Aug 13, 2024
331229e
fix flow error (#4964)
nowinkeyy Aug 14, 2024
83be88a
fix(launchpad): file upload in Kubernetes pods (#4970)
zjy365 Aug 14, 2024
9e2faf9
Patch kb addon (#4969)
wallyxjh Aug 14, 2024
6c82972
fix: check control plane count of master IPs (#4972)
cbluebird Aug 15, 2024
62a290d
fix: add return in PROMPTS_EN/PROMPTS_CN (#4974)
cbluebird Aug 15, 2024
20bf7a5
feat: support tagging launchpad and database application sources (#4975)
zjy365 Aug 15, 2024
3d0f964
feat(desktop): adjust the style of real-name authentication (#4979)
HUAHUAI23 Aug 16, 2024
d32471d
feat:launchpad && database add cost tip (#4980)
zjy365 Aug 16, 2024
dd2ac20
feat(docs): add SEM keywords parameter (#4981)
zjy365 Aug 20, 2024
3f63432
feat(desktop): signup user sem data add keyword data (#4983)
HUAHUAI23 Aug 20, 2024
cca4da9
feat: get os traffic from minio (#4968)
nowinkeyy Aug 20, 2024
ae37ede
build: add Husky and lint-staged for code formatting (#4982)
zjy365 Aug 21, 2024
0549a9a
Update db backup (#4976)
wallyxjh Aug 21, 2024
bd3f6d4
feat: templates support conditional rendering (#4937)
zijiren233 Aug 21, 2024
132eb38
add backuprepo (#4986)
wallyxjh Aug 21, 2024
a42f12a
add backuprepo (#4989)
wallyxjh Aug 21, 2024
5d6fab9
fix: defaults and inputs maybe empty (#4987)
zijiren233 Aug 21, 2024
1faf9d6
feat: add support for launching creation page in launchpad (#4984)
zjy365 Aug 22, 2024
7f8ff72
add dify installation QA (#4991)
wallyxjh Aug 22, 2024
f4bb39d
feat:desktop update sem (#4993)
zjy365 Aug 23, 2024
2882add
Feat/invoice (#4988)
bxy4543 Aug 23, 2024
e8d6271
styles(objectstorage): fix styles (#4959)
xudaotutou Aug 24, 2024
086681e
add devbox proposal (#4900)
fanux Aug 24, 2024
c69a460
fix: template undefined value (#4992)
zijiren233 Aug 24, 2024
a3c9c55
add devbox controller. (#4999)
lingdie Aug 27, 2024
fd6733e
set AutomountServiceAccountToken to false (#5001)
lingdie Aug 27, 2024
2bf0773
fix(desktop):fix init database error (#5003)
xudaotutou Aug 27, 2024
80f4682
feat(desktop): Implement smart dock behavior (#4998)
zjy365 Aug 28, 2024
3c418c3
optimize get app cost with index(owner+order_id) (#5002)
bxy4543 Aug 28, 2024
e91f227
Optimize/payment (#5000)
bxy4543 Aug 28, 2024
31471d7
Update costcenter (#4990)
xudaotutou Aug 28, 2024
06caa81
update cpu/mem usage (#5006)
wallyxjh Aug 28, 2024
5877ddb
add generate public and private key (#5004)
bearslyricattack Aug 29, 2024
7e77b7a
add devbox controller rbac, enable in ci to build docker images (#5009)
lingdie Aug 29, 2024
9e3327a
update cpu/mem usage (#5008)
wallyxjh Aug 29, 2024
e52f5d3
add devbox pod hostname set to devbox name (#5015)
lingdie Aug 30, 2024
d58375e
add devbox restart pod (#5010)
bearslyricattack Aug 30, 2024
54c0180
feat: cost quota and price (#5014)
zijiren233 Aug 30, 2024
b2f0445
update launchpad cpu/mem usage (#5016)
wallyxjh Aug 30, 2024
8a6844f
feat(account-service): add use giftcode (#5013)
HUAHUAI23 Aug 30, 2024
d2eb60c
update devbox to add delete resource. (#5017)
lingdie Aug 30, 2024
e3c9b62
add default rbac rules for devbox runtime and runtime class. (#5012)
lingdie Aug 31, 2024
3d62549
add additionalPrinterColumns for devbox. (#5020)
lingdie Aug 31, 2024
35c1c56
change label location (#5022)
bearslyricattack Sep 2, 2024
ba66b04
fix: resolve desktop monitoring issue (#5019)
zjy365 Sep 2, 2024
569bcfd
add extraEnv toleration affinity,ephemeral-storage limit (#5023)
bearslyricattack Sep 2, 2024
022e1a0
feat: support user external domain (#5021)
zijiren233 Sep 2, 2024
5d1d9ba
change runtime and runtime class to namespace scope, improve devbox c…
lingdie Sep 2, 2024
1122146
refactor:Fetch Launchpad pricing from service API (#5025)
zjy365 Sep 2, 2024
68c0244
feat(costcenter): add gift code (#5026)
HUAHUAI23 Sep 3, 2024
306bbda
add devbox controller rbac. (#5028)
lingdie Sep 3, 2024
4e13ab5
fix devbox get runtime. (#5030)
lingdie Sep 3, 2024
17601ae
5.0.0 New document (#5032)
bearslyricattack Sep 3, 2024
980e796
add devbox default runtime ref namespace to devbox-system. (#5034)
lingdie Sep 4, 2024
7d882d0
add logs for CheckPodConsistency. (#5035)
lingdie Sep 4, 2024
a7a7cac
fix: signup with password donot save kc (#5036)
zijiren233 Sep 4, 2024
95ce6b8
fix ssh volume bug (#5039)
bearslyricattack Sep 5, 2024
8eef22e
fix: switch pod logs (#5040)
zijiren233 Sep 5, 2024
9ca435c
feat: add SEO TDK support and pricebox to template (#5038)
zjy365 Sep 5, 2024
0ed0635
add devbox phase and controller (#5042)
bearslyricattack Sep 5, 2024
4a17349
add devbox node and containerId (#5045)
bearslyricattack Sep 5, 2024
4ec1134
fix: adjust GPU quota for launchpad (#5041)
zjy365 Sep 6, 2024
e4e5702
add random (#5050)
bearslyricattack Sep 6, 2024
7e6cb8b
Monitor api adapt token (#5049)
bxy4543 Sep 6, 2024
8ad51bc
update launchpad test (#5044)
wallyxjh Sep 6, 2024
60c4065
add service port (#5048)
bearslyricattack Sep 6, 2024
bab49b7
feat: applaunchpad log previous (#5047)
zijiren233 Sep 6, 2024
47001c9
fix release bug (#5051)
bearslyricattack Sep 6, 2024
7091b86
feat: user private ns invite (#5043)
zijiren233 Sep 9, 2024
4fabfc9
update launchpad single (#5052)
wallyxjh Sep 9, 2024
d47170c
add release old tag (#5053)
bearslyricattack Sep 9, 2024
b03274c
remove pod finalizer (#5060)
bearslyricattack Sep 10, 2024
e334705
bump format go version (#5062)
bxy4543 Sep 10, 2024
b4ee7b8
feat: add Kafka and Milvus connection string support (#5061)
zjy365 Sep 10, 2024
22e4ff2
refactor(desktop): refactor delete (#5055)
xudaotutou Sep 10, 2024
97939b5
fix: log stream cannot be used with jsonRes after flushHeader (#5064)
zijiren233 Sep 11, 2024
dbca6f0
feat: acmedns (#5063)
zijiren233 Sep 11, 2024
e10a76e
Add terminate ns, skip notifications for abnormal users, set default.…
bxy4543 Sep 11, 2024
7a19c64
upgrade devbox runtime crd, rewrite devbox controller. (#5066)
lingdie Sep 11, 2024
6647429
fix webhook (#5068)
bxy4543 Sep 12, 2024
1decf9a
Fix devbox podPhase logic and license in deploy.yaml.tmpl (#5067)
lingdie Sep 12, 2024
e91bce9
fix:permission change check for launchpad (#5072)
zjy365 Sep 12, 2024
456aaaf
Region amount api (#5070)
bxy4543 Sep 12, 2024
932cd71
feat(objectstorage): web host add history router support (#5076)
HUAHUAI23 Sep 12, 2024
79b0cae
feat(applaunchpad): Improve domain handling for legacy and new domain…
zjy365 Sep 13, 2024
d36fa02
fix:launchpad resource update in checkPermission API (#5077)
zjy365 Sep 13, 2024
6338cf8
feat: db log (#5069)
zijiren233 Sep 13, 2024
bf2fe19
Devbox runtime support release command and args (#5078)
lingdie Sep 13, 2024
7ef586d
WIP: Replace `ingress-nginx` with `higress`. (#4831)
zzjin Sep 13, 2024
4e95958
fix(objectstorage): Fix site hosting errors for domains (#5082)
HUAHUAI23 Sep 14, 2024
fad8188
feat: launchpad implement URL query to form data conversion (#5081)
zjy365 Sep 18, 2024
6507e53
add devbox monitor (#5086)
bxy4543 Sep 18, 2024
0f6d5cd
fix env render with app images (#5079)
bxy4543 Sep 18, 2024
febe93b
fix: improve timezone handling in Kubernetes pods (#5087)
zjy365 Sep 19, 2024
570c1a0
update (#5075)
nowinkeyy Sep 19, 2024
52a1e82
Update costcenter (#5085)
xudaotutou Sep 19, 2024
c23bad8
Fix/get invoice payment (#5088)
bxy4543 Sep 19, 2024
bcb8ab4
add LastTerminatedState and improve squash logic for devbox. (#5080)
lingdie Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/check-format-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
- "CHANGELOG/**"
env:
# Common versions
GO_VERSION: "1.20"
GO_VERSION: "1.23"

jobs:
format-code:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
- { name: job-heartbeat, path: job/heartbeat }
- { name: resources, path: resources }
- { name: node, path: node }
- { name: devbox, path: devbox}
- { name: objectstorage, path: objectstorage }
steps:
- name: Checkout
Expand Down Expand Up @@ -201,6 +202,7 @@ jobs:
- { name: job-heartbeat, path: job/heartbeat }
- { name: resources, path: resources }
- { name: node, path: node }
- { name: devbox, path: devbox }
- { name: objectstorage, path: objectstorage }
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ on:
- "!**/*.yaml"
env:
# Common versions
GO_VERSION: "1.20"
GO_VERSION: "1.22"
DEFAULT_OWNER: "labring"
CRYPTOKEY: ${{ secrets.CONTROLLER_BUILD_CRYPTOKEY }}

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tmp
**/.DS_Store
node_modules
vendor
.vscode/
pkg/registry/save/testdata/registry
.dummy.report.md
deploy/cloud/tars
.vscode/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ A Cloud Operating System designed for managing cloud-native applications

</div>

https://github.com/labring/sealos/assets/82700206/b1f8a25a-55cf-4d15-a47b-38cf7d507134
https://github.com/user-attachments/assets/a7b7ed5c-0e31-4158-8a76-3b161ed70a70

<p align="center">
<a href="https://sealos.io/docs/Intro">Docs</a> |
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

</div>

https://github.com/labring/sealos/assets/82700206/b1f8a25a-55cf-4d15-a47b-38cf7d507134
https://github.com/user-attachments/assets/a7b7ed5c-0e31-4158-8a76-3b161ed70a70

<p align="center">
<a href="https://sealos.run/docs/Intro">文档</a> |
Expand Down
8 changes: 5 additions & 3 deletions controllers/account/api/v1/debt_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ var DefaultDebtConfig = map[DebtStatusType]int64{
const DebtNamespaceAnnoStatusKey = "debt.sealos/status"

const (
NormalDebtNamespaceAnnoStatus = "Normal"
SuspendDebtNamespaceAnnoStatus = "Suspend"
ResumeDebtNamespaceAnnoStatus = "Resume"
NormalDebtNamespaceAnnoStatus = "Normal"
SuspendDebtNamespaceAnnoStatus = "Suspend"
ResumeDebtNamespaceAnnoStatus = "Resume"
TerminateSuspendDebtNamespaceAnnoStatus = "TerminateSuspend"
)

// DebtSpec defines the desired state of Debt
type DebtSpec struct {
UserName string `json:"userName,omitempty"`
UserID string `json:"userID,omitempty"`
}

// DebtStatus defines the observed state of Debt
Expand Down
5 changes: 4 additions & 1 deletion controllers/account/api/v1/debt_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ func (d *DebtValidate) Handle(ctx context.Context, req admission.Request) admiss
return admission.ValidationResponse(true, "")
}
// is user sa
if !strings.HasPrefix(g, saPrefix+":ns-") {
if !strings.HasPrefix(g, saPrefix+":user-system") {
continue
}
if strings.Contains(req.UserInfo.Username, "user-controller-manager") {
break
}
if isWhiteList(req) {
return admission.ValidationResponse(true, "")
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/account/api/v1/payment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type PaymentSpec struct {

// UserID is the user id who want to recharge
UserID string `json:"userID,omitempty"`
// UserCr is the user cr name who want to recharge
UserCR string `json:"userCR,omitempty"`
// Amount is the amount of recharge
Amount int64 `json:"amount,omitempty"`
// e.g. wechat, alipay, creditcard, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ spec:
properties:
userName:
type: string
userID:
type: string
type: object
status:
description: DebtStatus defines the observed state of Debt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ spec:
userID:
description: UserID is the user id who want to recharge
type: string
userCR:
description: UserCr is the user cr name who want to recharge
type: string
type: object
status:
description: PaymentStatus defines the observed state of Payment
Expand Down
208 changes: 44 additions & 164 deletions controllers/account/controllers/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (

accountv1 "github.com/labring/sealos/controllers/account/api/v1"
"github.com/labring/sealos/controllers/pkg/database"
"github.com/labring/sealos/controllers/pkg/pay"
"github.com/labring/sealos/controllers/pkg/resources"
pkgtypes "github.com/labring/sealos/controllers/pkg/types"
"github.com/labring/sealos/controllers/pkg/utils/env"
Expand All @@ -58,8 +57,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"
)

const (
Expand Down Expand Up @@ -98,11 +95,6 @@ type AccountReconciler struct {
//+kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;update;patch;delete

func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
//It should not stop the normal process for the failure to delete the payment
// delete payments that exist for more than 5 minutes
if err := r.DeletePayment(ctx); err != nil {
r.Logger.Error(err, "delete payment failed")
}
user := &userv1.User{}
owner := ""
if err := r.Get(ctx, client.ObjectKey{Namespace: req.Namespace, Name: req.Name}, user); err == nil {
Expand All @@ -113,82 +105,14 @@ func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
// determine the resource quota created by the owner user and the resource quota initialized by the account user,
// and only the resource quota created by the team user
_, err = r.syncAccount(ctx, owner, "ns-"+user.Name)
if errors.Is(err, gorm.ErrRecordNotFound) && user.CreationTimestamp.Add(20*24*time.Hour).Before(time.Now()) {
return ctrl.Result{}, nil
}
return ctrl.Result{}, err
} else if client.IgnoreNotFound(err) != nil {
return ctrl.Result{}, err
}

payment := &accountv1.Payment{}
if err := r.Get(ctx, client.ObjectKey{Namespace: req.Namespace, Name: req.Name}, payment); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
if payment.Spec.UserID == "" || payment.Spec.Amount == 0 {
return ctrl.Result{}, fmt.Errorf("payment is invalid: %v", payment)
}
if payment.Status.TradeNO == "" {
return ctrl.Result{Requeue: true, RequeueAfter: time.Millisecond * 300}, nil
}
if payment.Status.Status == pay.PaymentSuccess {
return ctrl.Result{}, nil
}

account, err := r.syncAccount(ctx, getUsername(payment.Spec.UserID), payment.Namespace)
if err != nil {
return ctrl.Result{}, fmt.Errorf("get account failed: %v", err)
}

// get payment handler
payHandler, err := pay.NewPayHandler(payment.Spec.PaymentMethod)
if err != nil {
r.Logger.Error(err, "get payment handler failed")
return ctrl.Result{}, err
}
// get payment details(status, amount)
// TODO The GetPaymentDetails may cause issues when using Stripe
status, orderAmount, err := payHandler.GetPaymentDetails(payment.Status.TradeNO)
if err != nil {
return ctrl.Result{}, fmt.Errorf("query order failed: %v", err)
}
r.Logger.V(1).Info("query order details", "orderStatus", status, "orderAmount", orderAmount)
switch status {
case pay.PaymentSuccess:
//1¥ = 100WechatPayAmount; 1 WechatPayAmount = 10000 SealosAmount
payAmount := orderAmount * 10000
gift, err := r.getAmountWithRates(payAmount, account)
if err != nil {
r.Logger.Error(err, "get gift error")
}
if err = r.AccountV2.Payment(&pkgtypes.Payment{
PaymentRaw: pkgtypes.PaymentRaw{
UserUID: account.UserUID,
Amount: payAmount,
Gift: gift,
CreatedAt: payment.CreationTimestamp.Time,
RegionUserOwner: owner,
Method: payment.Spec.PaymentMethod,
TradeNO: payment.Status.TradeNO,
CodeURL: payment.Status.CodeURL,
},
}); err != nil {
r.Logger.Error(err, "save payment failed", "payment", payment)
return ctrl.Result{}, nil
}
payment.Status.Status = pay.PaymentSuccess
if err := r.Status().Update(ctx, payment); err != nil {
return ctrl.Result{}, fmt.Errorf("update payment failed: %v", err)
}

case pay.PaymentProcessing, pay.PaymentNotPaid:
return ctrl.Result{Requeue: true, RequeueAfter: time.Second}, nil
case pay.PaymentFailed, pay.PaymentExpired:
if err := r.Delete(ctx, payment); err != nil {
return ctrl.Result{}, fmt.Errorf("delete payment failed: %v", err)
}
return ctrl.Result{}, nil
default:
return ctrl.Result{}, fmt.Errorf("unknown status: %v", err)
}

return ctrl.Result{}, nil
}

Expand All @@ -204,10 +128,7 @@ func (r *AccountReconciler) syncAccount(ctx context.Context, owner string, userN
}
account, err := r.AccountV2.NewAccount(&pkgtypes.UserQueryOpts{Owner: owner})
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, fmt.Errorf("failed to create %s account: %v", owner, err)
return nil, err
}
return account, nil
}
Expand Down Expand Up @@ -245,53 +166,12 @@ func (r *AccountReconciler) adaptEphemeralStorageLimitRange(ctx context.Context,
})
}

// DeletePayment delete payments that exist for more than 5 minutes
func (r *AccountReconciler) DeletePayment(ctx context.Context) error {
payments := &accountv1.PaymentList{}
err := r.List(ctx, payments)
if err != nil {
return err
}
for _, payment := range payments.Items {
//get payment handler
payHandler, err := pay.NewPayHandler(payment.Spec.PaymentMethod)
if err != nil {
r.Logger.Error(err, "get payment handler failed")
return err
}
//delete payment if it is exist for more than 5 minutes
if time.Since(payment.CreationTimestamp.Time) > time.Minute*5 {
if payment.Status.TradeNO != "" {
status, amount, err := payHandler.GetPaymentDetails(payment.Status.TradeNO)
if err != nil {
r.Logger.Error(err, "get payment details failed")
}
if status == pay.PaymentSuccess {
if payment.Status.Status != pay.PaymentSuccess {
continue
}
r.Logger.Info("payment success, post delete payment cr", "payment", payment, "amount", amount)
}
// expire session
if err = payHandler.ExpireSession(payment.Status.TradeNO); err != nil {
r.Logger.Error(err, "cancel payment failed")
}
}
if err := r.Delete(ctx, &payment); err != nil {
return err
}
}
}
return nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *AccountReconciler) SetupWithManager(mgr ctrl.Manager, rateOpts controller.Options) error {
r.Logger = ctrl.Log.WithName("account_controller")
r.AccountSystemNamespace = env.GetEnvWithDefault(ACCOUNTNAMESPACEENV, DEFAULTACCOUNTNAMESPACE)
return ctrl.NewControllerManagedBy(mgr).
For(&userv1.User{}, builder.WithPredicates(OnlyCreatePredicate{})).
Watches(&source.Kind{Type: &accountv1.Payment{}}, &handler.EnqueueRequestForObject{}).
WithOptions(rateOpts).
Complete(r)
}
Expand Down Expand Up @@ -352,49 +232,49 @@ func parseConfigList(s string, list interface{}, configName string) error {
return nil
}

func GetUserOwner(user *userv1.User) string {
own := user.Annotations[userv1.UserAnnotationOwnerKey]
if own == "" {
return user.Name
}
return own
}
//func GetUserOwner(user *userv1.User) string {
// own := user.Annotations[userv1.UserAnnotationOwnerKey]
// if own == "" {
// return user.Name
// }
// return own
//}

const BaseUnit = 1_000_000

func (r *AccountReconciler) getAmountWithRates(amount int64, account *pkgtypes.Account) (amt int64, err error) {
//userActivities, err := pkgtypes.ParseUserActivities(account.Annotations)
//if err != nil {
// return nil, 0, fmt.Errorf("parse user activities failed: %w", err)
//}
//
//rechargeDiscount := pkgtypes.RechargeDiscount{
// DiscountSteps: r.RechargeStep,
// DiscountRates: r.RechargeRatio,
//}
//if len(userActivities) > 0 {
// if activityType, phase, _ := pkgtypes.GetUserActivityDiscount(r.Activities, &userActivities); phase != nil {
// if len(phase.RechargeDiscount.DiscountSteps) > 0 {
// rechargeDiscount.DiscountSteps = phase.RechargeDiscount.DiscountSteps
// rechargeDiscount.DiscountRates = phase.RechargeDiscount.DiscountRates
// }
// rechargeDiscount.SpecialDiscount = phase.RechargeDiscount.SpecialDiscount
// rechargeDiscount = phase.RechargeDiscount
// currentPhase := userActivities[activityType].Phases[userActivities[activityType].CurrentPhase]
// anno = pkgtypes.SetUserPhaseRechargeTimes(account.Annotations, activityType, currentPhase.Name, currentPhase.RechargeNums+1)
// }
//}
//return anno, getAmountWithDiscount(amount, rechargeDiscount), nil

discount, err := r.AccountV2.GetUserAccountRechargeDiscount(&pkgtypes.UserQueryOpts{UID: account.UserUID})
if err != nil {
return 0, fmt.Errorf("get user %s account recharge discount failed: %w", account.UserUID, err)
}
if discount == nil || discount.DiscountSteps == nil || discount.DiscountRates == nil {
return getAmountWithDiscount(amount, r.DefaultDiscount), nil
}
return getAmountWithDiscount(amount, *discount), nil
}
//func (r *AccountReconciler) getAmountWithRates(amount int64, account *pkgtypes.Account) (amt int64, err error) {
// //userActivities, err := pkgtypes.ParseUserActivities(account.Annotations)
// //if err != nil {
// // return nil, 0, fmt.Errorf("parse user activities failed: %w", err)
// //}
// //
// //rechargeDiscount := pkgtypes.RechargeDiscount{
// // DiscountSteps: r.RechargeStep,
// // DiscountRates: r.RechargeRatio,
// //}
// //if len(userActivities) > 0 {
// // if activityType, phase, _ := pkgtypes.GetUserActivityDiscount(r.Activities, &userActivities); phase != nil {
// // if len(phase.RechargeDiscount.DiscountSteps) > 0 {
// // rechargeDiscount.DiscountSteps = phase.RechargeDiscount.DiscountSteps
// // rechargeDiscount.DiscountRates = phase.RechargeDiscount.DiscountRates
// // }
// // rechargeDiscount.SpecialDiscount = phase.RechargeDiscount.SpecialDiscount
// // rechargeDiscount = phase.RechargeDiscount
// // currentPhase := userActivities[activityType].Phases[userActivities[activityType].CurrentPhase]
// // anno = pkgtypes.SetUserPhaseRechargeTimes(account.Annotations, activityType, currentPhase.Name, currentPhase.RechargeNums+1)
// // }
// //}
// //return anno, getAmountWithDiscount(amount, rechargeDiscount), nil
//
// discount, err := r.AccountV2.GetUserAccountRechargeDiscount(&pkgtypes.UserQueryOpts{UID: account.UserUID})
// if err != nil {
// return 0, fmt.Errorf("get user %s account recharge discount failed: %w", account.UserUID, err)
// }
// if discount == nil || discount.DiscountSteps == nil || discount.DiscountRates == nil {
// return getAmountWithDiscount(amount, r.DefaultDiscount), nil
// }
// return getAmountWithDiscount(amount, *discount), nil
//}

func getAmountWithDiscount(amount int64, discount pkgtypes.RechargeDiscount) int64 {
if discount.SpecialDiscount != nil && discount.SpecialDiscount[amount/BaseUnit] != 0 {
Expand Down
Loading
Loading