Skip to content

Commit

Permalink
Make the cloud scheduler deployer GKE-aware
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jianglai committed Sep 19, 2024
1 parent c47f821 commit 21b91a7
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions release/builder/deployCloudSchedulerAndQueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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 " +
Expand All @@ -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(),
Expand Down Expand Up @@ -319,14 +333,20 @@ 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]
// XML config file path
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)
Expand All @@ -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)
Expand Down

0 comments on commit 21b91a7

Please sign in to comment.