Merge pull request #1585 from aledbf/add-version-flag

Add version flag
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-10-25 08:28:23 -03:00 committed by GitHub
commit 61d32aef0f
3 changed files with 20 additions and 1 deletions

View file

@ -183,5 +183,5 @@ To detect which version of the ingress controller is running, exec into the pod
```console
POD_NAMESPACE=ingress-nginx
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app=ingress-nginx -o jsonpath={.items[0].metadata.name})
kubectl exec -it $POD_NAME -n $POD_NAMESPACE /nginx-ingress-controller version
kubectl exec -it $POD_NAME -n $POD_NAMESPACE /nginx-ingress-controller --version
```

View file

@ -104,6 +104,9 @@ func NewIngressController(backend ingress.Controller) *GenericController {
useNodeInternalIP = flags.Bool("report-node-internal-ip-address", false,
`Defines if the nodes IP address to be returned in the ingress status should be the internal instead of the external IP address`)
showVersion = flags.Bool("version", false,
`Shows release information about the NGINX Ingress controller`)
)
flags.AddGoFlagSet(flag.CommandLine)
@ -112,6 +115,12 @@ func NewIngressController(backend ingress.Controller) *GenericController {
// Workaround for this issue:
// https://github.com/kubernetes/kubernetes/issues/17162
flag.CommandLine.Parse([]string{})
if *showVersion {
fmt.Println(backend.Info().String())
os.Exit(0)
}
backend.OverrideFlags(flags)
flag.Set("logtostderr", "true")

View file

@ -17,6 +17,7 @@ limitations under the License.
package ingress
import (
"fmt"
"time"
"github.com/spf13/pflag"
@ -130,6 +131,15 @@ type BackendInfo struct {
Repository string `json:"repository"`
}
func (bi BackendInfo) String() string {
return fmt.Sprintf(`
Name: %v
Release: %v
Build: %v
Repository: %v
`, bi.Name, bi.Release, bi.Build, bi.Repository)
}
// Configuration holds the definition of all the parts required to describe all
// ingresses reachable by the ingress controller (using a filter by namespace)
type Configuration struct {