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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the cloud scheduler deployer GKE-aware #2562

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
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
Loading