Skip to content

Commit

Permalink
Refactor the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
krishvoor committed Jul 20, 2023
1 parent 0a412d0 commit d21fefd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 51 deletions.
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
GIT_COMMIT = $(shell git rev-parse HEAD)

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(BRANCH),)
VERSION := $(shell git describe --tags --abbrev=0)
else
VERSION := $(subst main,latest,$(BRANCH))
endif

SOURCES := $(shell find . -type f -name "*.go")
BUILD_DATE = $(shell date '+%Y-%m-%d-%H:%M:%S')
INGRESS_PERF_VERSION= github.com/cloud-bulldozer/kube-burner/pkg/version

BIN_DIR = bin
BIN_NAME = ingress-perf
BIN_PATH = $(BIN_DIR)/$(BIN_NAME)
SOURCES = $(shell find . -type f -name "*.go")
CGO = 0

.PHONY: build lint clean

Expand All @@ -10,7 +24,7 @@ all: lint build
build: $(BIN_PATH)

$(BIN_PATH): $(SOURCES)
CGO_ENABLED=0 go build -o $(BIN_PATH) cmd/ingress-perf.go
GOARCH=$(go env GOARCH) CGO_ENABLED=$(CGO) go build -v -ldflags "-X $(INGRESS_PERF_VERSION).GitCommit=$(GIT_COMMIT) -X $(INGRESS_PERF_VERSION).Version=$(VERSION)" -o $(BIN_PATH) cmd/ingress-perf.go

clean:
rm -Rf $(BIN_DIR)
Expand Down
53 changes: 10 additions & 43 deletions cmd/ingress-perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package main

import (
"bytes"
"fmt"
"os/exec"
"strings"

"github.com/cloud-bulldozer/go-commons/indexers"
"github.com/cloud-bulldozer/ingress-perf/pkg/config"
_ "github.com/cloud-bulldozer/ingress-perf/pkg/log"
"github.com/cloud-bulldozer/ingress-perf/pkg/runner"
"github.com/cloud-bulldozer/kube-burner/pkg/version"
uid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
Expand All @@ -34,6 +32,14 @@ var cmd = &cobra.Command{
Short: "Benchmark OCP ingress stack",
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "😎 Print the version number of ingress-perf",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s@%s \n", version.Version, version.GitCommit)
},
}

func run() *cobra.Command {
var cfg, uuid, baseUUID, esServer, esIndex, logLevel, baseIndex string
var cleanup bool
Expand Down Expand Up @@ -89,47 +95,8 @@ func run() *cobra.Command {
return cmd
}

func getGitInfo() (string, string) {

// Get the last released tag info
cmdTag := exec.Command("git", "describe", "--tags", "--abbrev=0")
var outTag bytes.Buffer
cmdTag.Stdout = &outTag
errTag := cmdTag.Run()
gitTag := "Unknown"
if errTag == nil {
gitTag = strings.TrimSpace(outTag.String())
}

// Get the last Commit Hash
cmdCommit := exec.Command("git", "rev-parse", "--short", "HEAD")
var outCommit bytes.Buffer
cmdCommit.Stdout = &outCommit
errCommit := cmdCommit.Run()
gitCommitHash := "Unknown"
if errCommit == nil {
gitCommitHash = strings.TrimSpace(outCommit.String())
}

return gitTag, gitCommitHash
}

func version() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the version number ",
SilenceErrors: true,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
gitTag, gitCommitHash := getGitInfo()
fmt.Printf("😎 Ingress-perf version is %s@%s \n", gitTag, gitCommitHash)
},
}
return cmd
}

func main() {
cmd.AddCommand(run(), version())
cmd.AddCommand(run(), versionCmd)
if err := cmd.Execute(); err != nil {
log.Fatal(err.Error())
}
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/cloud-bulldozer/ingress-perf
go 1.19

require (
github.com/cloud-bulldozer/go-commons v1.0.7
github.com/cloud-bulldozer/go-commons v1.0.9
github.com/cloud-bulldozer/kube-burner v1.7.3
github.com/openshift/api v0.0.0-20230414095907-0540dde8186d
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
github.com/satori/go.uuid v1.2.0
Expand All @@ -30,7 +31,7 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloud-bulldozer/go-commons v1.0.7 h1:fYwGUDf6rUANmAkMpBsL3q5c8thkR4i5bS6VdXm9gcQ=
github.com/cloud-bulldozer/go-commons v1.0.7/go.mod h1:4EOHI/QEs0tgNK4CroFGhEPDvImjRqsJvJZRY9fpSNk=
github.com/cloud-bulldozer/go-commons v1.0.9 h1:JNLcC36kk6Iml0JuBXUSyi8iR+ebgCeMWQScwnSUekw=
github.com/cloud-bulldozer/go-commons v1.0.9/go.mod h1:peHBEG4iCC9zKFzA4P16dpINZASWshsCy9T4dVpcBVI=
github.com/cloud-bulldozer/kube-burner v1.7.3 h1:CO+fk6HGjoBfT4pTQGjfiwRd23Fo5isUp7JUXpHhDT0=
github.com/cloud-bulldozer/kube-burner v1.7.3/go.mod h1:NnqtBx6cW53zlVf65Mv2U43hDlc/VF0FquFmjUeySV4=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -61,8 +63,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
Expand Down Expand Up @@ -122,8 +124,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -219,6 +221,7 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down

0 comments on commit d21fefd

Please sign in to comment.