-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubectl-trace): support version for image version
Signed-off-by: Lorenzo Fontana <lo@linux.com>
- Loading branch information
Showing
6 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/fntlnz/kubectl-trace/pkg/version" | ||
"github.com/spf13/cobra" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
) | ||
|
||
func NewVersionCommand(streams genericclioptions.IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version information for kubectl trace", | ||
RunE: func(c *cobra.Command, args []string) error { | ||
fmt.Fprintln(streams.Out, version.String()) | ||
return nil | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// Populated by makefile | ||
var gitCommit string | ||
var buildTime string | ||
var versionFormat = "git commit: %s\nbuild date: %s" | ||
var imageNameTagFormat = "quay.io/fntlnz/kubectl-trace-bpftrace:%s" | ||
|
||
func GitCommit() string { | ||
return gitCommit | ||
} | ||
|
||
func ImageNameTag() string { | ||
return fmt.Sprintf(imageNameTagFormat, GitCommit()) | ||
} | ||
|
||
func Time() *time.Time { | ||
if len(buildTime) == 0 { | ||
return nil | ||
} | ||
i, err := strconv.ParseInt(buildTime, 10, 64) | ||
if err != nil { | ||
return nil | ||
} | ||
t := time.Unix(i, 0) | ||
return &t | ||
} | ||
|
||
func String() string { | ||
ts := Time() | ||
if ts == nil { | ||
return fmt.Sprintf(versionFormat, GitCommit(), "undefined") | ||
} | ||
return fmt.Sprintf(versionFormat, GitCommit(), ts.String()) | ||
} |