Skip to content

Commit

Permalink
Add version flag (#125)
Browse files Browse the repository at this point in the history
Add the version flag using the go-commons code.

Signed-off-by: Joe Talerico <[email protected]>
Co-authored-by: Joe Talerico <[email protected]>
  • Loading branch information
jtaleric and Joe Talerico authored Dec 15, 2023
1 parent 4dfa1c5 commit cd902f0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ BIN_DIR = bin
BIN_PATH = $(BIN_DIR)/$(ARCH)/$(BIN)
CGO = 0
RHEL_VERSION = ubi9
CONTAINER ?= podman
CONTAINER_BUILD ?= podman build --force-rm
CONTAINER_NS ?= quay.io/cloud-bulldozer/netperf

# k8s-netperf version
GIT_COMMIT = $(shell git rev-parse HEAD)
BUILD_DATE = $(shell date '+%Y-%m-%d-%H:%M:%S')
CMD_VERSION= github.com/cloud-bulldozer/go-commons/version
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(BRANCH),HEAD)
VERSION := $(shell git describe --tags --abbrev=0)
else
VERSION := $(BRANCH)
endif

all: build container-build

build: $(BIN_PATH)
Expand All @@ -31,14 +43,14 @@ gha-build:
@echo "Building the container image for GHA"
$(CONTAINER_BUILD) -f containers/Containerfile \
--build-arg RHEL_VERSION=$(RHEL_VERSION) --platform=linux/amd64,linux/arm64,linux/ppc64le,linux/s390x \
-t $(CONTAINER_NS) ./containers --manifest=$(CONTAINER_NS):latest
-t $(CONTAINER_NS) ./containers --manifest=$(CONTAINER_NS)-manifest:latest

gha-push: build gha-build
@echo "Pushing Container Images & manifest"
$(CONTAINER_BUILD) manifest push
$(CONTAINER) manifest push $(CONTAINER_NS)-manifest:latest $(CONTAINER_NS)

clean: $(BIN_PATH)
rm -rf bin/$(ARCH)

$(BIN_PATH): $(SOURCES)
GOARCH=$(ARCH) CGO_ENABLED=$(CGO) go build -v -o $(BIN_PATH) ./cmd/k8s-netperf
GOARCH=$(ARCH) CGO_ENABLED=$(CGO) go build -v -ldflags "-X $(CMD_VERSION).GitCommit=$(GIT_COMMIT) -X $(CMD_VERSION).BuildDate=$(BUILD_DATE) -X $(CMD_VERSION).Version=$(VERSION)" -o $(BIN_PATH) ./cmd/k8s-netperf
14 changes: 13 additions & 1 deletion cmd/k8s-netperf/k8s-netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cloud-bulldozer/go-commons/indexers"
ocpmetadata "github.com/cloud-bulldozer/go-commons/ocp-metadata"
"github.com/cloud-bulldozer/go-commons/prometheus"
cmdVersion "github.com/cloud-bulldozer/go-commons/version"
"github.com/cloud-bulldozer/k8s-netperf/pkg/archive"
"github.com/cloud-bulldozer/k8s-netperf/pkg/config"
"github.com/cloud-bulldozer/k8s-netperf/pkg/iperf"
Expand Down Expand Up @@ -47,12 +48,21 @@ var (
showMetrics bool
tcpt float64
json bool
version bool
)

var rootCmd = &cobra.Command{
Use: "k8s-netperf",
Short: "A tool to run network performance tests in Kubernetes cluster",
Run: func(cmd *cobra.Command, args []string) {
if version {
fmt.Println("Version:", cmdVersion.Version)
fmt.Println("Git Commit:", cmdVersion.GitCommit)
fmt.Println("Build Date:", cmdVersion.BuildDate)
fmt.Println("Go Version:", cmdVersion.GoVersion)
fmt.Println("OS/Arch:", cmdVersion.OsArch)
os.Exit(0)
}

uid := ""
if len(id) > 0 {
Expand All @@ -79,7 +89,6 @@ var rootCmd = &cobra.Command{
}
cfg = cf
}

// Read in k8s config
kconfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
Expand Down Expand Up @@ -137,6 +146,8 @@ var rootCmd = &cobra.Command{
}

var sr result.ScenarioResults
sr.Version = cmdVersion.Version
sr.GitCommit = cmdVersion.GitCommit
// If the client and server needs to be across zones
lz, zones, _ := k8s.GetZone(client)
nodesInZone := zones[lz]
Expand Down Expand Up @@ -481,6 +492,7 @@ func main() {
rootCmd.Flags().StringVar(&searchURL, "search", "", "OpenSearch URL, if you have auth, pass in the format of https://user:pass@url:port")
rootCmd.Flags().BoolVar(&showMetrics, "metrics", false, "Show all system metrics retrieved from prom")
rootCmd.Flags().Float64Var(&tcpt, "tcp-tolerance", 10, "Allowed %diff from hostNetwork to podNetwork, anything above tolerance will result in k8s-netperf exiting 1.")
rootCmd.Flags().BoolVar(&version, "version", false, "k8s-netperf version")

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Doc struct {
LtcyMetric string `json:"ltcyMetric"`
TCPRetransmit float64 `json:"tcpRetransmits"`
UDPLossPercent float64 `json:"udpLossPercent"`
ToolVersion string `json:"toolVersion"`
ToolGitCommit string `json:"toolGitCommit"`
Metadata result.Metadata `json:"metadata"`
ServerNodeCPU metrics.NodeCPU `json:"serverCPU"`
ServerPodCPU []metrics.PodCPU `json:"serverPods"`
Expand Down Expand Up @@ -87,6 +89,8 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) {
d := Doc{
UUID: uuid,
Timestamp: time,
ToolVersion: sr.Version,
ToolGitCommit: sr.GitCommit,
Driver: r.Driver,
HostNetwork: r.HostNetwork,
Parallelism: r.Parallelism,
Expand Down
4 changes: 3 additions & 1 deletion pkg/results/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ type Data struct {

// ScenarioResults each scenario could have multiple results
type ScenarioResults struct {
Results []Data
Results []Data
Version string
GitCommit string
Metadata
}

Expand Down

0 comments on commit cd902f0

Please sign in to comment.