Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Log binary versions #216

Merged
merged 7 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions cmd/mic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,14 +15,20 @@ var (
kubeconfig string
cloudconfig string
forceNamespaced bool
versionInfo bool
)

func main() {
defer glog.Flush()
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this what you meant @kkmsft ?

}
glog.Info("Starting mic process. Version: %v. Build date: %v", version.MICVersion, version.BuildDate)
CecileRobertMichon marked this conversation as resolved.
Show resolved Hide resolved
if cloudconfig == "" {
glog.Fatalf("Could not get the cloud config")
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/nmi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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")
Expand All @@ -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.Info("Starting nmi process. Version: %v. Build date: %v", version.NMIVersion, version.BuildDate)
kkmsft marked this conversation as resolved.
Show resolved Hide resolved
CecileRobertMichon marked this conversation as resolved.
Show resolved Hide resolved
client, err := k8s.NewKubeClient()
if err != nil {
log.Fatalf("%+v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mic/mic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be used in case of -v command line option for both mmi and mic. Would be a good way to find out the comparable nmi/mic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really want to exit the process after printing the version?

Copy link
Contributor

@kkmsft kkmsft May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking if so if some one runs

nmi -v
or
mic -v

this is the only which needs to be called. In that case the exit can be left there as is - thoughts ?

Also wondering why the fmt was used here originally, does this assume that blog is not initialized or some other rule to be followed in version.go - any ideas ?

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)
}