Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 5 additions & 22 deletions cmd/nginx-ingress/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ import (
)

var (

// Injected during build
version string

// Info read from the binary
commitHash = "unknown"
commitTime = "unknown"
dirtyBuild = true

healthStatus = flag.Bool("health-status", false,
`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.
Useful for external health-checking of the Ingress Controller`)
Expand Down Expand Up @@ -187,17 +178,14 @@ var (
)

//gocyclo:ignore
func parseFlags(versionInfo string, binaryInfo string) {
func parseFlags() {
flag.Parse()

initialChecks()

if *versionFlag {
printVersionInfo(versionInfo, binaryInfo)
os.Exit(0)
}

glog.Infof("Starting NGINX Ingress Controller %v PlusFlag=%v", versionInfo, *nginxPlus)
glog.Info(binaryInfo)
initialChecks()

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

Expand Down Expand Up @@ -284,19 +272,14 @@ func initialChecks() {
}
}

glog.Infof("Starting with flags: %+q", os.Args[1:])

unparsed := flag.Args()
if len(unparsed) > 0 {
glog.Warningf("Ignoring unhandled arguments: %+q", unparsed)
}
}

// printVersionInfo prints the the version and binary info before exiting if the flag is set
func printVersionInfo(versionInfo string, binaryInfo string) {
fmt.Println(versionInfo)
fmt.Println(binaryInfo)
os.Exit(0)
}

// validationChecks checks the values for various flags
func validationChecks() {
healthStatusURIValidationError := validateLocation(*healthStatusURI)
Expand Down
10 changes: 8 additions & 2 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -37,9 +38,14 @@ import (
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

// Injected during build
var version string

func main() {
binaryInfo, versionInfo := getBuildInfo()
parseFlags(binaryInfo, versionInfo)
commitHash, commitTime, dirtyBuild := getBuildInfo()
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())

parseFlags()

config, kubeClient := createConfigAndKubeClient()

Expand Down
17 changes: 8 additions & 9 deletions cmd/nginx-ingress/utils.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import (
"fmt"
"runtime"
"runtime/debug"
)

func getBuildInfo() (string, string) {
func getBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
commitHash = "unknown"
commitTime = "unknown"
dirtyBuild = "unknown"

info, ok := debug.ReadBuildInfo()
if !ok {
return "", ""
return
}
for _, kv := range info.Settings {
switch kv.Key {
Expand All @@ -18,11 +20,8 @@ func getBuildInfo() (string, string) {
case "vcs.time":
commitTime = kv.Value
case "vcs.modified":
dirtyBuild = kv.Value == "true"
dirtyBuild = kv.Value
}
}
binaryInfo := fmt.Sprintf("Commit=%v Date=%v DirtyState=%v Arch=%v/%v Go=%v", commitHash, commitTime, dirtyBuild, runtime.GOOS, runtime.GOARCH, runtime.Version())
versionInfo := fmt.Sprintf("Version=%v", version)

return versionInfo, binaryInfo
return commitHash, commitTime, dirtyBuild
}