Skip to content

Commit c7e31dc

Browse files
lucacomecoolbry95
authored andcommitted
Always print build info, add flags used (nginx#3231)
1 parent 9f40d88 commit c7e31dc

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

cmd/nginx-ingress/flags.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ import (
1515
)
1616

1717
var (
18-
19-
// Injected during build
20-
version string
21-
22-
// Info read from the binary
23-
commitHash = "unknown"
24-
commitTime = "unknown"
25-
dirtyBuild = true
26-
2718
healthStatus = flag.Bool("health-status", false,
2819
`Add a location based on the value of health-status-uri to the default server. The location responds with the 200 status code for any request.
2920
Useful for external health-checking of the Ingress Controller`)
@@ -187,17 +178,14 @@ var (
187178
)
188179

189180
//gocyclo:ignore
190-
func parseFlags(versionInfo string, binaryInfo string) {
181+
func parseFlags() {
191182
flag.Parse()
192183

193-
initialChecks()
194-
195184
if *versionFlag {
196-
printVersionInfo(versionInfo, binaryInfo)
185+
os.Exit(0)
197186
}
198187

199-
glog.Infof("Starting NGINX Ingress Controller %v PlusFlag=%v", versionInfo, *nginxPlus)
200-
glog.Info(binaryInfo)
188+
initialChecks()
201189

202190
watchNamespaces = strings.Split(*watchNamespace, ",")
203191

@@ -284,19 +272,14 @@ func initialChecks() {
284272
}
285273
}
286274

275+
glog.Infof("Starting with flags: %+q", os.Args[1:])
276+
287277
unparsed := flag.Args()
288278
if len(unparsed) > 0 {
289279
glog.Warningf("Ignoring unhandled arguments: %+q", unparsed)
290280
}
291281
}
292282

293-
// printVersionInfo prints the the version and binary info before exiting if the flag is set
294-
func printVersionInfo(versionInfo string, binaryInfo string) {
295-
fmt.Println(versionInfo)
296-
fmt.Println(binaryInfo)
297-
os.Exit(0)
298-
}
299-
300283
// validationChecks checks the values for various flags
301284
func validationChecks() {
302285
healthStatusURIValidationError := validateLocation(*healthStatusURI)

cmd/nginx-ingress/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"os/signal"
10+
"runtime"
1011
"strings"
1112
"syscall"
1213
"time"
@@ -37,9 +38,14 @@ import (
3738
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
3839
)
3940

41+
// Injected during build
42+
var version string
43+
4044
func main() {
41-
binaryInfo, versionInfo := getBuildInfo()
42-
parseFlags(binaryInfo, versionInfo)
45+
commitHash, commitTime, dirtyBuild := getBuildInfo()
46+
fmt.Printf("NGINX Ingress Controller Version=%v Commit=%v Date=%v DirtyState=%v Arch=%v/%v Go=%v\n", version, commitHash, commitTime, dirtyBuild, runtime.GOOS, runtime.GOARCH, runtime.Version())
47+
48+
parseFlags()
4349

4450
config, kubeClient := createConfigAndKubeClient()
4551

cmd/nginx-ingress/utils.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package main
22

33
import (
4-
"fmt"
5-
"runtime"
64
"runtime/debug"
75
)
86

9-
func getBuildInfo() (string, string) {
7+
func getBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
8+
commitHash = "unknown"
9+
commitTime = "unknown"
10+
dirtyBuild = "unknown"
11+
1012
info, ok := debug.ReadBuildInfo()
1113
if !ok {
12-
return "", ""
14+
return
1315
}
1416
for _, kv := range info.Settings {
1517
switch kv.Key {
@@ -18,11 +20,8 @@ func getBuildInfo() (string, string) {
1820
case "vcs.time":
1921
commitTime = kv.Value
2022
case "vcs.modified":
21-
dirtyBuild = kv.Value == "true"
23+
dirtyBuild = kv.Value
2224
}
2325
}
24-
binaryInfo := fmt.Sprintf("Commit=%v Date=%v DirtyState=%v Arch=%v/%v Go=%v", commitHash, commitTime, dirtyBuild, runtime.GOOS, runtime.GOARCH, runtime.Version())
25-
versionInfo := fmt.Sprintf("Version=%v", version)
26-
27-
return versionInfo, binaryInfo
26+
return commitHash, commitTime, dirtyBuild
2827
}

0 commit comments

Comments
 (0)