From 9bc3343f1c3622b62dfaea0df96befd7ae802fda Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:01:57 +0000 Subject: [PATCH 1/2] Added EKS support in scheduling logic --- .../api/handler/schedule_task_v1alpha1.go | 103 +++++++++++------- 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/internal/api/handler/schedule_task_v1alpha1.go b/internal/api/handler/schedule_task_v1alpha1.go index 084f767..72deabb 100644 --- a/internal/api/handler/schedule_task_v1alpha1.go +++ b/internal/api/handler/schedule_task_v1alpha1.go @@ -20,48 +20,67 @@ func ScheduleTaskV1alpha1(ctx context.Context, store store.Interface, http.Error(w, err.Error(), http.StatusInternalServerError) return } - for _, policy := range *policies { - schedule, err := store.GetSchedule(policy.ScheduleName) - if err == gorm.ErrRecordNotFound { - w.WriteHeader(http.StatusNotFound) - return - } - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - location, err := time.LoadLocation(schedule.TimeZone) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - nowInTargetLocation := time.Now().In(location) - day, hour := timezone.ConvertTimeToIndex(nowInTargetLocation) - var arr []int - for _, v := range schedule.Schedule.Data().NdArray { - arr = append(arr, v...) - } - matrixSize := schedule.Schedule.Data().Shape[0] * schedule.Schedule.Data().Shape[1] - prevIdx := getPreviousIdx(day*24+hour, matrixSize) - now := arr[day*24+hour] - prev := arr[prevIdx] - if now != prev { - for _, tag := range policy.Tags { - for k, v := range tag { - for _, project := range policy.Projects { - e := worker.QueueElem{ - RequestURI: v1alpha1.GoryaTaskChangeStageProcedure, - Project: project, - TagKey: k, - TagValue: v, - Action: now, - } - taskProcessor.Dispatch(ctx, &e) - } - } - } - } - } + for _, policy := range *policies { + if policy.Type == "EKS" { + // Implement the logic to schedule compute units for EKS + for _, tag := range policy.Tags { + for k, v := range tag { + for _, project := range policy.Projects { + e := worker.QueueElem{ + RequestURI: v1alpha1.GoryaTaskChangeStageProcedure, + Project: project, + TagKey: k, + TagValue: v, + Action: now, + // Add necessary parameters for EKS + } + taskProcessor.Dispatch(ctx, &e) + } + } + } + } else { + schedule, err := store.GetSchedule(policy.ScheduleName) + if err == gorm.ErrRecordNotFound { + w.WriteHeader(http.StatusNotFound) + return + } + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + location, err := time.LoadLocation(schedule.TimeZone) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + nowInTargetLocation := time.Now().In(location) + day, hour := timezone.ConvertTimeToIndex(nowInTargetLocation) + var arr []int + for _, v := range schedule.Schedule.Data().NdArray { + arr = append(arr, v...) + } + matrixSize := schedule.Schedule.Data().Shape[0] * schedule.Schedule.Data().Shape[1] + prevIdx := getPreviousIdx(day*24+hour, matrixSize) + now := arr[day*24+hour] + prev := arr[prevIdx] + if now != prev { + for _, tag := range policy.Tags { + for k, v := range tag { + for _, project := range policy.Projects { + e := worker.QueueElem{ + RequestURI: v1alpha1.GoryaTaskChangeStageProcedure, + Project: project, + TagKey: k, + TagValue: v, + Action: now, + } + taskProcessor.Dispatch(ctx, &e) + } + } + } + } + } + } } } From 12d515faf90026fa8176d220540340ecd38853f8 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:03:02 +0000 Subject: [PATCH 2/2] Added EKS configuration file --- internal/api/config/eks_config.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 internal/api/config/eks_config.go diff --git a/internal/api/config/eks_config.go b/internal/api/config/eks_config.go new file mode 100644 index 0000000..d913d27 --- /dev/null +++ b/internal/api/config/eks_config.go @@ -0,0 +1,20 @@ +package config + +import ( + "os" +) + +type EKSConfig struct { + ClusterName string + NodeGroupName string + // Add other necessary fields here +} + +func LoadEKSConfigFromEnv() *EKSConfig { + return &EKSConfig{ + ClusterName: os.Getenv("EKS_CLUSTER_NAME"), + NodeGroupName: os.Getenv("EKS_NODE_GROUP_NAME"), + // Load other necessary fields here + } +} +