Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kvij committed Sep 19, 2023
1 parent 0467944 commit 16b6280
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ func kill(exitCode int) {
case config.NeverKillIstioOnFailure && exitCode != 0:
log(fmt.Sprintf(logLineUnformatted, "Skipping Istio kill", "NEVER_KILL_ISTIO_ON_FAILURE is true", exitCode))
os.Exit(exitCode)
case config.IstioQuitAPI == "":
// No istio API sent, fallback to Pkill method
log(fmt.Sprintf(logLineUnformatted, "Stopping Istio with pkill", "ISTIO_QUIT_API is not set", exitCode))
killGenericEndpoints()
killIstioWithPkill()
default:
// Stop istio using api
log(fmt.Sprintf(logLineUnformatted, "Stopping Istio with API", "ISTIO_QUIT_API is set", exitCode))
Expand Down
20 changes: 20 additions & 0 deletions scuttle_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package main

import (
"fmt"
"net/url"
"os"
"strings"
"time"
)

const defaultAdminAPIPort = 15000
const defaultQuitAPIPort = 15020

// ScuttleConfig ... represents Scuttle's configuration based on environment variables or defaults.
type ScuttleConfig struct {
LoggingEnabled bool
Expand Down Expand Up @@ -43,6 +47,10 @@ func getConfig() ScuttleConfig {
QuitWithoutEnvoyTimeout: getDurationFromEnv("QUIT_WITHOUT_ENVOY_TIMEOUT", time.Duration(0), loggingEnabled),
}

if config.IstioQuitAPI == "" {
config.IstioQuitAPI = replacePort(config.EnvoyAdminAPI, defaultAdminAPIPort, defaultQuitAPIPort)
}

return config
}

Expand Down Expand Up @@ -122,3 +130,15 @@ func getDurationFromEnv(name string, defaultVal time.Duration, logEnabled bool)

return defaultVal
}

// replacePort returns a URL with the port replaced when the sourceURL is valid and has the original port set.
// If the original port does not match or the sourceURL is invalid an empty string is returned.
func replacePort(sourceURL string, original, replacement int) string {
u, err := url.Parse(sourceURL)
if err != nil || (u.Port() != fmt.Sprintf("%d", original)) {
return ""
}

u.Host = fmt.Sprintf("%s:%d", u.Hostname(), replacement)
return u.String()
}

0 comments on commit 16b6280

Please sign in to comment.