From 7cc42f2df843687139301d70d3e14c9c3e7582ef Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 25 Oct 2017 01:06:48 -0300 Subject: [PATCH] Add version flag --- deploy/README.md | 2 +- pkg/ingress/controller/launch.go | 9 +++++++++ pkg/ingress/types.go | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/deploy/README.md b/deploy/README.md index a5bda3d67..bd2684326 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -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 ``` diff --git a/pkg/ingress/controller/launch.go b/pkg/ingress/controller/launch.go index 57d0d253a..d7b6aef0f 100644 --- a/pkg/ingress/controller/launch.go +++ b/pkg/ingress/controller/launch.go @@ -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") diff --git a/pkg/ingress/types.go b/pkg/ingress/types.go index 840dc9b3d..37a552f97 100644 --- a/pkg/ingress/types.go +++ b/pkg/ingress/types.go @@ -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 {