Skip to content

Commit

Permalink
Allow custom timeout when fetching container tags (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfrench authored Jul 5, 2023
1 parent a405bf7 commit ace9df2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func init() {
klog.Exitf("Failed to bind show-errored-containers flag: %v", err)
}

findCmd.Flags().Uint16P("timeout", "t", 10, "When finding container images, the time in seconds before canceling the operation.")
err = viper.BindPFlag("timeout", findCmd.Flags().Lookup("timeout"))
if err != nil {
klog.Exitf("Failed to bind timeout flag: %v", err)
}

rootCmd.PersistentFlags().Bool("show-old", false, "Only show charts that are not on the latest version")
err = viper.BindPFlag("show-old", rootCmd.PersistentFlags().Lookup("show-old"))
if err != nil {
Expand Down Expand Up @@ -306,7 +312,8 @@ func Execute(VERSION, COMMIT string) {

func handleContainers(kubeContext string) (*output.ContainersOutput, error) {
// Set up a context we can use to cancel all operations to external container registries if we need to
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
timeout := time.Duration(viper.GetUint16("timeout")) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
defer func() {
Expand Down
5 changes: 4 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Flags:
--containers Show old container image versions. There will be no helm output unless the --helm flag is set as well
--helm Show old helm releases. You can combine this flag with `--containers` to have both output in a single run.
-h, --help help for find
--show-non-semver When finding container images, show all containers even if they don't follow semver.
--show-errored-containers When finding container images, show errors encountered when scanning.
--show-non-semver When finding container images, show all containers even if they don't follow semver.
-t, --timeout uint16 When finding container images, the time in seconds before canceling the operation. (default 10)
Global Flags:
--alsologtostderr log to standard error as well as files (default true)
Expand Down Expand Up @@ -105,6 +107,7 @@ redis redis redis 3 15.4.1
There are a couple flags that are unique to the container image output.
- `--show-non-semver` will also show any container tags running in the cluster that do not have valid semver versions. By default these are not shown.
- `--show-errored-containers` will show any containers that returned some sort of error when reaching out to the registry and/or when processing the tags.
- `--timeout` will set the time (in seconds) before remote queries to the registry are cancelled. Useful when an image has many tags. Defaults to 10 seconds.

Below is sample output for Nova when using the `--containers` flag

Expand Down

0 comments on commit ace9df2

Please sign in to comment.