From 1ccdace0c3275f1268a5b31457c1772131f2e159 Mon Sep 17 00:00:00 2001 From: John Long Date: Tue, 13 Feb 2024 18:17:26 -0500 Subject: [PATCH] ensure flags take precedence over cfg --- docs/fox.md | 13 ++++++++----- docs/fox_build.md | 11 +++++++---- docs/fox_completion.md | 11 +++++++---- docs/fox_completion_bash.md | 11 +++++++---- docs/fox_completion_fish.md | 11 +++++++---- docs/fox_completion_powershell.md | 11 +++++++---- docs/fox_completion_zsh.md | 11 +++++++---- docs/fox_config.md | 11 +++++++---- docs/fox_config_setup.md | 11 +++++++---- docs/fox_config_show.md | 11 +++++++---- docs/fox_deploy.md | 11 +++++++---- docs/fox_docs.md | 11 +++++++---- docs/fox_init.md | 11 +++++++---- docs/fox_proxy.md | 11 +++++++---- docs/fox_publish.md | 11 +++++++---- docs/fox_release.md | 11 +++++++---- docs/fox_version.md | 11 +++++++---- internal/config/config.go | 12 ++++++++++-- internal/config/flags.go | 24 ++++++++++++------------ internal/repo/build.go | 8 ++++++-- internal/repo/deploy.go | 6 +++--- internal/repo/repo.go | 2 +- 22 files changed, 152 insertions(+), 89 deletions(-) diff --git a/docs/fox.md b/docs/fox.md index de37c24..146af2b 100644 --- a/docs/fox.md +++ b/docs/fox.md @@ -12,11 +12,14 @@ and release your KubeFox Apps. ### Options ``` - -a, --app string path to directory containing KubeFox App - -h, --help help for fox - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -h, --help help for fox + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_build.md b/docs/fox_build.md index 7db42a9..e64a98f 100644 --- a/docs/fox_build.md +++ b/docs/fox_build.md @@ -34,10 +34,13 @@ fox build my-component --publish ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_completion.md b/docs/fox_completion.md index 82fd530..2e8c51b 100644 --- a/docs/fox_completion.md +++ b/docs/fox_completion.md @@ -17,10 +17,13 @@ See each sub-command's help for details on how to use the generated script. ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_completion_bash.md b/docs/fox_completion_bash.md index 5caf8b8..27e1c71 100644 --- a/docs/fox_completion_bash.md +++ b/docs/fox_completion_bash.md @@ -40,10 +40,13 @@ fox completion bash ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_completion_fish.md b/docs/fox_completion_fish.md index de6bc09..46f37c9 100644 --- a/docs/fox_completion_fish.md +++ b/docs/fox_completion_fish.md @@ -31,10 +31,13 @@ fox completion fish [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_completion_powershell.md b/docs/fox_completion_powershell.md index 0aef724..56cd504 100644 --- a/docs/fox_completion_powershell.md +++ b/docs/fox_completion_powershell.md @@ -28,10 +28,13 @@ fox completion powershell [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_completion_zsh.md b/docs/fox_completion_zsh.md index 06192cd..503e0be 100644 --- a/docs/fox_completion_zsh.md +++ b/docs/fox_completion_zsh.md @@ -42,10 +42,13 @@ fox completion zsh [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_config.md b/docs/fox_config.md index e6323cf..029e363 100644 --- a/docs/fox_config.md +++ b/docs/fox_config.md @@ -17,10 +17,13 @@ Use the config subcommand to help setup your local environment. ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_config_setup.md b/docs/fox_config_setup.md index 7c59e7e..f2b108f 100644 --- a/docs/fox_config_setup.md +++ b/docs/fox_config_setup.md @@ -15,10 +15,13 @@ fox config setup [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_config_show.md b/docs/fox_config_show.md index b1aea2b..84f0faa 100644 --- a/docs/fox_config_show.md +++ b/docs/fox_config_show.md @@ -15,10 +15,13 @@ fox config show [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_deploy.md b/docs/fox_deploy.md index a27ff6a..d3d5c44 100644 --- a/docs/fox_deploy.md +++ b/docs/fox_deploy.md @@ -22,10 +22,13 @@ fox deploy [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_docs.md b/docs/fox_docs.md index 7b816d5..abab0b5 100644 --- a/docs/fox_docs.md +++ b/docs/fox_docs.md @@ -20,10 +20,13 @@ fox docs [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_init.md b/docs/fox_init.md index 4be7091..c28fd22 100644 --- a/docs/fox_init.md +++ b/docs/fox_init.md @@ -22,10 +22,13 @@ fox init [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_proxy.md b/docs/fox_proxy.md index 21c992e..c280e30 100644 --- a/docs/fox_proxy.md +++ b/docs/fox_proxy.md @@ -47,10 +47,13 @@ fox proxy 8080 --virtual-env my-env --app-deployment my-dep ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_publish.md b/docs/fox_publish.md index bfcc32d..5164098 100644 --- a/docs/fox_publish.md +++ b/docs/fox_publish.md @@ -27,10 +27,13 @@ fox publish [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_release.md b/docs/fox_release.md index b6647a2..cc06a0b 100644 --- a/docs/fox_release.md +++ b/docs/fox_release.md @@ -43,10 +43,13 @@ fox release v1.2.3 --virtual-env prod ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/docs/fox_version.md b/docs/fox_version.md index e28dd04..085baaf 100644 --- a/docs/fox_version.md +++ b/docs/fox_version.md @@ -15,10 +15,13 @@ fox version [flags] ### Options inherited from parent commands ``` - -a, --app string path to directory containing KubeFox App - -i, --info enable info output - -o, --output string output format, one of ["json", "yaml"] (default "yaml") - -v, --verbose enable verbose output + -a, --app string path to directory containing KubeFox App + -i, --info enable info output + -o, --output string output format, one of ["json", "yaml"] (default "yaml") + --registry-address string address of your container registry + --registry-token string access token for your container registry + --registry-username string username for your container registry + -v, --verbose enable verbose output ``` ### SEE ALSO diff --git a/internal/config/config.go b/internal/config/config.go index ac58b3b..0e40269 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -23,6 +23,7 @@ import ( "github.com/cli/oauth/device" "github.com/xigxog/fox/internal/log" "github.com/xigxog/fox/internal/utils" + kfutils "github.com/xigxog/kubefox/utils" "sigs.k8s.io/yaml" ) @@ -87,7 +88,15 @@ type ContainerRegistry struct { } func (cfg *Config) IsRegistryLocal() bool { - return strings.HasPrefix(cfg.ContainerRegistry.Address, LocalRegistry) + return strings.HasPrefix(cfg.GetContainerRegistry().Address, LocalRegistry) +} + +func (cfg *Config) GetContainerRegistry() ContainerRegistry { + return ContainerRegistry{ + Address: kfutils.First(cfg.Flags.RegistryAddress, cfg.ContainerRegistry.Address), + Token: kfutils.First(cfg.Flags.RegistryToken, cfg.ContainerRegistry.Token), + Username: kfutils.First(cfg.Flags.RegistryUsername, cfg.ContainerRegistry.Username), + } } func (cfg *Config) Load() { @@ -234,7 +243,6 @@ func (cfg *Config) setupRegistry() { cfg.ContainerRegistry.Address = utils.InputPrompt("Enter the container registry endpoint you'd like to use", "", true) cfg.ContainerRegistry.Username = utils.InputPrompt("Enter the container registry username (if required)", "", false) cfg.ContainerRegistry.Token = utils.InputPrompt("Enter the container registry access token or password", "", true) - return } func (cfg *Config) setupGitHub() { diff --git a/internal/config/flags.go b/internal/config/flags.go index 98034d4..640c377 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -12,24 +12,24 @@ import "time" type Flags struct { // persistent flags defined in root command - AppPath string - OutFormat string + AppPath string + OutFormat string + RegistryAddress string + RegistryToken string + RegistryUsername string DryRun bool Info bool Verbose bool // flags used by subcommands - AppDeployment string - Builder string - Kind string - Namespace string - Platform string - Version string - VirtEnv string - RegistryAddress string - RegistryUsername string - RegistryToken string + AppDeployment string + Builder string + Kind string + Namespace string + Platform string + Version string + VirtEnv string CreateTag bool ForceBuild bool diff --git a/internal/repo/build.go b/internal/repo/build.go index f56dc05..1c6d7a8 100644 --- a/internal/repo/build.go +++ b/internal/repo/build.go @@ -185,6 +185,10 @@ func (r *repo) IsImageLocal(img string) bool { } func (r *repo) KindLoad(img string) { + if !r.cfg.IsRegistryLocal() { + return + } + kind := r.cfg.Flags.Kind if kind == "" && r.cfg.Kind.AlwaysLoad { kind = r.cfg.Kind.ClusterName @@ -211,11 +215,11 @@ func (r *repo) KindLoad(img string) { } func (r *repo) GetRegAuth() string { - token := r.cfg.ContainerRegistry.Token + token := r.cfg.GetContainerRegistry().Token if r.cfg.GitHub.Token != "" { token = r.cfg.GitHub.Token } - user := r.cfg.ContainerRegistry.Username + user := r.cfg.GetContainerRegistry().Username if user == "" { user = "kubefox" } diff --git a/internal/repo/deploy.go b/internal/repo/deploy.go index aa4a257..351bb52 100644 --- a/internal/repo/deploy.go +++ b/internal/repo/deploy.go @@ -106,8 +106,8 @@ func (r *repo) Publish() *v1alpha1.AppDeployment { } func (r *repo) applyIPS(ctx context.Context, p *v1alpha1.Platform, spec *v1alpha1.AppDeploymentSpec) { - if r.cfg.ContainerRegistry.Token != "" { - cr := r.cfg.ContainerRegistry + cr := r.cfg.GetContainerRegistry() + if cr.Token != "" { name := fmt.Sprintf("%s-image-pull-secret", spec.AppName) dockerCfg := fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"%s"}}}`, cr.Address, cr.Username, cr.Token) @@ -186,7 +186,7 @@ func (r *repo) buildAppDep() *v1alpha1.AppDeployment { commit := r.GetCommit("") reg := r.app.ContainerRegistry if reg == "" { - reg = r.cfg.ContainerRegistry.Address + reg = r.cfg.GetContainerRegistry().Address } appDep := &v1alpha1.AppDeployment{ diff --git a/internal/repo/repo.go b/internal/repo/repo.go index 365b3b7..1d7dcc9 100644 --- a/internal/repo/repo.go +++ b/internal/repo/repo.go @@ -139,7 +139,7 @@ func (r *repo) GetCompImageFromDir(compDirName string) string { } func (r *repo) GetCompImage(name, commit string) string { - return fmt.Sprintf("%s/%s/%s:%s", r.cfg.ContainerRegistry.Address, r.app.Name, name, commit) + return fmt.Sprintf("%s/%s/%s:%s", r.cfg.GetContainerRegistry().Address, r.app.Name, name, commit) } func (r *repo) GetRepoURL() string {