Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor version helper #4437

Merged
merged 1 commit into from
Aug 13, 2019
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
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())
}