Skip to content

Commit

Permalink
add extraEnv toleration affinity,ephemeral-storage limit (labring#5023)
Browse files Browse the repository at this point in the history
  • Loading branch information
bearslyricattack authored and zjy365 committed Sep 3, 2024
1 parent e005c36 commit 52b21a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
15 changes: 15 additions & 0 deletions controllers/devbox/api/v1alpha1/devbox_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ type RuntimeRef struct {
// +kubebuilder:validation:Required
Name string `json:"name"`
}
type RunSpec struct {
// +kubebuilder:validation:Optional
Env []corev1.EnvVar `json:"env"`
}

type ScheduleSpec struct {
// +kubebuilder:validation:Optional
Tolerations []corev1.Toleration
// +kubebuilder:validation:Optional
Affinity corev1.Affinity
}

type NetworkSpec struct {
// +kubebuilder:validation:Required
Expand All @@ -78,6 +89,10 @@ type DevboxSpec struct {
RuntimeRef RuntimeRef `json:"runtimeRef"`
// +kubebuilder:validation:Required
NetworkSpec NetworkSpec `json:"network"`
// +kubebuilder:validation:Optional
RunSpec RunSpec `json:"run"`
// +kubebuilder:validation:Optional
ScheduleSpec ScheduleSpec `json:"schedule"`
}

type NetworkStatus struct {
Expand Down
3 changes: 3 additions & 0 deletions controllers/devbox/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func main() {
var registryUser string
var registryPassword string
var authAddr string
var ephemeralStorage string
flag.StringVar(&registryAddr, "registry-addr", "sealos.hub:5000", "The address of the registry")
flag.StringVar(&registryUser, "registry-user", "admin", "The user of the registry")
flag.StringVar(&registryPassword, "registry-password", "passw0rd", "The password of the registry")
Expand All @@ -78,6 +79,7 @@ func main() {
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.StringVar(&ephemeralStorage, "ephemeral-storage", "2000Mi", "The maximum value of equatorial storage in devbox.")
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -158,6 +160,7 @@ func main() {
Scheme: mgr.GetScheme(),
CommitImageRegistry: registryAddr,
Recorder: mgr.GetEventRecorderFor("devbox-controller"),
EquatorialStorage: ephemeralStorage,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Devbox")
os.Exit(1)
Expand Down
10 changes: 7 additions & 3 deletions controllers/devbox/internal/controller/devbox_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
// DevboxReconciler reconciles a Devbox object
type DevboxReconciler struct {
CommitImageRegistry string

EquatorialStorage string
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Expand Down Expand Up @@ -384,6 +384,7 @@ func (r *DevboxReconciler) generateDevboxPod(ctx context.Context, devbox *devbox
},
},
}
envs = append(envs, devbox.Spec.RunSpec.Env...)

//get image name
imageName, err := r.getLastSuccessCommitImageName(ctx, devbox)
Expand All @@ -405,8 +406,9 @@ func (r *DevboxReconciler) generateDevboxPod(ctx context.Context, devbox *devbox
},
),
Limits: corev1.ResourceList{
"cpu": devbox.Spec.Resource["cpu"],
"memory": devbox.Spec.Resource["memory"],
"cpu": devbox.Spec.Resource["cpu"],
"memory": devbox.Spec.Resource["memory"],
"ephemeral-storage": resource.MustParse(r.EquatorialStorage),
},
},
VolumeMounts: []corev1.VolumeMount{
Expand Down Expand Up @@ -445,6 +447,8 @@ func (r *DevboxReconciler) generateDevboxPod(ctx context.Context, devbox *devbox
Volumes: volume,
TerminationGracePeriodSeconds: ptr.To(int64(terminationGracePeriodSeconds)),
AutomountServiceAccountToken: ptr.To(automountServiceAccountToken),
Tolerations: devbox.Spec.ScheduleSpec.Tolerations,
Affinity: &devbox.Spec.ScheduleSpec.Affinity,
},
}
if err = controllerutil.SetControllerReference(devbox, expectPod, r.Scheme); err != nil {
Expand Down

0 comments on commit 52b21a3

Please sign in to comment.