Skip to content

Commit

Permalink
Add --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sathieu committed Feb 22, 2018
1 parent 0ffce37 commit da6a2ba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ ifeq ($(GOHOSTOS),darwin)
SED_I=sed -i ''
endif

REPO_INFO=$(shell git config --get remote.origin.url)

ifndef COMMIT
COMMIT := git-$(shell git rev-parse --short HEAD)
endif

PKG=github.com/lemonldap-ng-controller/lemonldap-ng-controller

ARCH ?= $(shell go env GOARCH)
Expand Down Expand Up @@ -130,7 +136,7 @@ clean:
.PHONY: build
build: clean
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -a -installsuffix cgo \
-ldflags "-s -w" \
-ldflags "-s -w -X ${PKG}/version.RELEASE=${TAG} -X ${PKG}/version.COMMIT=${COMMIT} -X ${PKG}/version.REPO=${REPO_INFO}" \
-o ${TEMP_DIR}/rootfs/lemonldap-ng-controller ${PKG}/cmd

.PHONY: verify-all
Expand All @@ -139,7 +145,6 @@ verify-all:

.PHONY: test
test:
@echo "+ $@"
@go test -v -race -tags "$(BUILDTAGS) cgo" $(shell go list ${PKG}/... | grep -v vendor | grep -v '/test/e2e')

.PHONY: e2e-image
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Usage of /lemonldap-ng-controller:
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
--sync-period duration Relist and confirm cloud resources this often (default 10m0s)
-v, --v Level log level for V logs
--version Shows release information about the LemonLDAP::NG controller
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
--watch-namespace string Namespace to watch for Ingress. Default is to watch all namespaces
```
Expand Down
10 changes: 10 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main

import (
goflag "flag"
"fmt"
"os"
"time"

Expand All @@ -36,13 +37,15 @@ import (
fsos "github.com/lemonldap-ng-controller/lemonldap-ng-controller/internal/filesystem/os"
"github.com/lemonldap-ng-controller/lemonldap-ng-controller/internal/lemonldapng/converter"
"github.com/lemonldap-ng-controller/lemonldap-ng-controller/internal/signals"
"github.com/lemonldap-ng-controller/lemonldap-ng-controller/version"
)

var (
config *controller.Configuration = &controller.Configuration{
FS: &fsos.Filesystem{},
}
convertMode bool
versionMode bool
)

func main() {
Expand All @@ -64,6 +67,12 @@ func main() {
// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler()

if versionMode {
fmt.Println(version.String())
return
}
glog.Infof(version.Short())

if convertMode {
err := converter.Run(config.ConfigMapName, os.Stdin, os.Stdout)
if err != nil {
Expand Down Expand Up @@ -104,4 +113,5 @@ func init() {
flag.BoolVar(&config.ForceNamespaceIsolation, "force-namespace-isolation", false, "Force namespace isolation. This flag is required to avoid the reference of secrets or configmaps located in a different namespace than the specified in the flag --watch-namespace")
flag.StringVar(&config.LemonLDAPConfigurationDirectory, "lemonldap-ng-configuration-directory", "/var/lib/lemonldap-ng/conf", "LemonLDAP::NG configuration directory")
flag.BoolVar(&convertMode, "convert", false, "Convert lmConf-n.js from standard input to ConfigMap")
flag.BoolVar(&versionMode, "version", false, "Shows release information about the LemonLDAP::NG controller")
}
44 changes: 44 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2018 Mathieu Parent <math.parent@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import "fmt"

var (
// RELEASE returns the release version
RELEASE = "UNKNOWN"
// REPO returns the git repository URL
REPO = "UNKNOWN"
// COMMIT returns the short sha from git
COMMIT = "UNKNOWN"
)

// String returns information about the release.
func String() string {
return fmt.Sprintf(`-------------------------------------------------------------------------------
LemonLDAP::NG controller
Release: %v
Build: %v
Repository: %v
-------------------------------------------------------------------------------
`, RELEASE, COMMIT, REPO)
}

// Short returns one-line information about the release.
func Short() string {
return fmt.Sprintf(`LemonLDAP::NG controller %v (build: %v, repository: %v)`, RELEASE, COMMIT, REPO)
}

0 comments on commit da6a2ba

Please sign in to comment.