Refactor version helper (#4437)
This commit is contained in:
parent
f2a0ab035f
commit
016219d394
2 changed files with 30 additions and 5 deletions
|
@ -23,10 +23,12 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tv42/httpunix"
|
"github.com/tv42/httpunix"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PID defines the location of the pid file used by NGINX
|
// PID defines the location of the pid file used by NGINX
|
||||||
|
@ -148,3 +150,21 @@ func buildUnixSocketClient(timeout time.Duration) *http.Client {
|
||||||
Transport: u,
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,11 @@ limitations under the License.
|
||||||
|
|
||||||
package version
|
package version
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"k8s.io/ingress-nginx/internal/nginx"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// RELEASE returns the release version
|
// RELEASE returns the release version
|
||||||
|
@ -31,9 +35,10 @@ var (
|
||||||
func String() string {
|
func String() string {
|
||||||
return fmt.Sprintf(`-------------------------------------------------------------------------------
|
return fmt.Sprintf(`-------------------------------------------------------------------------------
|
||||||
NGINX Ingress controller
|
NGINX Ingress controller
|
||||||
Release: %v
|
Release: %v
|
||||||
Build: %v
|
Build: %v
|
||||||
Repository: %v
|
Repository: %v
|
||||||
|
%v
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
`, RELEASE, COMMIT, REPO)
|
`, RELEASE, COMMIT, REPO, nginx.Version())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue