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

Update devbox controller, add support init request ephemeral storage. #5156

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions controllers/devbox/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func main() {
var registryUser string
var registryPassword string
var authAddr string
var ephemeralStorage string
var requestEphemeralStorage string
var limitEphemeralStorage string
var debugMode bool
flag.StringVar(&registryAddr, "registry-addr", "sealos.hub:5000", "The address of the registry")
flag.StringVar(&registryUser, "registry-user", "admin", "The user of the registry")
Expand All @@ -86,7 +87,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.StringVar(&ephemeralStorage, "ephemeral-storage", "2000Mi", "The maximum value of equatorial storage 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{
Development: true,
}
Expand Down Expand Up @@ -177,12 +179,13 @@ func main() {
}

if err = (&controller.DevboxReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CommitImageRegistry: registryAddr,
Recorder: mgr.GetEventRecorderFor("devbox-controller"),
EquatorialStorage: ephemeralStorage,
DebugMode: debugMode,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
CommitImageRegistry: registryAddr,
Recorder: mgr.GetEventRecorderFor("devbox-controller"),
RequestEphemeralStorage: requestEphemeralStorage,
LimitEphemeralStorage: limitEphemeralStorage,
DebugMode: debugMode,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Devbox")
os.Exit(1)
Expand Down
7 changes: 4 additions & 3 deletions controllers/devbox/internal/controller/devbox_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ import (

// DevboxReconciler reconciles a Devbox object
type DevboxReconciler struct {
CommitImageRegistry string
EquatorialStorage string
CommitImageRegistry string
RequestEphemeralStorage string
LimitEphemeralStorage string

DebugMode bool

Expand Down Expand Up @@ -526,7 +527,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.EquatorialStorage),
Resources: helper.GenerateResourceRequirements(devbox, r.RequestEphemeralStorage, r.LimitEphemeralStorage),
},
}

Expand Down
28 changes: 22 additions & 6 deletions controllers/devbox/internal/controller/helper/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ func PodMatchExpectations(expectPod *corev1.Pod, pod *corev1.Pod) bool {
return false
}

// Check Ephemeral Storage changes
if container.Resources.Requests.StorageEphemeral().Cmp(*expectContainer.Resources.Requests.StorageEphemeral()) != 0 {
slog.Info("Ephemeral-Storage requests are not equal")
return false
}
if container.Resources.Limits.StorageEphemeral().Cmp(*expectContainer.Resources.Limits.StorageEphemeral()) != 0 {
slog.Info("Ephemeral-Storage limits are not equal")
return false
}

// Check environment variables
if len(container.Env) != len(expectContainer.Env) {
return false
Expand Down Expand Up @@ -370,18 +380,19 @@ func GenerateSSHVolume(devbox *devboxv1alpha1.Devbox) corev1.Volume {
}
}

func GenerateResourceRequirements(devbox *devboxv1alpha1.Devbox, equatorialStorage string) corev1.ResourceRequirements {
func GenerateResourceRequirements(devbox *devboxv1alpha1.Devbox, 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.ResourceCPU: devbox.Spec.Resource["cpu"],
corev1.ResourceMemory: devbox.Spec.Resource["memory"],
corev1.ResourceEphemeralStorage: resource.MustParse(requestEphemeralStorage),
},
),
Limits: corev1.ResourceList{
"cpu": devbox.Spec.Resource["cpu"],
"memory": devbox.Spec.Resource["memory"],
"ephemeral-storage": resource.MustParse(equatorialStorage),
corev1.ResourceCPU: devbox.Spec.Resource["cpu"],
corev1.ResourceMemory: devbox.Spec.Resource["memory"],
corev1.ResourceEphemeralStorage: resource.MustParse(limitEphemeralStorage),
},
}
}
Expand All @@ -403,6 +414,11 @@ func calculateResourceRequest(limit corev1.ResourceList) corev1.ResourceList {
memoryRequest := memoryValue / rate
request[corev1.ResourceMemory] = *resource.NewQuantity(int64(memoryRequest), resource.BinarySI)
}

if ephemeralStorage, ok := limit[corev1.ResourceEphemeralStorage]; ok {
request[corev1.ResourceEphemeralStorage] = ephemeralStorage
}

return request
}

Expand Down
Loading