From 21b91a7ed33439bfb62ae46eface847a05acfa70 Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Wed, 18 Sep 2024 13:28:32 -0400 Subject: [PATCH] Make the cloud scheduler deployer GKE-aware Depending on if a "--gke" parameter (must be the last one) is passed, the deployer constructs the corresponding URIs for GAE or GKE accordingly. TESTED=Used the deployer to deploy tasks to alpha and verified that they run on GKE. --- .../builder/deployCloudSchedulerAndQueue.go | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/release/builder/deployCloudSchedulerAndQueue.go b/release/builder/deployCloudSchedulerAndQueue.go index 74ef57ca22..5a1bf00470 100644 --- a/release/builder/deployCloudSchedulerAndQueue.go +++ b/release/builder/deployCloudSchedulerAndQueue.go @@ -30,8 +30,12 @@ import ( "gopkg.in/yaml.v3" ) +var gke bool = false + var projectName string +var baseDomain string + var clientId string const GcpLocation = "us-central1" @@ -80,6 +84,9 @@ type TasksSyncManager struct { } type YamlEntries struct { + GcpProject struct { + BaseDomain string `yaml:"baseDomain"` + } `yaml:"gcpProject"` Auth struct { OauthClientId string `yaml:"oauthClientId"` } `yaml:"auth"` @@ -169,7 +176,7 @@ func (manager TasksSyncManager) getXmlEntries() []Task { } func (manager TasksSyncManager) getArgs(task Task, operationType string) []string { - // Cloud Schedule doesn't allow description of more than 499 chars and \n + // Cloud Scheduler doesn't allow description of more than 499 chars. var description string if len(task.Description) > 499 { log.Default().Println("Task description exceeds the allowed length of " + @@ -186,13 +193,20 @@ func (manager TasksSyncManager) getArgs(task Task, operationType string) []strin service = task.Service } + var uri string + if gke { + uri = fmt.Sprintf("https://%s.%s%s", service, baseDomain, strings.TrimSpace(task.URL)) + } else { + uri = fmt.Sprintf("https://%s-dot-%s.appspot.com%s", service, projectName, strings.TrimSpace(task.URL)) + } + return []string{ "--project", projectName, "scheduler", "jobs", operationType, "http", task.Name, "--location", GcpLocation, "--schedule", task.Schedule, - "--uri", fmt.Sprintf("https://%s-dot-%s.appspot.com%s", service, projectName, strings.TrimSpace(task.URL)), + "--uri", uri, "--description", description, "--http-method", "get", "--oidc-service-account-email", getCloudSchedulerServiceAccountEmail(), @@ -319,7 +333,8 @@ func getExistingEntries(cmd *exec.Cmd) ExistingEntries { func main() { if len(os.Args) < 4 || os.Args[1] == "" || os.Args[2] == "" || os.Args[3] == "" { panic("Error - Invalid Parameters.\n" + - "Required params: 1 - Nomulus config YAML path; 2 - config XML path; 3 - project name;") + "Required params: 1 - Nomulus config YAML path; 2 - config XML path; 3 - project name;\n" + + "Optional params: 5 - [--gke]") } // Nomulus YAML config file path, used to extract OAuth client ID. nomulusConfigFileLocation := os.Args[1] @@ -327,6 +342,11 @@ func main() { configFileLocation := os.Args[2] // Project name where to submit the tasks projectName = os.Args[3] + // Whether to deploy cloud scheduler tasks to run on GKE + if len(os.Args) > 4 && os.Args[4] == "--gke" { + gke = true + log.Default().Println("GKE mode enabled") + } log.Default().Println("YAML Filepath " + nomulusConfigFileLocation) yamlFile, err := os.Open(nomulusConfigFileLocation) @@ -339,6 +359,8 @@ func main() { if err := yaml.Unmarshal(byteValue, &yamlEntries); err != nil { panic("Failed to parse YAML file entries: " + err.Error()) } + + baseDomain = yamlEntries.GcpProject.BaseDomain clientId = yamlEntries.Auth.OauthClientId log.Default().Println("XML Filepath " + configFileLocation)