Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-apiproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
HUAHUAI23 committed Nov 8, 2024
2 parents e64d455 + d754ebe commit 6ee56b4
Show file tree
Hide file tree
Showing 148 changed files with 4,272 additions and 1,429 deletions.
1 change: 0 additions & 1 deletion controllers/account/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clbanning/mxj/v2 v2.5.7 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions controllers/devbox/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func main() {
var registryUser string
var registryPassword string
var authAddr string
var requestCPURate float64
var requestMemoryRate float64
var requestEphemeralStorage string
var limitEphemeralStorage string
var debugMode bool
Expand All @@ -87,6 +89,8 @@ func main() {
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.BoolVar(&debugMode, "debug", false, "If set, debug mode will be enabled")
flag.Float64Var(&requestCPURate, "request-cpu-rate", 10, "The request rate of cpu limit in devbox.")
flag.Float64Var(&requestMemoryRate, "request-memory-rate", 10, "The request rate of memory limit in devbox.")
flag.StringVar(&requestEphemeralStorage, "request-ephemeral-storage", "500Mi", "The request value of ephemeral storage in devbox.")
flag.StringVar(&limitEphemeralStorage, "limit-ephemeral-storage", "10Gi", "The limit value of ephemeral storage in devbox.")
opts := zap.Options{
Expand Down Expand Up @@ -183,6 +187,8 @@ func main() {
Scheme: mgr.GetScheme(),
CommitImageRegistry: registryAddr,
Recorder: mgr.GetEventRecorderFor("devbox-controller"),
RequestCPURate: requestCPURate,
RequestMemoryRate: requestMemoryRate,
RequestEphemeralStorage: requestEphemeralStorage,
LimitEphemeralStorage: limitEphemeralStorage,
DebugMode: debugMode,
Expand Down
4 changes: 3 additions & 1 deletion controllers/devbox/internal/controller/devbox_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import (
// DevboxReconciler reconciles a Devbox object
type DevboxReconciler struct {
CommitImageRegistry string
RequestCPURate float64
RequestMemoryRate float64
RequestEphemeralStorage string
LimitEphemeralStorage string

Expand Down Expand Up @@ -547,7 +549,7 @@ func (r *DevboxReconciler) generateDevboxPod(devbox *devboxv1alpha1.Devbox, runt
WorkingDir: helper.GenerateWorkingDir(devbox, runtime),
Command: helper.GenerateCommand(devbox, runtime),
Args: helper.GenerateDevboxArgs(devbox, runtime),
Resources: helper.GenerateResourceRequirements(devbox, r.RequestEphemeralStorage, r.LimitEphemeralStorage),
Resources: helper.GenerateResourceRequirements(devbox, r.RequestCPURate, r.RequestMemoryRate, r.RequestEphemeralStorage, r.LimitEphemeralStorage),
},
}

Expand Down
21 changes: 16 additions & 5 deletions controllers/devbox/internal/controller/helper/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
)

const (
rate = 10
DevBoxPartOf = "devbox"
)

Expand Down Expand Up @@ -210,10 +209,18 @@ func PodMatchExpectations(expectPod *corev1.Pod, pod *corev1.Pod) bool {
expectContainer := expectPod.Spec.Containers[0]

// Check CPU and memory limits
if container.Resources.Requests.Cpu().Cmp(*expectContainer.Resources.Requests.Cpu()) != 0 {
slog.Info("CPU requests are not equal")
return false
}
if container.Resources.Limits.Cpu().Cmp(*expectContainer.Resources.Limits.Cpu()) != 0 {
slog.Info("CPU limits are not equal")
return false
}
if container.Resources.Requests.Memory().Cmp(*expectContainer.Resources.Requests.Memory()) != 0 {
slog.Info("Memory requests are not equal")
return false
}
if container.Resources.Limits.Memory().Cmp(*expectContainer.Resources.Limits.Memory()) != 0 {
slog.Info("Memory limits are not equal")
return false
Expand Down Expand Up @@ -381,14 +388,18 @@ func GenerateSSHVolume(devbox *devboxv1alpha1.Devbox) corev1.Volume {
}
}

func GenerateResourceRequirements(devbox *devboxv1alpha1.Devbox, requestEphemeralStorage, limitEphemeralStorage string) corev1.ResourceRequirements {
func GenerateResourceRequirements(devbox *devboxv1alpha1.Devbox,
requestCPURate, requestMemoryRate float64,
requestEphemeralStorage, limitEphemeralStorage string,
) corev1.ResourceRequirements {
return corev1.ResourceRequirements{
Requests: calculateResourceRequest(
corev1.ResourceList{
corev1.ResourceCPU: devbox.Spec.Resource["cpu"],
corev1.ResourceMemory: devbox.Spec.Resource["memory"],
corev1.ResourceEphemeralStorage: resource.MustParse(requestEphemeralStorage),
},
requestCPURate, requestMemoryRate,
),
Limits: corev1.ResourceList{
corev1.ResourceCPU: devbox.Spec.Resource["cpu"],
Expand All @@ -402,21 +413,21 @@ func IsExceededQuotaError(err error) bool {
return strings.Contains(err.Error(), "exceeded quota")
}

func calculateResourceRequest(limit corev1.ResourceList) corev1.ResourceList {
func calculateResourceRequest(limit corev1.ResourceList, requestCPURate, requestMemoryRate float64) corev1.ResourceList {
if limit == nil {
return nil
}
request := make(corev1.ResourceList)
// Calculate CPU request
if cpu, ok := limit[corev1.ResourceCPU]; ok {
cpuValue := cpu.AsApproximateFloat64()
cpuRequest := cpuValue / rate
cpuRequest := cpuValue / requestCPURate
request[corev1.ResourceCPU] = *resource.NewMilliQuantity(int64(cpuRequest*1000), resource.DecimalSI)
}
// Calculate memory request
if memory, ok := limit[corev1.ResourceMemory]; ok {
memoryValue := memory.AsApproximateFloat64()
memoryRequest := memoryValue / rate
memoryRequest := memoryValue / requestMemoryRate
request[corev1.ResourceMemory] = *resource.NewQuantity(int64(memoryRequest), resource.BinarySI)
}

Expand Down
1 change: 0 additions & 1 deletion controllers/job/init/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion controllers/license/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -219,8 +218,10 @@ func (r *ObjectStorageUserReconciler) Reconcile(ctx context.Context, req ctrl.Re
updated = true
}

if used.Value() != size {
resourceQuota.Status.Used[ResourceObjectStorageSize] = resource.MustParse(strconv.FormatInt(size, 10))
stringSize := ConvertBytesToString(size)

if used.String() != stringSize {
resourceQuota.Status.Used[ResourceObjectStorageSize] = resource.MustParse(stringSize)
if err := r.Status().Update(ctx, resourceQuota); err != nil {
r.Logger.Error(err, "failed to update status", "name", resourceQuota.Name, "namespace", userNamespace)
return ctrl.Result{}, err
Expand Down Expand Up @@ -433,6 +434,30 @@ func (r *ObjectStorageUserReconciler) initObjectStorageKeySecret(secret *corev1.
return updated
}

func ConvertBytesToString(bytes int64) string {
var unit string
var value float64

switch {
case bytes >= 1<<40: // 1 TiB
value = float64(bytes) / (1 << 40)
unit = "Ti"
case bytes >= 1<<30: // 1 GiB
value = float64(bytes) / (1 << 30)
unit = "Gi"
case bytes >= 1<<20: // 1 MiB
value = float64(bytes) / (1 << 20)
unit = "Mi"
case bytes >= 1<<10: // 1 KiB
value = float64(bytes) / (1 << 10)
unit = "Ki"
default:
return fmt.Sprintf("%d", bytes)
}

return fmt.Sprintf("%.0f%s", value, unit)
}

// SetupWithManager sets up the controller with the Manager.
func (r *ObjectStorageUserReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Logger = ctrl.Log.WithName("object-storage-user-controller")
Expand Down
1 change: 0 additions & 1 deletion controllers/pkg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ replace (

require (
github.com/containers/storage v1.50.2
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49
github.com/dustin/go-humanize v1.0.1
github.com/go-logr/logr v1.4.1
github.com/golang-jwt/jwt/v4 v4.5.0
Expand Down
2 changes: 0 additions & 2 deletions controllers/pkg/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 h1:4GI5eviCwbPxDE311KryyyPUTO7IDVyHGp3Iyl+fEZY=
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49/go.mod h1:sbm1DAsayX+XsXCOC2CFAAU9JZhX0SPKwnybDjSd0Ls=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
5 changes: 0 additions & 5 deletions controllers/resources/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
Expand Down Expand Up @@ -61,7 +60,6 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/labring/sealos/controllers/account v0.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matoous/go-nanoid/v2 v2.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
Expand Down Expand Up @@ -98,8 +96,6 @@ require (
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -120,7 +116,6 @@ require (
)

replace (
github.com/labring/sealos/controllers/account => ../account
github.com/labring/sealos/controllers/pkg => ../pkg
github.com/labring/sealos/controllers/user => ../user
)
5 changes: 4 additions & 1 deletion docs/website/src/pages/components/Footer/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@
font-style: normal;
font-weight: 600;
line-height: 140%;
a{
display: flex;
align-items: center;
gap: 4px;
a {
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
}
Expand Down
23 changes: 18 additions & 5 deletions docs/website/src/pages/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ const Footer = ({ isPc }: { isPc: boolean }) => {
</div>
<div className="footer-bottom-wrap">
<div className="footer-bottom">
<div className="footer-bottom-text">
Made by Sealos Team.{' '}
<Link to={'https://beian.miit.gov.cn/'}>粤ICP备2023048773号</Link>&nbsp;
<div className="footer-bottom-text flex-wrap">
Made by Sealos Team.
<img
className="w-4 h-4"
src={require('@site/static/img/beian.png').default}
alt="beian"
/>
<Link to={'https://beian.miit.gov.cn/'}>浙公网安备33011002017870号</Link>
<Link to={'https://beian.miit.gov.cn/'}>粤ICP备2023048773号</Link>
珠海环界云计算有限公司版权所有
</div>
<div className="link">
Expand Down Expand Up @@ -130,8 +136,15 @@ const Footer = ({ isPc }: { isPc: boolean }) => {
<div className="footer-bottom-wrap">
<div className="footer-bottom">
<div className="footer-bottom-text">
Made by Sealos Team. <Link to={'https://beian.miit.gov.cn/'}>粤ICP备2023048773号</Link>
&nbsp; 珠海环界云计算有限公司版权所有
Made by Sealos Team.
<img
className="w-4 h-4"
src={require('@site/static/img/beian.png').default}
alt="beian"
/>
<Link to={'https://beian.miit.gov.cn/'}>浙公网安备33011002017870号</Link>
<Link to={'https://beian.miit.gov.cn/'}>粤ICP备2023048773号</Link>
珠海环界云计算有限公司版权所有
</div>
<div className="link">
{FooterLinks.map((item) => {
Expand Down
Binary file added docs/website/static/img/beian.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the

1. 获取登录凭证: 由于 login 页面不是在 desktop 项目里,所以需要从线上 sealos 获取登录凭证到本地开发: <https://cloud.sealos.io/> 。复制 storage 里的 session 到 localhost 环境实现 mock 登录。

2. Chakra ui <https://chakra-ui.com/getting-started>
2. Chakra ui <https://v2.chakra-ui.com/getting-started>

3. TanStack Query 用法:<https://cangsdarm.github.io/react-query-web-i18n/react>

Expand Down
26 changes: 13 additions & 13 deletions frontend/desktop/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"account_settings": "Account Settings",
"added": "Added",
"agree_policy": "I have read and agree to the",
"alarm_pod": "Alarm Pod: {{count}}",
"alarm_pod": "Unhealthy Pods: {{count}}",
"alerts": "Alerts",
"all_apps": "All Apps",
"already_sent_code": "Already sent code",
Expand All @@ -19,7 +19,7 @@
"attachment": "appendix",
"avatar": "Avatar",
"balance": "Balance",
"bind": "Bind",
"bind": "Link",
"bind_success": "Binding successful",
"bonus": "Bonus",
"bound": "Bound",
Expand Down Expand Up @@ -70,13 +70,13 @@
"enterprise_name": "Company name",
"enterprise_name_required": "Please enter the correct company name",
"enterprise_verification": "Enterprise real name",
"expected_to_use_next_month": "Expected to use next month",
"expected_used": "Expected used",
"expected_to_use_next_month": "Estimated Next Invoice",
"expected_used": "Estimated Runaway",
"face_recognition_failed": "Personal real name failed",
"face_recognition_success": "Personal real-name success",
"failed_to_generate_invitation_link": "Failed to generate invitation link",
"failed_to_get_qr_code": "Failed to obtain real name QR code",
"flow": "Traffic",
"flow": " Network",
"force_delete_keywords": "All resources cannot be recovered after account deletion.",
"force_delete_tips": "There are still undeleted resources in your account. Once deleted, all resources will be unrecoverable. Please ensure you have backed up or transferred all important data.",
"from": "From",
Expand All @@ -91,7 +91,7 @@
"guide_objectstorage": "Massive storage space, almost bare metal speed experience",
"handle": "Handle",
"have_read": "Have read",
"healthy_pod": "Healthy Pod: {{count}}",
"healthy_pod": "Healthy Pods: {{count}}",
"hello_welcome": "Hello, welcome to",
"help_you_enable_high_availability_database": "Help you enable high availability database",
"home": "home",
Expand Down Expand Up @@ -125,15 +125,15 @@
"login_with_google": "Login with Google",
"login_with_oauth2": "login with OAuth2.0",
"login_with_wechat": "Login with Wechat",
"manage_team": "Manage Workspace",
"manage_team": "Manage Workspaces",
"member_list": "Member List",
"memory": "Memory",
"merge": "merge",
"merge_account_tips1": "The account you are trying to bind has been used by another user. Due to conflicting binding methods, the accounts cannot be merged.",
"merge_account_tips2": "The account you are trying to bind has been used by another user. You can choose to merge accounts to manage your information and settings in a unified way. After the merge is completed, your private workspace may be converted into a regular workspace. Do you want to merge accounts now?",
"merge_account_title": "Account has been bound",
"message_center": "Message Center",
"modify_member": "Modify Member",
"modify_member": "Modify Member",
"monitor": "Monitor",
"more_apps": "More Apps",
"name": "Name",
Expand All @@ -147,7 +147,7 @@
"nickname": "Nickname",
"no_apps_found": "No Apps Found",
"no_realname_auth": "NO REALNAME AUTH",
"notification": "notify",
"notification": "Notification",
"noworkspacecreated": "You haven't created a workspace yet",
"official_account_login": "Official account login",
"old_email": "Old email",
Expand Down Expand Up @@ -233,12 +233,12 @@
"total_amount": "Total Amount",
"unbind": "Unbind",
"unbind_success": "Unbinding successfully",
"unbound": "Unbound",
"unbound": "Not Linked",
"under_active_development": "Under active development 🚧",
"unread": "Unread",
"upload_success": "Upload successful",
"used_last_month": "Used last month",
"used_resources": "Used Resources",
"used_last_month": " Last Invoice",
"used_resources": "Resources Used",
"user_name": "User Name",
"username": "Username",
"username_tips": "Username must be 3-16 characters, including letters, numbers",
Expand Down Expand Up @@ -267,4 +267,4 @@
"you_can_view_fees_through_the_fee_center": "You can view fees through the fee center",
"you_have_not_purchased_the_license": "You have not purchased the License",
"yuan": "Yuan"
}
}
Loading

0 comments on commit 6ee56b4

Please sign in to comment.