1
0
mirror of https://github.com/google/nomulus synced 2025-12-23 06:15:42 +00:00

Make the cloud scheduler deployer GKE-aware (#2562)

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.
This commit is contained in:
Lai Jiang
2024-09-19 12:28:08 -04:00
committed by GitHub
parent c47f821754
commit e167b4b753

View File

@@ -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)