Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubetest2 Version Addition #111

Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# get the repo root and output path
REPO_ROOT:=$(shell pwd)
export REPO_ROOT
OUT_DIR?=$(REPO_ROOT)/bin
OUT_DIR=$(REPO_ROOT)/bin
# record the source commit in the binary, overridable
COMMIT?=$(shell git describe --tags --always --dirty 2>/dev/null)
INSTALL?=install
# make install will place binaries here
# the default path attempts to mimic go install
Expand All @@ -47,7 +49,7 @@ SPACE:=$(subst ,, )
SHELL:=env PATH=$(subst $(SPACE),\$(SPACE),$(PATH)) $(SHELL)
# ==============================================================================
# flags for reproducible go builds
BUILD_FLAGS?=-trimpath -ldflags="-buildid="
BUILD_FLAGS?=-trimpath -ldflags="-buildid= -X=sigs.k8s.io/kubetest2/pkg/app.GitTag=$(COMMIT)"
Copy link
Contributor

Choose a reason for hiding this comment

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

unfortunately, handling the deployers won't be so straightforward :)
this will just always get the kubetest2 shim version. but we can have deployers built at different commits.


build-all:
go build -v $(BUILD_FLAGS) ./...
Expand Down
3 changes: 3 additions & 0 deletions pkg/app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func runE(
opts.bindFlags(kubetest2Flags)
artifacts.MustBindFlags(kubetest2Flags)

cmd.Printf("Running deployer %s version: %s\n", deployerName, shim.GitTag)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can add this after deployer versions are added


// NOTE: unknown flags are forwarded to the deployer as arguments
kubetest2Flags.ParseErrorsWhitelist.UnknownFlags = true

Expand All @@ -91,6 +93,7 @@ func runE(
if err != nil {
return fmt.Errorf("unable to find tester %v: %v", opts.test, err)
}
cmd.Printf("Running tester %s version: %s\n", opts.test, shim.GitTag)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can add this after testers versions are added


// Get tester usage by running it with --help
var helpArgs []string
Expand Down
12 changes: 11 additions & 1 deletion pkg/app/shim/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (
"sigs.k8s.io/kubetest2/pkg/process"
)

// GitTag captures the git commit SHA of the build. This gets printed by all the deployers and testers
var GitTag string

// Main implements the kubetest2 root binary entrypoint
func Main() {
if err := Run(); err != nil {
Expand Down Expand Up @@ -66,22 +69,29 @@ func NewCommand() *cobra.Command {

// runE implements the actual command logic
func runE(cmd *cobra.Command, args []string) error {
cmd.Printf("Running %s version: %s\n", BinaryName, GitTag)
// there should be at least one argument (the deployer) unless the user
// is asking for help on the shim itself
if len(args) < 1 {
return cmd.Help()
}

// gracefully handle -h or --help if it is the only argument
// gracefully handle help or version command if it is the only argument
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this feature, but if other arguments are set AND --help is included, it will try to deploy?

Copy link
Contributor

Choose a reason for hiding this comment

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

no

kubetest2/pkg/app/cmd.go

Lines 139 to 143 in 96ab8c9

// print usage and return if no args are provided, or help is explicitly requested
if len(args) == 0 || opts.HelpRequested() {
cmd.Print(usage.String())
return nil
}

if len(args) == 1 {
// check for -h, --help
flags := pflag.NewFlagSet(BinaryName, pflag.ContinueOnError)
help := flags.BoolP("help", "h", false, "")
// check for -v, --version
ver := flags.BoolP("version", "v", false, fmt.Sprintf("prints %s version", BinaryName))
// we don't care about errors, only if -h / --help was set
_ = flags.Parse(args)
if *help {
return cmd.Help()
}
if *ver {
fmt.Printf("%s version %s\n", BinaryName, GitTag)
return nil
}
}

// otherwise find and execute the deployer with the remaining arguments
Expand Down