Skip to content

Commit 466ca55

Browse files
committed
Merge branch 'main' into feat/zod-to-openapi
2 parents abf09f8 + 20c7544 commit 466ca55

292 files changed

Lines changed: 12184 additions & 4687 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ pkg/registry/save/testdata/registry
2323
deploy/cloud/tars
2424
.vscode/
2525
/lifecycle/tools/
26+
27+
**.env*

controllers/pkg/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ require (
3939
github.com/wechatpay-apiv3/wechatpay-go v0.2.17
4040
go.mongodb.org/mongo-driver v1.12.1
4141
go.uber.org/zap v1.26.0
42-
golang.org/x/time v0.5.0
4342
gopkg.in/natefinch/lumberjack.v2 v2.2.1
4443
gopkg.in/yaml.v3 v3.0.1
4544
gorm.io/driver/postgres v1.5.4
4645
gorm.io/gorm v1.25.5
4746
k8s.io/api v0.29.0
4847
k8s.io/apimachinery v0.29.0
49-
k8s.io/client-go v12.0.0+incompatible
5048
sigs.k8s.io/controller-runtime v0.17.2
5149
)
5250

@@ -106,13 +104,15 @@ require (
106104
golang.org/x/sys v0.20.0 // indirect
107105
golang.org/x/term v0.20.0 // indirect
108106
golang.org/x/text v0.15.0 // indirect
107+
golang.org/x/time v0.5.0 // indirect
109108
google.golang.org/appengine v1.6.8 // indirect
110109
google.golang.org/protobuf v1.34.1 // indirect
111110
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
112111
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
113112
gopkg.in/inf.v0 v0.9.1 // indirect
114113
gopkg.in/ini.v1 v1.67.0 // indirect
115114
gopkg.in/yaml.v2 v2.4.0 // indirect
115+
k8s.io/client-go v12.0.0+incompatible // indirect
116116
k8s.io/klog/v2 v2.110.1 // indirect
117117
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
118118
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect

controllers/pkg/objectstorage/objectstorage.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ func QueryUserUsageAndTraffic(client *MetricsClient) (Metrics, error) {
247247
if err != nil {
248248
return nil, fmt.Errorf("failed to get bucket traffic metrics: %w", err)
249249
}
250+
251+
// Initialize a map to count the number of metrics per bucket for sent traffic
252+
bucketSentCounts := make(map[string]int)
253+
// Seed the random number generator
254+
250255
for _, bucketMetric := range bucketMetrics {
251256
if !isUsageAndTrafficBytesTargetMetric(bucketMetric.Name) {
252257
continue
@@ -279,7 +284,14 @@ func QueryUserUsageAndTraffic(client *MetricsClient) (Metrics, error) {
279284
metricData.Usage[bucket] += intValue
280285
}
281286
if bucketMetric.Name == "minio_bucket_traffic_sent_bytes" {
287+
// Skip this data point to simulate loss
288+
// if strings.HasPrefix(bucket, "961a5c2b") && rand.Intn(10) == 0 {
289+
// fmt.Printf("Simulated data loss for bucket %s, value %d\n", bucket, intValue)
290+
// continue
291+
// }
282292
metricData.Sent[bucket] += intValue
293+
// Increment the counter for this bucket
294+
bucketSentCounts[bucket]++
283295
}
284296
if bucketMetric.Name == "minio_bucket_traffic_received_bytes" {
285297
metricData.Received[bucket] += intValue
@@ -289,6 +301,22 @@ func QueryUserUsageAndTraffic(client *MetricsClient) (Metrics, error) {
289301
}
290302
}
291303

304+
// After processing all metrics, check the counts for sent traffic
305+
for user, metricData := range obMetrics {
306+
for bucket, count := range bucketSentCounts {
307+
if _, ok := metricData.Sent[bucket]; ok {
308+
if count < 4 {
309+
// Zero out if less than 4 metrics were added
310+
metricData.Sent[bucket] = -1
311+
}
312+
// if strings.HasPrefix(bucket, "961a5c2b") {
313+
// fmt.Println("bucket:", bucket, ", sent:", sent)
314+
// }
315+
}
316+
}
317+
obMetrics[user] = metricData
318+
}
319+
292320
return obMetrics, err
293321
}
294322

controllers/resources/controllers/monitor_controller.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"sync"
2626
"time"
2727

28+
v1 "github.com/labring/sealos/controllers/account/api/v1"
29+
2830
"github.com/labring/sealos/controllers/pkg/types"
2931

3032
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -260,11 +262,31 @@ func (r *MonitorReconciler) enqueueNamespacesForReconcile() {
260262
return
261263
}
262264

265+
filterNormalNamespace(namespaceList)
266+
263267
if err := r.processNamespaceList(namespaceList); err != nil {
264268
r.Logger.Error(err, "failed to process namespace", "time", time.Now().Format(time.RFC3339))
265269
}
266270
}
267271

272+
func filterNormalNamespace(namespaceList *corev1.NamespaceList) {
273+
var items []corev1.Namespace
274+
for i := range namespaceList.Items {
275+
debtStatus := ""
276+
anno := namespaceList.Items[i].Annotations
277+
if anno != nil {
278+
debtStatus = anno[v1.DebtNamespaceAnnoStatusKey]
279+
}
280+
if debtStatus == v1.SuspendDebtNamespaceAnnoStatus || debtStatus == v1.SuspendCompletedDebtNamespaceAnnoStatus ||
281+
debtStatus == v1.FinalDeletionDebtNamespaceAnnoStatus || debtStatus == v1.FinalDeletionCompletedDebtNamespaceAnnoStatus {
282+
continue
283+
}
284+
items = append(items, namespaceList.Items[i])
285+
}
286+
namespaceList.Items = items
287+
logger.Info("filter normal namespace", "namespaceList len", len(namespaceList.Items), "time", time.Now().Format(time.RFC3339))
288+
}
289+
268290
func (r *MonitorReconciler) processNamespaceList(namespaceList *corev1.NamespaceList) error {
269291
logger.Info("start processNamespaceList", "namespaceList len", len(namespaceList.Items), "time", time.Now().Format(time.RFC3339))
270292
if len(namespaceList.Items) == 0 {
@@ -580,9 +602,14 @@ func (r *MonitorReconciler) monitorObjectStorageTraffic() error {
580602
sent := int64(0)
581603
if r.lastObjectMetrics != nil && r.lastObjectMetrics[user].Sent != nil {
582604
if _, ok := r.lastObjectMetrics[user].Sent[bucket]; ok {
583-
ss := m - r.lastObjectMetrics[user].Sent[bucket]
584-
if ss > 0 {
585-
sent = ss
605+
if m == -1 {
606+
r.currentObjectMetrics[user].Sent[bucket] = r.lastObjectMetrics[user].Sent[bucket]
607+
m = r.lastObjectMetrics[user].Sent[bucket]
608+
} else {
609+
ss := m - r.lastObjectMetrics[user].Sent[bucket]
610+
if ss > 0 {
611+
sent = ss
612+
}
586613
}
587614
}
588615
}

frontend/desktop/.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"i18n-ally.keystyle": "nested",
1212
"i18n-ally.sortKeys": true,
1313
"i18n-ally.keepFulfilled": false,
14-
"i18n-ally.sourceLanguage": "zh",
15-
"i18n-ally.displayLanguage": "zh",
14+
"i18n-ally.sourceLanguage": "en",
15+
"i18n-ally.displayLanguage": "en",
1616
"i18n-ally.namespace": true,
1717
"i18n-ally.pathMatcher": "{locale}/{namespaces}.json",
1818
"i18n-ally.extract.targetPickingStrategy": "most-similar-by-key",

frontend/desktop/deploy/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ sealos build -t docker.io/labring/sealos-cloud-desktop:latest -f Kubefile .
66

77
### Env
88

9-
| Name | Description | Default |
10-
|----------------------------|-----------------------------|--------------------|
11-
| `cloudDomain` | sealos cloud domain | `127.0.0.1.nip.io` |
12-
| `wildcardCertSecretName` | wildcard cert secret name | `wildcard-cert` |
9+
| Name | Description | Default |
10+
| ------------------------ | ------------------------- | ------------------ |
11+
| `cloudDomain` | sealos cloud domain | `127.0.0.1.nip.io` |
12+
| `wildcardCertSecretName` | wildcard cert secret name | `wildcard-cert` |
1313

1414
### Config
1515

1616
Here is a config file example:
17+
1718
```yaml
1819
# desktop-config.yaml
1920
apiVersion: apps.sealos.io/v1beta1
@@ -49,7 +50,7 @@ spec:
4950
layout:
5051
title: "Sealos Cloud"
5152
logo: "/logo.png"
52-
backgroundImage: "/images/bg-blue.svg"
53+
backgroundImage: "/images/bg-light.svg"
5354
meta:
5455
title: "Sealos Cloud"
5556
description: "Sealos Cloud"
@@ -76,7 +77,6 @@ spec:
7677
password:
7778
enabled: "true"
7879
salt: "thisispasswordsalt"
79-
8080
```
8181
8282
### How to run
@@ -86,5 +86,5 @@ sealos run \
8686
--env cloudDomain="127.0.0.1.nip.io" \
8787
--env wildcardCertSecretName="wildcard-cert" \
8888
docker.io/labring/sealos-cloud-desktop:latest \
89-
--config-file desktop-config.yaml
89+
--config-file desktop-config.yaml
9090
```

frontend/desktop/deploy/manifests/configmap.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data:
2323
layout:
2424
title: "Sealos Cloud"
2525
logo: "/logo.svg"
26-
backgroundImage: "/images/bg-blue.svg"
26+
backgroundImage: "/images/bg-light.svg"
2727
meta:
2828
title: "Sealos Cloud"
2929
description: "Sealos Cloud"

frontend/desktop/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838
"@tanstack/react-query": "^4.35.3",
3939
"@umami/node": "^0.4.0",
4040
"axios": "^1.5.1",
41+
"boring-avatars": "^1.11.2",
4142
"clsx": "^1.2.1",
4243
"cors": "^2.8.5",
4344
"croner": "^8.0.2",
4445
"dayjs": "^1.11.10",
4546
"decimal.js": "^10.4.3",
47+
"disposable-email-domains-js": "^1.11.0",
4648
"eslint": "8.38.0",
4749
"eslint-config-next": "13.3.0",
4850
"framer-motion": "^10.16.4",
@@ -53,6 +55,7 @@
5355
"jsonwebtoken": "^9.0.2",
5456
"jwt-decode": "^4.0.0",
5557
"lodash": "^4.17.21",
58+
"lucide-react": "^0.488.0",
5659
"minio": "^7.1.3",
5760
"mongodb": "^5.9.0",
5861
"nanoid": "^4.0.2",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- CreateTable
2+
CREATE TABLE "user_info" (
3+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
4+
"user_uid" UUID NOT NULL,
5+
"sign_up_region_uid" UUID NOT NULL,
6+
"is_inited" BOOL NOT NULL DEFAULT false,
7+
"config" JSONB,
8+
9+
CONSTRAINT "user_info_pkey" PRIMARY KEY ("id")
10+
);
11+
12+
-- CreateTable
13+
CREATE TABLE "workspace_usage" (
14+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
15+
"user_uid" UUID NOT NULL,
16+
"workspace_uid" UUID NOT NULL,
17+
"region_uid" UUID NOT NULL,
18+
"seat" INT4 NOT NULL,
19+
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
20+
"updated_at" TIMESTAMPTZ(3) NOT NULL,
21+
22+
CONSTRAINT "workspace_usage_pkey" PRIMARY KEY ("id")
23+
);
24+
25+
-- CreateIndex
26+
CREATE UNIQUE INDEX "user_info_user_uid_key" ON "user_info"("user_uid");
27+
28+
-- CreateIndex
29+
CREATE INDEX "workspace_usage_user_uid_idx" ON "workspace_usage"("user_uid");
30+
31+
-- CreateIndex
32+
CREATE UNIQUE INDEX "workspace_usage_region_uid_user_uid_workspace_uid_key" ON "workspace_usage"("region_uid", "user_uid", "workspace_uid");

frontend/desktop/prisma/global/schema.prisma

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ model OauthProvider {
2525
}
2626

2727
model Region {
28-
uid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
29-
displayName String
30-
location String
31-
domain String
32-
description String?
33-
txDetail TransactionDetail[]
28+
uid String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
29+
displayName String
30+
location String
31+
domain String
32+
description String?
33+
txDetail TransactionDetail[]
34+
WorkspaceUsage WorkspaceUsage[]
3435
}
3536

3637
model Account {
@@ -59,6 +60,34 @@ model AccountTransaction {
5960
billing_id String @db.Uuid
6061
}
6162

63+
model UserInfo {
64+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
65+
userUid String @unique @map("user_uid") @db.Uuid
66+
signUpRegionUid String @map("sign_up_region_uid") @db.Uuid
67+
isInited Boolean @default(false) @map("is_inited")
68+
// verify_email Boolean @default(false)
69+
config Json?
70+
user User @relation(fields: [userUid], references: [uid])
71+
72+
@@map("user_info")
73+
}
74+
75+
model WorkspaceUsage {
76+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
77+
userUid String @map("user_uid") @db.Uuid
78+
workspaceUid String @map("workspace_uid") @db.Uuid
79+
regionUid String @map("region_uid") @db.Uuid
80+
seat Int
81+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
82+
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
83+
region Region @relation(fields: [regionUid], references: [uid])
84+
user User @relation(fields: [userUid], references: [uid])
85+
86+
@@unique([regionUid, userUid, workspaceUid])
87+
@@index([userUid])
88+
@@map("workspace_usage")
89+
}
90+
6291
model ErrorPaymentCreate {
6392
userUid String @db.Uuid
6493
regionUid String @db.Uuid
@@ -106,6 +135,8 @@ model User {
106135
DeleteUserTransactionInfo DeleteUserTransactionInfo?
107136
deleteUserLog DeleteUserLog?
108137
userTasks UserTask[]
138+
userInfo UserInfo?
139+
WorkspaceUsage WorkspaceUsage[]
109140
}
110141

111142
model Transfer {
@@ -219,7 +250,7 @@ model EventLog {
219250
createdAt DateTime @default(now()) @db.Timestamptz(3)
220251
mainId String
221252
eventName String
222-
// json
253+
// json
223254
data String
224255
}
225256

0 commit comments

Comments
 (0)