* Add NMI and MIC versions to binary version var

* Add NMI and MIC version to binary build

* fix typo in makefile

* add log line for mic.go

* add version info flag

* use Infof instead of Info
This commit is contained in:
Cecile Robert-Michon 2019-05-17 14:30:54 -07:00 коммит произвёл Krishnakumar R
Родитель 31748d7aec
Коммит 9e675dbbf7
5 изменённых файлов: 25 добавлений и 9 удалений

Просмотреть файл

@ -15,7 +15,8 @@ MIC_VERSION ?= $(DEFAULT_VERSION)
DEMO_VERSION ?= $(DEFAULT_VERSION)
IDENTITY_VALIDATOR_VERSION ?= $(DEFAULT_VERSION)
VERSION_VAR := $(REPO_PATH)/version.Version
NMI_VERSION_VAR := $(REPO_PATH)/version.NMIVersion
MIC_VERSION_VAR := $(REPO_PATH)/version.MICVersion
GIT_VAR := $(REPO_PATH)/version.GitCommit
BUILD_DATE_VAR := $(REPO_PATH)/version.BuildDate
BUILD_DATE := $$(date +%Y-%m-%d-%H:%M)
@ -33,7 +34,7 @@ else
endif
endif
GO_BUILD_OPTIONS := --tags "netgo osusergo" -ldflags "-s -X $(VERSION_VAR)=$(NMI_VERSION) -X $(GIT_VAR)=$(GIT_HASH) -X $(BUILD_DATE_VAR)=$(BUILD_DATE) -extldflags '-static'"
GO_BUILD_OPTIONS := --tags "netgo osusergo" -ldflags "-s -X $(NMI_VERSION_VAR)=$(NMI_VERSION) -X $(MIC_VERSION_VAR)=$(MIC_VERSION) -X $(GIT_VAR)=$(GIT_HASH) -X $(BUILD_DATE_VAR)=$(BUILD_DATE) -extldflags '-static'"
E2E_TEST_OPTIONS := -count=1 -v -timeout 24h -ginkgo.failFast
# useful for other docker repos
@ -94,7 +95,7 @@ deepcopy-gen:
.PHONY: image-nmi
image-nmi:
docker build -t "$(REGISTRY)/$(NMI_IMAGE)" --build-arg NMI_VEARSION="$(NMI_VERSION)" --target=nmi .
docker build -t "$(REGISTRY)/$(NMI_IMAGE)" --build-arg NMI_VERSION="$(NMI_VERSION)" --target=nmi .
.PHONY: image-mic
image-mic:

Просмотреть файл

@ -5,6 +5,7 @@ import (
"os"
"github.com/Azure/aad-pod-identity/pkg/mic"
"github.com/Azure/aad-pod-identity/version"
"github.com/golang/glog"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
@ -14,6 +15,7 @@ var (
kubeconfig string
cloudconfig string
forceNamespaced bool
versionInfo bool
)
func main() {
@ -21,7 +23,12 @@ func main() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to the kube config")
flag.StringVar(&cloudconfig, "cloudconfig", "", "Path to cloud config e.g. Azure.json file")
flag.BoolVar(&forceNamespaced, "forceNamespaced", false, "Forces namespaced identities, binding, and assignment")
flag.BoolVar(&versionInfo, "version", false, "Prints the version information")
flag.Parse()
if versionInfo {
version.PrintVersionAndExit()
}
glog.Infof("Starting mic process. Version: %v. Build date: %v", version.MICVersion, version.BuildDate)
if cloudconfig == "" {
glog.Fatalf("Could not get the cloud config")
}

Просмотреть файл

@ -5,6 +5,7 @@ import (
"github.com/Azure/aad-pod-identity/pkg/k8s"
server "github.com/Azure/aad-pod-identity/pkg/nmi/server"
"github.com/Azure/aad-pod-identity/version"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
@ -18,6 +19,7 @@ const (
var (
debug = pflag.Bool("debug", true, "sets log to debug level")
versionInfo = pflag.Bool("version", false, "prints the version information")
nmiPort = pflag.String("nmi-port", defaultNmiPort, "NMI application port")
metadataIP = pflag.String("metadata-ip", defaultMetadataIP, "instance metadata host ip")
metadataPort = pflag.String("metadata-port", defaultMetadataPort, "instance metadata host ip")
@ -29,10 +31,13 @@ var (
func main() {
pflag.Parse()
if *versionInfo {
version.PrintVersionAndExit()
}
if *debug {
log.SetLevel(log.DebugLevel)
}
log.Info("starting nmi process")
log.Infof("Starting nmi process. Version: %v. Build date: %v", version.NMIVersion, version.BuildDate)
client, err := k8s.NewKubeClient()
if err != nil {
log.Fatalf("%+v", err)

Просмотреть файл

@ -14,7 +14,7 @@ import (
"github.com/Azure/aad-pod-identity/pkg/crd"
"github.com/Azure/aad-pod-identity/pkg/pod"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/informers"
@ -49,7 +49,7 @@ type ClientInt interface {
}
func NewMICClient(cloudconfig string, config *rest.Config, isNamespaced bool) (*Client, error) {
glog.Infof("Starting to create the pod identity client. Version: %v. Build date: %v", version.Version, version.BuildDate)
glog.Infof("Starting to create the pod identity client. Version: %v. Build date: %v", version.MICVersion, version.BuildDate)
clientSet := kubernetes.NewForConfigOrDie(config)
informer := informers.NewSharedInformerFactory(clientSet, 30*time.Second)

Просмотреть файл

@ -11,11 +11,14 @@ var BuildDate string
// GitCommit is the commit hash when the binary was built
var GitCommit string
// Version is the version of the binary
var Version string
// MICVersion is the version of the MIC component
var MICVersion string
// NMIVersion is the version of the NMI component
var NMIVersion string
// PrintVersionAndExit prints the version and exits
func PrintVersionAndExit() {
fmt.Printf("Version: %s - Commit: %s - Date: %s\n", Version, GitCommit, BuildDate)
fmt.Printf("MIC Version: %s - NMI Version: %s - Commit: %s - Date: %s\n", MICVersion, NMIVersion, GitCommit, BuildDate)
os.Exit(0)
}