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

Add flags: timeout and delay-enrollment #534

Merged
merged 1 commit into from
May 15, 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
17 changes: 12 additions & 5 deletions so-elastic-agent-builder/source/so-elastic-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var fleetHostURLsList = ""
var fleetHostFlag string

var enrollmentToken, enrollmentTokenFlag string
var delayEnrollFlag bool
var timeoutFlag time.Duration

func check(err error, context string) {
if err != nil {
Expand Down Expand Up @@ -93,6 +95,8 @@ func main() {
// Allow runtime configuration
flag.StringVar(&enrollmentTokenFlag, "token", "", "Override default Enrollment Token")
flag.StringVar(&fleetHostFlag, "fleet", "", "Override default Fleet Host")
flag.BoolVar(&delayEnrollFlag, "delay-enroll", false, "Add delay enroll flag")
flag.DurationVar(&timeoutFlag, "timeout", 5*time.Minute, "Set the timeout duration (default: 5 minutes)")
flag.Parse()

if enrollmentTokenFlag != "" {
Expand Down Expand Up @@ -184,13 +188,17 @@ func main() {
arg4 := "--certificate-authorities=" + installPath + "soca.crt"
arg5 := "-n"

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3)
args := []string{arg1, arg2, arg3, arg4, arg5}
if delayEnrollFlag {
args = append(args, "--delay-enroll")
}

ctx, cancel := context.WithTimeout(context.Background(), timeoutFlag)
defer cancel()

cmd := exec.CommandContext(ctx, prg, arg1, arg2, arg3, arg4, arg5)
cmd := exec.CommandContext(ctx, prg, args...)

//strings.join the following
statusLogs("Executing the following: " + prg + " " + arg1 + " " + arg2 + " " + arg3 + " " + arg4 + " " + arg5)
statusLogs("Executing the following: " + prg + " " + strings.Join(args, " "))

output, err := cmd.CombinedOutput()
check(err, string(output))
Expand All @@ -199,5 +207,4 @@ func main() {

statusLogs("Elastic Agent installation completed")
fmt.Println("\n\nInstallation completed successfully.")

}
Loading