Skip to content

Commit

Permalink
[pull] main from labring:main (#673)
Browse files Browse the repository at this point in the history
* Fix doc platform-components relative link. (labring#4896)

* fix: bg file ext (labring#4895)

* opt: desktop default config (labring#4876)

* opt: desktop default config

link: frontend/desktop/data/config.yaml:26

* opt: docsurl

* refactor: enhance i18n type annotations for better developer experience (labring#4878)

* refactor: enhance i18n type annotations for better developer experience

* desktop done

* fix build

* delete script

* fix launchpad ci

* delete file

* update

* delete appname as I18nCommonKey

* update

* fix: update work order status to pending (labring#4899)

* fix: update work order status to pending

* add description

* feat: use dumb-init as the init system for Docker container (labring#4901)

* feat: use dumb-init as the init system for Docker container

* add account center

* update pause_message

* dep: upgrade controllers client-go and controller-runtime (labring#4898)

* dep: upgrade user controller client-go version and fix kc reconcile when delete secret.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade terminal controller client-go version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade resource controller client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade objectstorage controller client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade node controller client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade license controller client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade jobs client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade db/adminer client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* dep: upgrade account,app controller client-go and ctrl-runtime version.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* do go mod tidy in job/init.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* fix terminal cache.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* fix adminer cache.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* fix app main.go.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* run go mod tidy in controllers.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* fix license check.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* fix type is not found error in node-ctr

* fix type is not found in account-ctr

* fix

* fix account go lint.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* fix resource controller go lint.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* restore test files.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

* delete useless admin label const.
Signed-off-by: yy <[email protected]>

Signed-off-by: yy <[email protected]>

---------

Signed-off-by: yy <[email protected]>
Co-authored-by: xuziyi <[email protected]>

* update:dbprovider Pause Hint message (labring#4902)

* update:dbprovider Pause Hint message

* fix notifications

* fix guide

* update workorder

* fix

* update:docs announcementBar (labring#4906)

* fix:update copywriting (labring#4905)

* fix: download exit and status_code check (labring#4908)

* Remove registry with no more needed. (labring#4910)

Signed-off-by: zzjin <[email protected]>

* feat: Add .gitignore file and i18n.md documentation (labring#4911)

* change svc version to 1.22 (labring#4916)

change svc version to 1.22

change svc version to 1.22

change svc version to 1.22

change svc version to 1.22

change svc version to 1.22

* i18n: update i18n for template provider (labring#4917)

Signed-off-by: Carson Yang <[email protected]>

* feat: resource quota add object storage size (labring#4874)

* resource quota add object storage size

* Doc: update video (labring#4915)

* Doc: update video

* doc:update video url

* refactor: improve i18n in dbprovider for better developer experience  (labring#4919)

* refactor: improve i18n in dbprovider for better developer experience

Signed-off-by: jingyang <[email protected]>

* delete unuserd keys

* update keys

* update

* update

* update quota

---------

Signed-off-by: jingyang <[email protected]>

* Forward compatibility terminal label. (labring#4921)

Signed-off-by: zzjin <[email protected]>

* Replace gomail/gomail with wneessen/go-mail in email mail utility (labring#4867)

The gomail/gomail library was replaced with the go-mail library for sending emails. This change involved updating the go.mod, go.sum, and email.go files. The email.go changes include a new method of setting TO and FROM addresses, and a new way to dial and send the email. This switch to go-mail provides better error handling and more customization options.

Co-authored-by: Jiahui <[email protected]>

* docs:update scripts (labring#4925)

* docs:update scripts

* update

* fix: db quota check (labring#4927)

* update:desktop add scripts & workorder closedBy (labring#4928)

* rollback email package (labring#4929)

* fix read notice cause panic (labring#4930)

* feat(desktop): add realname auth (labring#4931)

* feat(desktop): add realname auth

* i8n

* chore

* chore

* Fix: Resolve bug introduced by launchpad JSON patching (labring#4935)

Signed-off-by: jingyang <[email protected]>

* feat:dbprovider support reconfigure (labring#4926)

* feat:dbprovider support reconfigure

Signed-off-by: jingyang <[email protected]>

* done

* update

* update status

* add status & fix pgsql

* delete log

* second_edition

* add image

* fix

* update styles

* update

* update

* add Divider

---------

Signed-off-by: jingyang <[email protected]>

* update self-deployment (labring#4938)

* fix: desktop right-click menu issue (labring#4939)

* fix: desktop right-click menu issue

* update self-hosting

* update

* add i18n

* update bd_vid

* fix(desktop) add phone number bind logic to realname auth (labring#4940)

* fix(desktop): add bind phone number logic for realname auth

* chore

* chore

* chore

* chore

* chore

* chore

* fix: load env before fetching app details in launchpad (labring#4943)

* fix(desktop): fix realname auth multi notify (labring#4944)

* fix(desktop): fix realname auth multi notify

* ok

* ok

* CostCenter api update (labring#4932)

* optimize monitoring app store

* add get app instance role

* add app instance billing

* add test

* fix

* add CheckPermission with kc

* add get-regions api

* change regions to slice

* add GetCostAppList GetCostOverview api

* fix check-auth user

* fix divisor to zero

* fix get cost overview

* add app type list api

* add init region info

* fix docs get cost app type list

* add service account ingress

* add check region auth

* fix region auth

* add skip tls client get api

* add debug mod

* add basic cost distribution api

* remove deprecated encrypt account field

* set default time range

* add GetAppCostTimeRange api

* add dao test

* make format && fix semgrep ci

* make format && fix semgrep ci

* fix GetCostAppList

* optimize account reconcile

* ignore user not found

* add used_amount result for get app cost

* Ignore that a user is not created for a long time, cause a lot of errors

* add app cost sort with time

* optimize cost app api

* optimize cost app api

* optimize cost app api

* optimize cost app api

* get namespace id and name

* remove debug print

* remove debug print

* terminal named by `app.kubernetes.io/part-of` label

* feat: add desktop tooltip for improved user experience (labring#4945)

* feat:add desktop tooltip

* persist the state of the appbar

* delete

* feat:launchpad update container status reason (labring#4947)

* update container status reason

* update color

* update uploadConvertData

* fix mock app

* Add pausing kb cluster database in namespace controller & fix get cost api  (labring#4946)

* fix panic

* add stop cluster for debt

* fix GetConsumptionAmount api

* go mod tidy for controller

* feat(desktop): add signup user sem info (labring#4949)

* feat(desktop): add signup user sem info

* fix sql

* perf(desktop): reduce network traffic overhead (labring#4948)

* perf(desktop): reduce network traffic overhead

* update

* update db color

* fix getBilling api

* update template

* update

* menu

* update ts

* update open objectstorage

* feat:docs add 's' parameter for user source tracking (labring#4958)

* Update feishu notification (labring#4920)

* update kafka monitor

* update feishu notification

* feat(template): add translations for app content (labring#4961)

* feat:add translations for app content

* update

* fix(docs):header title translation (labring#4963)

* DB backup monitoring (labring#4950)

* optimize database backup monitor

* Because the obtained objectstorage traffic includes traffic communicating with the controller, filter out traffic smaller than 1 MB

* add to schema

* add backup clusterrole

* fix db backup named

* fix flow error (labring#4964)

* fix(launchpad): file upload in Kubernetes pods (labring#4970)

* fix upload file

* fix upload

* Patch kb addon (labring#4969)

* update kafka monitor

* enable kb addons

* fix: check control plane count of master IPs (labring#4972)

* fix: add return in PROMPTS_EN/PROMPTS_CN (labring#4974)

* feat: support tagging launchpad and database application sources (labring#4975)

* fix desktop api getBilling

* feat:db tag

* feat:launchpad tag

* fix useTranslation

* update

* update

* feat(desktop): adjust the style of real-name authentication (labring#4979)

* feat:launchpad && database add cost tip (labring#4980)

* feat:launchpad && database add cost tip

* fix color

* feat(docs): add SEM keywords parameter (labring#4981)

* feat(desktop): signup user sem data add keyword data (labring#4983)

* feat(desktop) signup user sem data add keyword data

* ok

* feat: get os traffic from minio (labring#4968)

* get os traffic from minio

* optimize get obj traffic within the last hour

---------

Co-authored-by: jiahui <[email protected]>

* build: add Husky and lint-staged for code formatting (labring#4982)

* Update db backup (labring#4976)

* update kafka monitor

* if backup exceed 1 hour,send notification

* feat: templates support conditional rendering (labring#4937)

* feat: template support if endif exp

* opt: use heap algorithm

* feat: support else grammar

* feat: support elif grammar

* fix: use a more precise regular expression

* fix: generate yaml list need skip empty

* chore: rename and clean js-yaml import

* feat: input support if exp

* feat: input type suooprt string | number | choice | boolean

* fix: from number type use default input

* fix: checkbox

* feat: safe run expression

* feat: isolation environment

* fix: default must be string

* fix: input style

* feat: support more syntax analysis

* fix: delete force update

* fix: select default value

* chore: add repo branch to env and dataset

* fix: missing platformEnvs

* fix: debounce not working

* feat: conditional rendering across yaml lists

* fix: api v1alpha

* fix: split yaml list need use reg to match top row

* fix: show field

* fix: use callback

* fix: optimize editor and form performance

* chore: del desc

* fix: change editor localstorage name

* chore: predef evaldata

* feat: cache form

* fix: cache getTemplateValues

* fix: instance yaml missing parse description

* chore: add comment

* opt: template envs

* fix: javascript.lang.security.audit.unsafe-formatstring.unsafe-formatstring

* chore: remove unuse isEqual

* fix: ensure conditional blocks without matching else() do not render content

* fix: editor scrolling performance

* add backuprepo (labring#4986)

* add backuprepo (labring#4989)

* fix: defaults and inputs maybe empty (labring#4987)

* feat: add support for launching creation page in launchpad (labring#4984)

* feat: add support for launching creation page in launchpad

* control login methods

* add dify installation QA (labring#4991)

* feat:desktop update sem (labring#4993)

* feat:desktop update sem

* fix balance isNegative

* fix upload

* fix

* Feat/invoice (labring#4988)

* add invoice service

* styles(objectstorage): fix styles (labring#4959)

* add devbox proposal (labring#4900)

* fix: template undefined value (labring#4992)

* fix: if input iten not define default, need set empty string

* fix: parse value if undefined set empty string

* add devbox controller. (labring#4999)

* add devbox controller

* add devbox controller

* fix lint and delete useless ops controller

* fix lint and delete useless ops controller

* add license and fix fmt.

* set AutomountServiceAccountToken to false (labring#5001)

* fix(desktop):fix init database error (labring#5003)

* feat(desktop): Implement smart dock behavior (labring#4998)

* feat:app dock

* update

* update

* fix dbprovider isEdit

* optimize get app cost with index(owner+order_id) (labring#5002)

* Optimize/payment (labring#5000)

* optimize payment controller

* add backward compatible code

* fix ci

* Update costcenter (labring#4990)

* feat:update costcenter

* feat:(costcenter): bot callback

* feat:(costcenter): bot callback

* chore: clean code

* update cpu/mem usage (labring#5006)

* add generate public and private key (labring#5004)

* add generate public and private key

* add generate public and private key

* add generate public and private key

* add generate public and private key

* add generate public and private key

* add generate public and private key

* fix bug

* Changes

* Changes

* Changes

* Changes

* Changes

* add devbox controller rbac, enable in ci to build docker images (labring#5009)

* add devbox controller rbac, enable in ci to build docker images

* add devbox controller rbac, enable in ci to build docker images

* add devbox controller rbac, enable in ci to build docker images

* update cpu/mem usage (labring#5008)

* add devbox pod hostname set to devbox name (labring#5015)

* add devbox restart pod (labring#5010)


* add devbox restart pod

* feat: cost quota and price (labring#5014)

* feat: init template cost quota and price

* feat: usage

* feat: price box

* fix: checkQuotaAllow

* fix: get quota

* fix: nodeport pricea

* fix: no used code

* fix: no used code

* fix: CheckQuotaType

* fix: cannot slice number

* update launchpad cpu/mem usage (labring#5016)

* feat(account-service): add use giftcode (labring#5013)

* feat(account-service): add use giftcode

* update swagger doc and complete test

* update devbox to add delete resource. (labring#5017)

* update devbox to add delete resource.

* update devbox to add delete resource.

* add default rbac rules for devbox runtime and runtime class. (labring#5012)

* add retry logic when get service, fix rbac.

* fix license.

* add RetryOnConflict when sync pod

* add additionalPrinterColumns for devbox. (labring#5020)

* add additionalPrinterColumns for devbox.

* add ResourceVersionChangedPredicate for devbox pod change status to reconcile devbox.

* change label location (labring#5022)

* fix: resolve desktop monitoring issue (labring#5019)

* add extraEnv toleration affinity,ephemeral-storage limit (labring#5023)

* feat: support user external domain (labring#5021)

* feat: support user external domain

* fix: template deploy init templates json

* change runtime and runtime class to namespace scope, improve devbox c… (labring#5024)

* change runtime and runtime class to namespace scope, improve devbox create logic, add container configs to runtime and devbox crd.

* fix lint.

* fix format.

* fix deploy yaml.

* refactor:Fetch Launchpad pricing from service API (labring#5025)

* refactor:Fetch Launchpad pricing from service API

* update

* feat(costcenter): add gift code (labring#5026)

* ok

* ok

* add support for char -

* change status code

* add devbox controller rbac. (labring#5028)

* fix devbox get runtime. (labring#5030)

Signed-off-by: yy <[email protected]>

* 5.0.0 New document (labring#5032)

* 4.0

* 5.0 de

* 5.0

* 5

* add devbox default runtime ref namespace to devbox-system. (labring#5034)

* add devbox default runtime ref namespace to devbox-system.

Signed-off-by: yy <[email protected]>

* set default runtime image ref to self ns.

Signed-off-by: yy <[email protected]>

---------

Signed-off-by: yy <[email protected]>

* add logs for CheckPodConsistency. (labring#5035)

* add log to debug.

Signed-off-by: yy <[email protected]>

* add log to debug.

Signed-off-by: yy <[email protected]>

* add log to debug.

Signed-off-by: yy <[email protected]>

---------

Signed-off-by: yy <[email protected]>

* fix: signup with password donot save kc (labring#5036)

* fix ssh volume bug (labring#5039)

* fix: switch pod logs (labring#5040)

* feat: add SEO TDK support and pricebox to template (labring#5038)

* feat: add SEO TDK support to template

* add pricebox

* update styles

* fix quota

* fix docs ci

* fix ci

* update toast

* update Translation

* template done

* update price

* add devbox phase and controller (labring#5042)

* fix ssh volume bug

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox phase and controller

* add devbox node and containerId (labring#5045)

* add devbox node and containerId

* add devbox node and containerId

* fix: adjust GPU quota for launchpad (labring#5041)

* fix: adjust GPU quota for launchpad

* fix select style

* update launchpad

* getMonitorData

* add random (labring#5050)

* Monitor api adapt token (labring#5049)

* add get monitor api

* add account api token

* adapt token

* adapt token

* get payment with invoiced arg.

* update launchpad test (labring#5044)

* update launchpad test

* update launchpad test

* add service port (labring#5048)

* add service port

* fix bug

* fix bug

* feat: applaunchpad log previous (labring#5047)

* feat: applaunchpad support previous and sincetime

* feat: since i18n

* fix: stream prefer flush header

* fix: previous cannot prefer flush header

* feat: no_logs_for_now

* fix  release bug (labring#5051)

* feat: user private ns invite (labring#5043)

* feat: user private ns support invite

* feat: user controller

* feat: ns rename

* fix: canAbdicate

* feat: operationrequest controller cannot transfer personal workspace

* adapt old rolebinding (#73)

* replace owner reference user to bind user

* make format

---------

Co-authored-by: Jiahui <[email protected]>
Co-authored-by: jiahui <[email protected]>

* update launchpad single (labring#5052)

* add release old tag (labring#5053)

* add release old tag

* add release old tag

* add release old tag

* add release old tag

* remove pod finalizer (labring#5060)

* remove pod finalizer

* remove pod finalizer

* remove pod finalizer

* bump format go version (labring#5062)

* feat: add Kafka and Milvus connection string support (labring#5061)

* feat: add Kafka and Milvus connection string support

* update

* refactor(desktop): refactor delete (labring#5055)

* fix: log stream cannot be used with jsonRes after flushHeader (labring#5064)

* feat: acmedns (labring#5063)

* feat: acmedns

* fix: create tls secret

* fix: acmedns secret base64

* fix: pipeline b64dec

* fix: acmedns host

* chore: prompts

* fix: acmedns secret placeholder cannot b64dec

* Add terminate ns, skip notifications for abnormal users, set default.NodePort.Limit=10, adapt new user struct. (labring#5056)

* add terminate namespace with anno

* adapt account

* skip notification by abnormal users

* revert mod version

* upgrade devbox runtime crd, rewrite devbox controller. (labring#5066)

* upgrade devbox runtime crd, rewrite devbox controller.

* fix comment.

* fix license

* remove duplicate get

* fix event massage

* add new commit history if pod is not in devbox commit historys.

* fix SEALOS_DEVBOX_NAME env

* add label to devbox controller predicate

* fix go version

* fix lint

* fix webhook (labring#5068)

* Fix devbox podPhase logic and license in deploy.yaml.tmpl (labring#5067)

* fix license.

Signed-off-by: yy <[email protected]>

* fix devbox version

* fix status.

---------

Signed-off-by: yy <[email protected]>

* fix:permission change check for launchpad (labring#5072)

* update desktop billing

* add checkPermission api

* Change Location

* update

* Region amount api (labring#5070)

* get all region consumption amount

* skip tls

* fix

* feat(objectstorage): web host add history router support (labring#5076)

* feat(objectstorage): web host add history router support

* ok

* ok

* ok

* feat(applaunchpad): Improve domain handling for legacy and new domains (labring#5011)

* update docs

* feat:domain

* update

* update default

* delete log

* update default user domain

* delete get env

* fix custom

* delete log

* fix:launchpad resource update in checkPermission API (labring#5077)

* feat: db log (labring#5069)

* feat: db log previous

* fix: translate key type

* fix: remove v8 compile cache

* feat: db migrate previous log

* Devbox runtime support release command and args (labring#5078)

* add release command and args for release default commands.

* add default workingDir

* add make pre-deploy

* WIP: Replace `ingress-nginx` with `higress`. (labring#4831)

* WIP: Replace `ingress-nginx` to `higress`.

Signed-off-by: zzjin <[email protected]>

* feat: update higress version

* feat: controller autoscalling and gateway daemonset

* feat: Optimize H2 flow control buffer size

* chore: bump higress version to 2.0.0

* chore: no need to install istio

---------

Signed-off-by: zzjin <[email protected]>
Co-authored-by: zijiren233 <[email protected]>

* fix(objectstorage): Fix site hosting errors for domains (labring#5082)

* feat: launchpad implement URL query to form data conversion (labring#5081)

* feat: launchpad implement URL query to form data conversion

* add appName

* update

* fix dockerfile

* add devbox monitor (labring#5086)

* fix env render with app images (labring#5079)

* fix: improve timezone handling in Kubernetes pods (labring#5087)

* update (labring#5075)

* Update costcenter (labring#5085)

* feat(costcenter): price calculator

* perf(costcenter-frontend):auth

* Fix/get invoice payment (labring#5088)

* fix get payment with invoice arg

* remove old version verification process

* fix get transfer

* fix deploy account service in cloud scripts

* swag

* add LastTerminatedState and improve squash logic for devbox. (labring#5080)

* add LastTerminatedState for devbox.

Signed-off-by: yy <[email protected]>

* fix makefile.

Signed-off-by: yy <[email protected]>

* fix requeue.

* fix enqueue logic

* add state and rename last state

* add check pod container size

* add squash check.

---------

Signed-off-by: yy <[email protected]>

---------

Signed-off-by: yy <[email protected]>
Signed-off-by: zzjin <[email protected]>
Signed-off-by: Carson Yang <[email protected]>
Signed-off-by: jingyang <[email protected]>
Co-authored-by: zzjin <[email protected]>
Co-authored-by: zijiren <[email protected]>
Co-authored-by: jingyang <[email protected]>
Co-authored-by: yy <[email protected]>
Co-authored-by: xuziyi <[email protected]>
Co-authored-by: xudaotutou <[email protected]>
Co-authored-by: Jiahui <[email protected]>
Co-authored-by: Carson Yang <[email protected]>
Co-authored-by: 左风 <[email protected]>
Co-authored-by: Winni Neessen <[email protected]>
Co-authored-by: limbo <[email protected]>
Co-authored-by: 抒情熊 <[email protected]>
Co-authored-by: 谢金虎 <[email protected]>
Co-authored-by: BlueBird <[email protected]>
Co-authored-by: xuziyi <[email protected]>
Co-authored-by: jiahui <[email protected]>
Co-authored-by: fanux <[email protected]>
Co-authored-by: Jiahui <[email protected]>
Co-authored-by: zijiren233 <[email protected]>
  • Loading branch information
20 people authored Sep 20, 2024
1 parent 4288104 commit e601ff2
Show file tree
Hide file tree
Showing 1,867 changed files with 75,847 additions and 16,933 deletions.
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

0 comments on commit e601ff2

Please sign in to comment.