Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 016219d

Browse files
authoredAug 13, 2019
Refactor version helper (kubernetes#4437)
1 parent f2a0ab0 commit 016219d

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed
 

‎internal/nginx/main.go

+20
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import (
2323
"io/ioutil"
2424
"net/http"
2525
"os"
26+
"os/exec"
2627
"strings"
2728
"time"
2829

2930
"github.com/tv42/httpunix"
31+
"k8s.io/klog"
3032
)
3133

3234
// PID defines the location of the pid file used by NGINX
@@ -148,3 +150,21 @@ func buildUnixSocketClient(timeout time.Duration) *http.Client {
148150
Transport: u,
149151
}
150152
}
153+
154+
// Version return details about NGINX
155+
func Version() string {
156+
flag := "-v"
157+
158+
if klog.V(2) {
159+
flag = "-V"
160+
}
161+
162+
cmd := exec.Command("nginx", flag)
163+
out, err := cmd.CombinedOutput()
164+
if err != nil {
165+
klog.Errorf("unexpected error obtaining NGINX version: %v", err)
166+
return "N/A"
167+
}
168+
169+
return string(out)
170+
}

‎version/version.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ limitations under the License.
1616

1717
package version
1818

19-
import "fmt"
19+
import (
20+
"fmt"
21+
22+
"k8s.io/ingress-nginx/internal/nginx"
23+
)
2024

2125
var (
2226
// RELEASE returns the release version
@@ -31,9 +35,10 @@ var (
3135
func String() string {
3236
return fmt.Sprintf(`-------------------------------------------------------------------------------
3337
NGINX Ingress controller
34-
Release: %v
35-
Build: %v
36-
Repository: %v
38+
Release: %v
39+
Build: %v
40+
Repository: %v
41+
%v
3742
-------------------------------------------------------------------------------
38-
`, RELEASE, COMMIT, REPO)
43+
`, RELEASE, COMMIT, REPO, nginx.Version())
3944
}

0 commit comments

Comments
 (0)
This repository has been archived.