Skip to content

Commit

Permalink
Refactor version helper (kubernetes#4437)
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Aug 13, 2019
1 parent f2a0ab0 commit 016219d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
20 changes: 20 additions & 0 deletions internal/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import (
"io/ioutil"
"net/http"
"os"
"os/exec"
"strings"
"time"

"github.com/tv42/httpunix"
"k8s.io/klog"
)

// PID defines the location of the pid file used by NGINX
Expand Down Expand Up @@ -148,3 +150,21 @@ func buildUnixSocketClient(timeout time.Duration) *http.Client {
Transport: u,
}
}

// Version return details about NGINX
func Version() string {
flag := "-v"

if klog.V(2) {
flag = "-V"
}

cmd := exec.Command("nginx", flag)
out, err := cmd.CombinedOutput()
if err != nil {
klog.Errorf("unexpected error obtaining NGINX version: %v", err)
return "N/A"
}

return string(out)
}
15 changes: 10 additions & 5 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package version

import "fmt"
import (
"fmt"

"k8s.io/ingress-nginx/internal/nginx"
)

var (
// RELEASE returns the release version
Expand All @@ -31,9 +35,10 @@ var (
func String() string {
return fmt.Sprintf(`-------------------------------------------------------------------------------
NGINX Ingress controller
Release: %v
Build: %v
Repository: %v
Release: %v
Build: %v
Repository: %v
%v
-------------------------------------------------------------------------------
`, RELEASE, COMMIT, REPO)
`, RELEASE, COMMIT, REPO, nginx.Version())
}

0 comments on commit 016219d

Please sign in to comment.