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

feat: allow overriding registry rate limit in test command #256

Merged
merged 5 commits into from
Sep 15, 2021
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
13 changes: 13 additions & 0 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/argoproj-labs/argocd-image-updater/pkg/registry"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.uber.org/ratelimit"
)

func newTestCommand() *cobra.Command {
Expand All @@ -23,6 +25,7 @@ func newTestCommand() *cobra.Command {
disableKubernetes bool
ignoreTags []string
disableKubeEvents bool
rateLimit int
)
var runCmd = &cobra.Command{
Use: "test IMAGE",
Expand Down Expand Up @@ -102,6 +105,15 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
log.Fatalf("could not set registry credentials: %v", err)
}

checkFlag := func(f *pflag.Flag) {
if f.Name == "rate-limit" {
log.Infof("Overriding registry rate-limit to %d requests per second", rateLimit)
ep.Limiter = ratelimit.New(rateLimit)
}
}

cmd.Flags().Visit(checkFlag)

var creds *image.Credential
var username, password string
if credentials != "" {
Expand Down Expand Up @@ -158,5 +170,6 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
runCmd.Flags().StringVar(&kubeConfig, "kubeconfig", "", "path to your Kubernetes client configuration")
runCmd.Flags().StringVar(&credentials, "credentials", "", "the credentials definition for the test (overrides registry config)")
runCmd.Flags().BoolVar(&disableKubeEvents, "disable-kubernetes-events", false, "Disable kubernetes events")
runCmd.Flags().IntVar(&rateLimit, "rate-limit", 20, "specificy registry rate limit (overrides registry.conf)")
return runCmd
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/prometheus/client_golang v1.7.1
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
go.uber.org/ratelimit v0.1.1-0.20201110185707-e86515f0dda9
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
Expand Down