mirror of
https://github.com/google/nomulus
synced 2026-01-03 03:35: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:
@@ -30,8 +30,12 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var gke bool = false
|
||||||
|
|
||||||
var projectName string
|
var projectName string
|
||||||
|
|
||||||
|
var baseDomain string
|
||||||
|
|
||||||
var clientId string
|
var clientId string
|
||||||
|
|
||||||
const GcpLocation = "us-central1"
|
const GcpLocation = "us-central1"
|
||||||
@@ -80,6 +84,9 @@ type TasksSyncManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type YamlEntries struct {
|
type YamlEntries struct {
|
||||||
|
GcpProject struct {
|
||||||
|
BaseDomain string `yaml:"baseDomain"`
|
||||||
|
} `yaml:"gcpProject"`
|
||||||
Auth struct {
|
Auth struct {
|
||||||
OauthClientId string `yaml:"oauthClientId"`
|
OauthClientId string `yaml:"oauthClientId"`
|
||||||
} `yaml:"auth"`
|
} `yaml:"auth"`
|
||||||
@@ -169,7 +176,7 @@ func (manager TasksSyncManager) getXmlEntries() []Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (manager TasksSyncManager) getArgs(task Task, operationType string) []string {
|
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
|
var description string
|
||||||
if len(task.Description) > 499 {
|
if len(task.Description) > 499 {
|
||||||
log.Default().Println("Task description exceeds the allowed length of " +
|
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
|
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{
|
return []string{
|
||||||
"--project", projectName,
|
"--project", projectName,
|
||||||
"scheduler", "jobs", operationType,
|
"scheduler", "jobs", operationType,
|
||||||
"http", task.Name,
|
"http", task.Name,
|
||||||
"--location", GcpLocation,
|
"--location", GcpLocation,
|
||||||
"--schedule", task.Schedule,
|
"--schedule", task.Schedule,
|
||||||
"--uri", fmt.Sprintf("https://%s-dot-%s.appspot.com%s", service, projectName, strings.TrimSpace(task.URL)),
|
"--uri", uri,
|
||||||
"--description", description,
|
"--description", description,
|
||||||
"--http-method", "get",
|
"--http-method", "get",
|
||||||
"--oidc-service-account-email", getCloudSchedulerServiceAccountEmail(),
|
"--oidc-service-account-email", getCloudSchedulerServiceAccountEmail(),
|
||||||
@@ -319,7 +333,8 @@ func getExistingEntries(cmd *exec.Cmd) ExistingEntries {
|
|||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 4 || os.Args[1] == "" || os.Args[2] == "" || os.Args[3] == "" {
|
if len(os.Args) < 4 || os.Args[1] == "" || os.Args[2] == "" || os.Args[3] == "" {
|
||||||
panic("Error - Invalid Parameters.\n" +
|
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.
|
// Nomulus YAML config file path, used to extract OAuth client ID.
|
||||||
nomulusConfigFileLocation := os.Args[1]
|
nomulusConfigFileLocation := os.Args[1]
|
||||||
@@ -327,6 +342,11 @@ func main() {
|
|||||||
configFileLocation := os.Args[2]
|
configFileLocation := os.Args[2]
|
||||||
// Project name where to submit the tasks
|
// Project name where to submit the tasks
|
||||||
projectName = os.Args[3]
|
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)
|
log.Default().Println("YAML Filepath " + nomulusConfigFileLocation)
|
||||||
yamlFile, err := os.Open(nomulusConfigFileLocation)
|
yamlFile, err := os.Open(nomulusConfigFileLocation)
|
||||||
@@ -339,6 +359,8 @@ func main() {
|
|||||||
if err := yaml.Unmarshal(byteValue, &yamlEntries); err != nil {
|
if err := yaml.Unmarshal(byteValue, &yamlEntries); err != nil {
|
||||||
panic("Failed to parse YAML file entries: " + err.Error())
|
panic("Failed to parse YAML file entries: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseDomain = yamlEntries.GcpProject.BaseDomain
|
||||||
clientId = yamlEntries.Auth.OauthClientId
|
clientId = yamlEntries.Auth.OauthClientId
|
||||||
|
|
||||||
log.Default().Println("XML Filepath " + configFileLocation)
|
log.Default().Println("XML Filepath " + configFileLocation)
|
||||||
|
|||||||
Reference in New Issue
Block a user