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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EKS #13

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 20 additions & 0 deletions internal/api/config/eks_config.go
Original file line number Diff line number Diff line change
@@ -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
}
}

103 changes: 61 additions & 42 deletions internal/api/handler/schedule_task_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}
}
}
}

Expand Down