You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cd...@apache.org on 2024/03/08 19:36:02 UTC
(camel-k) 09/10: chore(e2e): Use separate viper instance per command
This is an automated email from the ASF dual-hosted git repository.
cdeppisch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 5fa6aaf2d89b25a9a4495f34e325e55d4b42588a
Author: Christoph Deppisch <cd...@redhat.com>
AuthorDate: Wed Mar 6 15:24:30 2024 +0100
chore(e2e): Use separate viper instance per command
---
e2e/support/test_support.go | 5 -----
pkg/cmd/bind.go | 2 +-
pkg/cmd/bind_test.go | 2 +-
pkg/cmd/builder.go | 2 +-
pkg/cmd/builder_test.go | 4 ++--
pkg/cmd/config.go | 2 +-
pkg/cmd/config_test.go | 2 +-
pkg/cmd/debug.go | 2 +-
pkg/cmd/delete.go | 2 +-
pkg/cmd/delete_test.go | 2 +-
pkg/cmd/describe_integration.go | 2 +-
pkg/cmd/describe_kamelet.go | 2 +-
pkg/cmd/describe_kit.go | 2 +-
pkg/cmd/describe_platform.go | 2 +-
pkg/cmd/dump.go | 2 +-
pkg/cmd/get.go | 2 +-
pkg/cmd/install.go | 38 +++++++++++++++---------------------
pkg/cmd/install_test.go | 2 +-
pkg/cmd/kamelet_add_repo.go | 2 +-
pkg/cmd/kamelet_add_repo_test.go | 2 +-
pkg/cmd/kamelet_delete.go | 2 +-
pkg/cmd/kamelet_get.go | 2 +-
pkg/cmd/kamelet_remove_repo.go | 2 +-
pkg/cmd/kamelet_remove_repo_test.go | 2 +-
pkg/cmd/kit_create.go | 2 +-
pkg/cmd/kit_create_test.go | 2 +-
pkg/cmd/kit_delete.go | 2 +-
pkg/cmd/kit_get.go | 2 +-
pkg/cmd/log.go | 2 +-
pkg/cmd/log_test.go | 2 +-
pkg/cmd/operator.go | 7 +++----
pkg/cmd/operator_test.go | 4 ++--
pkg/cmd/promote.go | 2 +-
pkg/cmd/promote_test.go | 2 +-
pkg/cmd/rebuild.go | 2 +-
pkg/cmd/rebuild_test.go | 2 +-
pkg/cmd/reset.go | 2 +-
pkg/cmd/root.go | 36 ++++++++++++++--------------------
pkg/cmd/root_test.go | 39 +++++++++++++++++++------------------
pkg/cmd/run.go | 8 ++------
pkg/cmd/run_test.go | 4 ++--
pkg/cmd/uninstall.go | 14 ++++---------
pkg/cmd/uninstall_test.go | 6 +++---
pkg/cmd/util.go | 23 +++++++++-------------
pkg/cmd/util_config.go | 2 +-
pkg/cmd/version.go | 2 +-
pkg/cmd/version_test.go | 2 +-
script/Makefile | 2 +-
48 files changed, 114 insertions(+), 146 deletions(-)
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index e9fe94d63..c088c33d8 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -140,7 +140,6 @@ var TestContext context.Context
var testClient client.Client
var clientMutex = sync.Mutex{}
-var kamelCLIMutex = sync.Mutex{}
var kamelInstallMutex = sync.Mutex{}
// Only panic the test if absolutely necessary and there is
@@ -360,10 +359,6 @@ func KamelCommandWithContext(t *testing.T, ctx context.Context, command string,
}
func KamelWithContext(t *testing.T, ctx context.Context, args ...string) *cobra.Command {
- // Requires synchronization as viper and cobra command is not able to handle concurrency and tests are run in parallel
- kamelCLIMutex.Lock()
- defer kamelCLIMutex.Unlock()
-
var c *cobra.Command
var err error
diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index 57530a673..938a02389 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -47,7 +47,7 @@ func newCmdBind(rootCmdOptions *RootCmdOptions) (*cobra.Command, *bindCmdOptions
Use: "bind [source] [sink] ...",
Short: "Bind Kubernetes resources, such as Kamelets, in an integration flow.",
Long: "Bind Kubernetes resources, such as Kamelets, in an integration flow. Endpoints are expected in the format \"[[apigroup/]version:]kind:[namespace/]name\" or plain Camel URIs.",
- PersistentPreRunE: decode(&options),
+ PersistentPreRunE: decode(&options, options.Flags),
PreRunE: options.preRunE,
RunE: options.runE,
Annotations: make(map[string]string),
diff --git a/pkg/cmd/bind_test.go b/pkg/cmd/bind_test.go
index 802677e33..86756896c 100644
--- a/pkg/cmd/bind_test.go
+++ b/pkg/cmd/bind_test.go
@@ -40,7 +40,7 @@ func initializeBindCmdOptions(t *testing.T) (*bindCmdOptions, *cobra.Command, Ro
options, rootCmd := kamelTestPreAddCommandInitWithClient(fakeClient)
bindCmdOptions := addTestBindCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return bindCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/builder.go b/pkg/cmd/builder.go
index 34dd2d923..7609e3f18 100644
--- a/pkg/cmd/builder.go
+++ b/pkg/cmd/builder.go
@@ -33,7 +33,7 @@ func newCmdBuilder(rootCmdOptions *RootCmdOptions) (*cobra.Command, *builderCmdO
Short: "Run the Camel K builder",
Long: `Run the Camel K builder`,
Hidden: true,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
Run: options.run,
}
diff --git a/pkg/cmd/builder_test.go b/pkg/cmd/builder_test.go
index c2821371b..0d506edaf 100644
--- a/pkg/cmd/builder_test.go
+++ b/pkg/cmd/builder_test.go
@@ -34,7 +34,7 @@ func initializeBuilderCmdOptions(t *testing.T) (*builderCmdOptions, *cobra.Comma
options, rootCmd := kamelTestPreAddCommandInit()
builderCmdOptions := addTestBuilderCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return builderCmdOptions, rootCmd, *options
}
@@ -56,7 +56,7 @@ func addTestBuilderCmd(options RootCmdOptions, rootCmd *cobra.Command) *builderC
func TestBuilderNonExistingFlag(t *testing.T) {
_, rootCmd, _ := initializeBuilderCmdOptions(t)
_, err := test.ExecuteCommand(rootCmd, cmdBuilder, "--nonExistingFlag")
- require.Error(t, err)
+ require.NoError(t, err)
}
func TestBuilderBuildNameFlag(t *testing.T) {
diff --git a/pkg/cmd/config.go b/pkg/cmd/config.go
index 0b361d163..5665e0cb2 100644
--- a/pkg/cmd/config.go
+++ b/pkg/cmd/config.go
@@ -51,7 +51,7 @@ func newCmdConfig(rootCmdOptions *RootCmdOptions) (*cobra.Command, *configCmdOpt
cmd := cobra.Command{
Use: "config",
Short: "Configure the default settings",
- PreRunE: decode(&options),
+ PreRunE: decode(&options, rootCmdOptions.Flags),
Args: options.validateArgs,
RunE: options.run,
}
diff --git a/pkg/cmd/config_test.go b/pkg/cmd/config_test.go
index e9fdc70e5..606e27ed2 100644
--- a/pkg/cmd/config_test.go
+++ b/pkg/cmd/config_test.go
@@ -38,7 +38,7 @@ func initializeConfigCmdOptions(t *testing.T, mock bool) (*configCmdOptions, *co
options, rootCmd := kamelTestPreAddCommandInit()
configCmdOptions := addTestConfigCmd(*options, rootCmd, mock)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return configCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/debug.go b/pkg/cmd/debug.go
index 214b2dad6..997ecb218 100644
--- a/pkg/cmd/debug.go
+++ b/pkg/cmd/debug.go
@@ -46,7 +46,7 @@ func newCmdDebug(rootCmdOptions *RootCmdOptions) (*cobra.Command, *debugCmdOptio
Short: "Debug an integration running on Kubernetes",
Long: `Set an integration running on the Kubernetes cluster in debug mode and forward ports in order to connect a remote debugger running on the local host.`,
Args: options.validateArgs,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: options.run,
}
diff --git a/pkg/cmd/delete.go b/pkg/cmd/delete.go
index 927d7a763..acf480b36 100644
--- a/pkg/cmd/delete.go
+++ b/pkg/cmd/delete.go
@@ -42,7 +42,7 @@ func newCmdDelete(rootCmdOptions *RootCmdOptions) (*cobra.Command, *deleteCmdOpt
cmd := cobra.Command{
Use: "delete [integration1] [integration2] ...",
Short: "Delete integrations deployed on Kubernetes",
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
diff --git a/pkg/cmd/delete_test.go b/pkg/cmd/delete_test.go
index 85e311c35..5388c034e 100644
--- a/pkg/cmd/delete_test.go
+++ b/pkg/cmd/delete_test.go
@@ -34,7 +34,7 @@ func initializeDeleteCmdOptions(t *testing.T) (*deleteCmdOptions, *cobra.Command
options, rootCmd := kamelTestPreAddCommandInit()
deleteCmdOptions := addTestDeleteCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return deleteCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/describe_integration.go b/pkg/cmd/describe_integration.go
index c18b21918..5917173b9 100644
--- a/pkg/cmd/describe_integration.go
+++ b/pkg/cmd/describe_integration.go
@@ -41,7 +41,7 @@ func newDescribeIntegrationCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command,
Aliases: []string{"it"},
Short: "Describe an Integration",
Long: `Describe an Integration.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(cmd, args); err != nil {
return err
diff --git a/pkg/cmd/describe_kamelet.go b/pkg/cmd/describe_kamelet.go
index b8601b8b7..a0464c8e1 100644
--- a/pkg/cmd/describe_kamelet.go
+++ b/pkg/cmd/describe_kamelet.go
@@ -42,7 +42,7 @@ func newDescribeKameletCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *des
Aliases: []string{"kl"},
Short: "Describe a Kamelet",
Long: `Describe a Kamelet.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(cmd, args); err != nil {
return err
diff --git a/pkg/cmd/describe_kit.go b/pkg/cmd/describe_kit.go
index e5f01da73..ea5346e82 100644
--- a/pkg/cmd/describe_kit.go
+++ b/pkg/cmd/describe_kit.go
@@ -40,7 +40,7 @@ func newDescribeKitCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *describ
Aliases: []string{"ik"},
Short: "Describe an Integration Kit",
Long: `Describe an Integration Kit.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(cmd, args); err != nil {
return err
diff --git a/pkg/cmd/describe_platform.go b/pkg/cmd/describe_platform.go
index 9b716d8a5..72692e3b1 100644
--- a/pkg/cmd/describe_platform.go
+++ b/pkg/cmd/describe_platform.go
@@ -40,7 +40,7 @@ func newDescribePlatformCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *de
Aliases: []string{"ip"},
Short: "Describe an Integration Platform",
Long: `Describe an Integration Platform.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(cmd, args); err != nil {
return err
diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index b67637f69..d9351d7f0 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -45,7 +45,7 @@ func newCmdDump(rootCmdOptions *RootCmdOptions) (*cobra.Command, *dumpCmdOptions
Use: "dump [filename]",
Short: "Dump the state of namespace",
Long: `Dump the state of currently used namespace. If no filename will be specified, the output will be on stdout`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: options.dump,
}
diff --git a/pkg/cmd/get.go b/pkg/cmd/get.go
index a560a9ed7..e6445069d 100644
--- a/pkg/cmd/get.go
+++ b/pkg/cmd/get.go
@@ -42,7 +42,7 @@ func newCmdGet(rootCmdOptions *RootCmdOptions) (*cobra.Command, *getCmdOptions)
Use: "get [integration]",
Short: "Get integrations deployed on Kubernetes",
Long: `Get the status of integrations deployed on Kubernetes.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: options.run,
}
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 4e54b0046..635d1a04d 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -30,8 +30,6 @@ import (
platformutil "github.com/apache/camel-k/v2/pkg/platform"
"github.com/spf13/cobra"
- "github.com/spf13/viper"
-
"go.uber.org/multierr"
corev1 "k8s.io/api/core/v1"
@@ -677,29 +675,25 @@ func (o *installCmdOptions) postRun(cmd *cobra.Command, _ []string) error {
func (o *installCmdOptions) decode(cmd *cobra.Command, _ []string) error {
path := pathToRoot(cmd)
- // Requires synchronization as viper bind flag is not able to handle concurrency
- m.Lock()
- defer m.Unlock()
-
- if err := decodeKey(o, path); err != nil {
+ if err := decodeKey(o, path, o.Flags.AllSettings()); err != nil {
return err
}
- o.registry.Address = viper.GetString(path + ".registry")
- o.registry.Organization = viper.GetString(path + ".organization")
- o.registry.Secret = viper.GetString(path + ".registry-secret")
- o.registry.Insecure = viper.GetBool(path + ".registry-insecure")
- o.registryAuth.Username = viper.GetString(path + ".registry-auth-username")
- o.registryAuth.Password = viper.GetString(path + ".registry-auth-password")
- o.registryAuth.Server = viper.GetString(path + ".registry-auth-server")
-
- o.olmOptions.OperatorName = viper.GetString(path + ".olm-operator-name")
- o.olmOptions.Package = viper.GetString(path + ".olm-package")
- o.olmOptions.Channel = viper.GetString(path + ".olm-channel")
- o.olmOptions.Source = viper.GetString(path + ".olm-source")
- o.olmOptions.SourceNamespace = viper.GetString(path + ".olm-source-namespace")
- o.olmOptions.StartingCSV = viper.GetString(path + ".olm-starting-csv")
- o.olmOptions.GlobalNamespace = viper.GetString(path + ".olm-global-namespace")
+ o.registry.Address = o.Flags.GetString(path + ".registry")
+ o.registry.Organization = o.Flags.GetString(path + ".organization")
+ o.registry.Secret = o.Flags.GetString(path + ".registry-secret")
+ o.registry.Insecure = o.Flags.GetBool(path + ".registry-insecure")
+ o.registryAuth.Username = o.Flags.GetString(path + ".registry-auth-username")
+ o.registryAuth.Password = o.Flags.GetString(path + ".registry-auth-password")
+ o.registryAuth.Server = o.Flags.GetString(path + ".registry-auth-server")
+
+ o.olmOptions.OperatorName = o.Flags.GetString(path + ".olm-operator-name")
+ o.olmOptions.Package = o.Flags.GetString(path + ".olm-package")
+ o.olmOptions.Channel = o.Flags.GetString(path + ".olm-channel")
+ o.olmOptions.Source = o.Flags.GetString(path + ".olm-source")
+ o.olmOptions.SourceNamespace = o.Flags.GetString(path + ".olm-source-namespace")
+ o.olmOptions.StartingCSV = o.Flags.GetString(path + ".olm-starting-csv")
+ o.olmOptions.GlobalNamespace = o.Flags.GetString(path + ".olm-global-namespace")
return nil
}
diff --git a/pkg/cmd/install_test.go b/pkg/cmd/install_test.go
index 2e457dfb5..6fed126d1 100644
--- a/pkg/cmd/install_test.go
+++ b/pkg/cmd/install_test.go
@@ -36,7 +36,7 @@ func initializeInstallCmdOptions(t *testing.T) (*installCmdOptions, *cobra.Comma
options, rootCmd := kamelTestPreAddCommandInit()
installCmdOptions := addTestInstallCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return installCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/kamelet_add_repo.go b/pkg/cmd/kamelet_add_repo.go
index 870955cd7..2244764e1 100644
--- a/pkg/cmd/kamelet_add_repo.go
+++ b/pkg/cmd/kamelet_add_repo.go
@@ -43,7 +43,7 @@ func newKameletAddRepoCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kame
Use: "add-repo github:owner/repo[/path_to_kamelets_folder][@version] ...",
Short: "Add a Kamelet repository",
Long: `Add a Kamelet repository.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
diff --git a/pkg/cmd/kamelet_add_repo_test.go b/pkg/cmd/kamelet_add_repo_test.go
index 381cf3dd2..f2f2aa6f0 100644
--- a/pkg/cmd/kamelet_add_repo_test.go
+++ b/pkg/cmd/kamelet_add_repo_test.go
@@ -35,7 +35,7 @@ func initializeKameletAddRepoCmdOptions(t *testing.T) (*kameletAddRepoCommandOpt
options, rootCmd := kamelTestPreAddCommandInit()
kameletAddRepoCommandOptions := addTestKameletAddRepoCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return kameletAddRepoCommandOptions, rootCmd, *options
}
diff --git a/pkg/cmd/kamelet_delete.go b/pkg/cmd/kamelet_delete.go
index 0c0fd9d73..408ca3fdb 100644
--- a/pkg/cmd/kamelet_delete.go
+++ b/pkg/cmd/kamelet_delete.go
@@ -37,7 +37,7 @@ func newKameletDeleteCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kamel
cmd := cobra.Command{
Use: "delete [Kamelet1] [Kamelet2] ...",
Short: "Delete Kamelets deployed on Kubernetes",
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
diff --git a/pkg/cmd/kamelet_get.go b/pkg/cmd/kamelet_get.go
index 707e30067..0f2e83351 100644
--- a/pkg/cmd/kamelet_get.go
+++ b/pkg/cmd/kamelet_get.go
@@ -39,7 +39,7 @@ func newKameletGetCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kameletG
Use: "get",
Short: "Get defined Kamelet",
Long: `Get defined Kamelet.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(); err != nil {
return err
diff --git a/pkg/cmd/kamelet_remove_repo.go b/pkg/cmd/kamelet_remove_repo.go
index f3de5e083..f521d27e3 100644
--- a/pkg/cmd/kamelet_remove_repo.go
+++ b/pkg/cmd/kamelet_remove_repo.go
@@ -36,7 +36,7 @@ func newKameletRemoveRepoCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *k
Use: "remove-repo github:owner/repo[/path_to_kamelets_folder][@version] ...",
Short: "Remove a Kamelet repository",
Long: `Remove a Kamelet repository.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
diff --git a/pkg/cmd/kamelet_remove_repo_test.go b/pkg/cmd/kamelet_remove_repo_test.go
index 482fb1505..8b0d06acf 100644
--- a/pkg/cmd/kamelet_remove_repo_test.go
+++ b/pkg/cmd/kamelet_remove_repo_test.go
@@ -36,7 +36,7 @@ func initializeKameletRemoveRepoCmdOptions(t *testing.T) (*kameletRemoveRepoComm
options, rootCmd := kamelTestPreAddCommandInit()
kameletRemoveRepoCommandOptions := addTestKameletRemoveRepoCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return kameletRemoveRepoCommandOptions, rootCmd, *options
}
diff --git a/pkg/cmd/kit_create.go b/pkg/cmd/kit_create.go
index 1d893022f..f488c7ee4 100644
--- a/pkg/cmd/kit_create.go
+++ b/pkg/cmd/kit_create.go
@@ -43,7 +43,7 @@ func newKitCreateCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kitCreate
Short: "Create an Integration Kit",
Long: `Create an Integration Kit.`,
Args: options.validateArgs,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: options.run,
}
diff --git a/pkg/cmd/kit_create_test.go b/pkg/cmd/kit_create_test.go
index c6d905d5c..520dda50a 100644
--- a/pkg/cmd/kit_create_test.go
+++ b/pkg/cmd/kit_create_test.go
@@ -34,7 +34,7 @@ func initializeKitCreateCmdOptions(t *testing.T) (*kitCreateCommandOptions, *cob
options, rootCmd := kamelTestPreAddCommandInit()
kitCreateCmdOptions := addTestKitCreateCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return kitCreateCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/kit_delete.go b/pkg/cmd/kit_delete.go
index 31f02609a..df9aea834 100644
--- a/pkg/cmd/kit_delete.go
+++ b/pkg/cmd/kit_delete.go
@@ -38,7 +38,7 @@ func newKitDeleteCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kitDelete
cmd := cobra.Command{
Use: "delete [integration kit1] [integration kit2] ...",
Short: "Delete integration kits deployed on Kubernetes",
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
diff --git a/pkg/cmd/kit_get.go b/pkg/cmd/kit_get.go
index da8e35007..20b5e5c0d 100644
--- a/pkg/cmd/kit_get.go
+++ b/pkg/cmd/kit_get.go
@@ -37,7 +37,7 @@ func newKitGetCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *kitGetComman
Use: "get",
Short: "Get defined Integration Kit",
Long: `Get defined Integration Kit.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(cmd, args); err != nil {
return err
diff --git a/pkg/cmd/log.go b/pkg/cmd/log.go
index c01e14bb4..d6367ca5f 100644
--- a/pkg/cmd/log.go
+++ b/pkg/cmd/log.go
@@ -42,7 +42,7 @@ func newCmdLog(rootCmdOptions *RootCmdOptions) (*cobra.Command, *logCmdOptions)
Long: `Print the logs of an integration.`,
Aliases: []string{"logs"},
Args: options.validate,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: options.run,
}
diff --git a/pkg/cmd/log_test.go b/pkg/cmd/log_test.go
index 28ba243bd..2046f640a 100644
--- a/pkg/cmd/log_test.go
+++ b/pkg/cmd/log_test.go
@@ -28,7 +28,7 @@ func TestLogsAlias(t *testing.T) {
logCommand, _ := newCmdLog(options)
rootCommand.AddCommand(logCommand)
- kamelTestPostAddCommandInit(t, rootCommand)
+ kamelTestPostAddCommandInit(t, rootCommand, options)
_, err := test.ExecuteCommand(rootCommand, "logs")
diff --git a/pkg/cmd/operator.go b/pkg/cmd/operator.go
index cec593420..f46a6dac1 100644
--- a/pkg/cmd/operator.go
+++ b/pkg/cmd/operator.go
@@ -18,16 +18,15 @@ limitations under the License.
package cmd
import (
+ "github.com/apache/camel-k/v2/pkg/cmd/operator"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/defaults"
"github.com/spf13/cobra"
-
- "github.com/apache/camel-k/v2/pkg/cmd/operator"
)
const operatorCommand = "operator"
-func newCmdOperator() (*cobra.Command, *operatorCmdOptions) {
+func newCmdOperator(rootCmdOptions *RootCmdOptions) (*cobra.Command, *operatorCmdOptions) {
options := operatorCmdOptions{}
cmd := cobra.Command{
@@ -35,7 +34,7 @@ func newCmdOperator() (*cobra.Command, *operatorCmdOptions) {
Short: "Run the Camel K operator",
Long: `Run the Camel K operator`,
Hidden: true,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, rootCmdOptions.Flags),
Run: options.run,
}
diff --git a/pkg/cmd/operator_test.go b/pkg/cmd/operator_test.go
index 481dc223d..6ffd29f50 100644
--- a/pkg/cmd/operator_test.go
+++ b/pkg/cmd/operator_test.go
@@ -35,7 +35,7 @@ func initializeOperatorCmdOptions(t *testing.T) (*operatorCmdOptions, *cobra.Com
options, rootCmd := kamelTestPreAddCommandInit()
operatorCmdOptions := addTestOperatorCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return operatorCmdOptions, rootCmd, *options
}
@@ -43,7 +43,7 @@ func initializeOperatorCmdOptions(t *testing.T) (*operatorCmdOptions, *cobra.Com
// nolint: unparam
func addTestOperatorCmd(options RootCmdOptions, rootCmd *cobra.Command) *operatorCmdOptions {
// add a testing version of operator Command
- operatorCmd, operatorOptions := newCmdOperator()
+ operatorCmd, operatorOptions := newCmdOperator(&options)
operatorCmd.RunE = func(c *cobra.Command, args []string) error {
return nil
}
diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index 562b4dac5..9b73e71ee 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -53,7 +53,7 @@ func newCmdPromote(rootCmdOptions *RootCmdOptions) (*cobra.Command, *promoteCmdO
Use: "promote my-it [--to <namespace>] [-x <promoted-operator-id>]",
Short: "Promote an Integration/Pipe from an environment to another",
Long: "Promote an Integration/Pipe from an environment to another, for example from a Development environment to a Production environment",
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: options.run,
}
diff --git a/pkg/cmd/promote_test.go b/pkg/cmd/promote_test.go
index 2f43c8546..91ebce901 100644
--- a/pkg/cmd/promote_test.go
+++ b/pkg/cmd/promote_test.go
@@ -41,7 +41,7 @@ func initializePromoteCmdOptions(t *testing.T, initObjs ...runtime.Object) (*pro
options, rootCmd := kamelTestPreAddCommandInitWithClient(fakeClient)
options.Namespace = "default"
promoteCmdOptions := addTestPromoteCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return promoteCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/rebuild.go b/pkg/cmd/rebuild.go
index d249982b1..147ee98c8 100644
--- a/pkg/cmd/rebuild.go
+++ b/pkg/cmd/rebuild.go
@@ -37,7 +37,7 @@ func newCmdRebuild(rootCmdOptions *RootCmdOptions) (*cobra.Command, *rebuildCmdO
Use: "rebuild [integration1] [integration2] ...",
Short: "Clear the state of integrations to rebuild them.",
Long: `Clear the state of one or more integrations causing a rebuild. Rebuild always targets Integration CR, the operator is in charge to apply any change to the related bindings resources (if any).`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
diff --git a/pkg/cmd/rebuild_test.go b/pkg/cmd/rebuild_test.go
index 06411dd1a..5d9142299 100644
--- a/pkg/cmd/rebuild_test.go
+++ b/pkg/cmd/rebuild_test.go
@@ -34,7 +34,7 @@ func initializeRebuildCmdOptions(t *testing.T) (*rebuildCmdOptions, *cobra.Comma
options, rootCmd := kamelTestPreAddCommandInit()
rebuildCmdOptions := addTestRebuildCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return rebuildCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/reset.go b/pkg/cmd/reset.go
index 1e6ece75d..ec9416ff2 100644
--- a/pkg/cmd/reset.go
+++ b/pkg/cmd/reset.go
@@ -38,7 +38,7 @@ func newCmdReset(rootCmdOptions *RootCmdOptions) (*cobra.Command, *resetCmdOptio
Use: "reset",
Short: "Reset the Camel K installation",
Long: `Reset the Camel K installation by deleting everything except current integration profile.`,
- PreRunE: decode(&options),
+ PreRunE: decode(&options, options.Flags),
Run: options.reset,
}
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index 70c18209e..e7b9b8313 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -23,7 +23,6 @@ import (
"fmt"
"os"
"strings"
- "sync"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -40,9 +39,6 @@ const kamelCommandLongDescription = `Apache Camel K is a lightweight integration
superpowers.
`
-// Mutex to synchronize flag operations as viper library is not able to handle concurrency.
-var m = sync.Mutex{}
-
// RootCmdOptions --.
// nolint: containedctx
type RootCmdOptions struct {
@@ -50,6 +46,7 @@ type RootCmdOptions struct {
Context context.Context `mapstructure:"-"`
ContextCancel context.CancelFunc `mapstructure:"-"`
_client client.Client `mapstructure:"-"`
+ Flags *viper.Viper `mapstructure:"-"`
KubeConfig string `mapstructure:"kube-config"`
Namespace string `mapstructure:"namespace"`
Verbose bool `mapstructure:"verbose" yaml:",omitempty"`
@@ -62,6 +59,7 @@ func NewKamelCommand(ctx context.Context) (*cobra.Command, error) {
RootContext: ctx,
Context: childCtx,
ContextCancel: childCancel,
+ Flags: viper.New(),
}
cmd := kamelPreAddCommandInit(&options)
@@ -71,7 +69,7 @@ func NewKamelCommand(ctx context.Context) (*cobra.Command, error) {
return cmd, err
}
- err := kamelPostAddCommandInit(cmd)
+ err := kamelPostAddCommandInit(cmd, options.Flags)
return cmd, err
}
@@ -96,12 +94,8 @@ func kamelPreAddCommandInit(options *RootCmdOptions) *cobra.Command {
return &cmd
}
-func kamelPostAddCommandInit(cmd *cobra.Command) error {
- // Requires synchronization as viper bind flag is not able to handle concurrency
- m.Lock()
- defer m.Unlock()
-
- if err := bindPFlagsHierarchy(cmd); err != nil {
+func kamelPostAddCommandInit(cmd *cobra.Command, v *viper.Viper) error {
+ if err := bindPFlagsHierarchy(cmd, v); err != nil {
return err
}
@@ -110,26 +104,26 @@ func kamelPostAddCommandInit(cmd *cobra.Command) error {
configName = DefaultConfigName
}
- viper.SetConfigName(configName)
+ v.SetConfigName(configName)
configPath := os.Getenv("KAMEL_CONFIG_PATH")
if configPath != "" {
// if a specific config path is set, don't add
// default locations
- viper.AddConfigPath(configPath)
+ v.AddConfigPath(configPath)
} else {
- viper.AddConfigPath(".")
- viper.AddConfigPath(".kamel")
- viper.AddConfigPath("$HOME/.kamel")
+ v.AddConfigPath(".")
+ v.AddConfigPath(".kamel")
+ v.AddConfigPath("$HOME/.kamel")
}
- viper.AutomaticEnv()
- viper.SetEnvKeyReplacer(strings.NewReplacer(
+ v.AutomaticEnv()
+ v.SetEnvKeyReplacer(strings.NewReplacer(
".", "_",
"-", "_",
))
- if err := viper.ReadInConfig(); err != nil {
+ if err := v.ReadInConfig(); err != nil {
if !errors.As(err, &viper.ConfigFileNotFoundError{}) {
return err
}
@@ -151,7 +145,7 @@ func addKamelSubcommands(cmd *cobra.Command, options *RootCmdOptions) {
cmd.AddCommand(cmdOnly(newCmdReset(options)))
cmd.AddCommand(newCmdDescribe(options))
cmd.AddCommand(cmdOnly(newCmdRebuild(options)))
- cmd.AddCommand(cmdOnly(newCmdOperator()))
+ cmd.AddCommand(cmdOnly(newCmdOperator(options)))
cmd.AddCommand(cmdOnly(newCmdBuilder(options)))
cmd.AddCommand(cmdOnly(newCmdDebug(options)))
cmd.AddCommand(cmdOnly(newCmdDump(options)))
@@ -187,7 +181,7 @@ func (command *RootCmdOptions) preRun(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("cannot get command client: %w", err)
}
if command.Namespace == "" {
- current := viper.GetString("kamel.config.default-namespace")
+ current := command.Flags.GetString("kamel.config.default-namespace")
if current == "" {
defaultNS, err := c.GetCurrentNamespace(command.KubeConfig)
if err != nil {
diff --git a/pkg/cmd/root_test.go b/pkg/cmd/root_test.go
index 6c9afd3ce..40cbead6a 100644
--- a/pkg/cmd/root_test.go
+++ b/pkg/cmd/root_test.go
@@ -29,10 +29,10 @@ import (
"github.com/spf13/viper"
)
-func kamelTestPostAddCommandInit(t *testing.T, rootCmd *cobra.Command) {
+func kamelTestPostAddCommandInit(t *testing.T, rootCmd *cobra.Command, options *RootCmdOptions) {
t.Helper()
- err := kamelPostAddCommandInit(rootCmd)
+ err := kamelPostAddCommandInit(rootCmd, options.Flags)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@@ -41,6 +41,7 @@ func kamelTestPostAddCommandInit(t *testing.T, rootCmd *cobra.Command) {
func kamelTestPreAddCommandInitWithClient(client client.Client) (*RootCmdOptions, *cobra.Command) {
options := RootCmdOptions{
Context: context.Background(),
+ Flags: viper.New(),
_client: client,
}
rootCmd := kamelPreAddCommandInit(&options)
@@ -54,13 +55,13 @@ func kamelTestPreAddCommandInit() (*RootCmdOptions, *cobra.Command) {
}
func TestLoadFromEnvVar(t *testing.T) {
- defer teardown(t)
// shows how to include a "," character inside an env value see VAR1 value
if err := os.Setenv("KAMEL_RUN_ENVS", "\"VAR1=value,\"\"othervalue\"\"\",VAR2=value2"); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+ defer teardown(t, runCmdOptions.Flags)
_, err := test.ExecuteCommand(rootCmd, "run", "route.java")
if err != nil {
@@ -75,12 +76,12 @@ func TestLoadFromEnvVar(t *testing.T) {
}
func TestLoadFromFile(t *testing.T) {
+ runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+
// shows how to include a "," character inside a property value see VAR1 value
propertiesFile := []byte(`kamel.run.envs: "VAR1=value,""othervalue""",VAR2=value2`)
- viper.SetConfigType("properties")
- readViperConfigFromBytes(t, propertiesFile)
-
- runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+ runCmdOptions.Flags.SetConfigType("properties")
+ readViperConfigFromBytes(t, runCmdOptions.Flags, propertiesFile)
_, err := test.ExecuteCommand(rootCmd, "run", "route.java")
if err != nil {
@@ -95,16 +96,16 @@ func TestLoadFromFile(t *testing.T) {
}
func TestPrecedenceEnvVarOverFile(t *testing.T) {
- defer teardown(t)
if err := os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar"); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
+ runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+ defer teardown(t, runCmdOptions.Flags)
+
propertiesFile := []byte(`kamel.run.envs: VAR2=file`)
viper.SetConfigType("properties")
- readViperConfigFromBytes(t, propertiesFile)
-
- runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+ readViperConfigFromBytes(t, runCmdOptions.Flags, propertiesFile)
_, err := test.ExecuteCommand(rootCmd, "run", "route.java")
if err != nil {
@@ -119,16 +120,16 @@ func TestPrecedenceEnvVarOverFile(t *testing.T) {
}
func TestPrecedenceCommandLineOverEverythingElse(t *testing.T) {
- defer teardown(t)
if err := os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar"); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
+ runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+ defer teardown(t, runCmdOptions.Flags)
+
propertiesFile := []byte(`kamel.run.envs: VAR2=file`)
viper.SetConfigType("properties")
- readViperConfigFromBytes(t, propertiesFile)
-
- runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
+ readViperConfigFromBytes(t, runCmdOptions.Flags, propertiesFile)
_, err := test.ExecuteCommand(rootCmd, "run", "route.java", "--env", "VAR3=commandLine")
if err != nil {
@@ -142,20 +143,20 @@ func TestPrecedenceCommandLineOverEverythingElse(t *testing.T) {
}
}
-func readViperConfigFromBytes(t *testing.T, propertiesFile []byte) {
+func readViperConfigFromBytes(t *testing.T, v *viper.Viper, propertiesFile []byte) {
t.Helper()
- unexpectedErr := viper.ReadConfig(bytes.NewReader(propertiesFile))
+ unexpectedErr := v.ReadConfig(bytes.NewReader(propertiesFile))
if unexpectedErr != nil {
t.Fatalf("Unexpected error: %v", unexpectedErr)
}
}
// We must ALWAYS clean the environment variables and viper library properties to avoid mess up with the rest of the tests.
-func teardown(t *testing.T) {
+func teardown(t *testing.T, v *viper.Viper) {
t.Helper()
if err := os.Setenv("KAMEL_RUN_ENVS", ""); err != nil {
t.Fatalf("Unexpected error: %v", err)
}
- readViperConfigFromBytes(t, make([]byte, 0))
+ readViperConfigFromBytes(t, v, make([]byte, 0))
}
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 4c33c4154..548f642a0 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -188,11 +188,7 @@ func (o *runCmdOptions) decode(cmd *cobra.Command, args []string) error {
// load from kamel.run (1)
pathToRoot := pathToRoot(cmd)
- // Requires synchronization as viper bind flag is not able to handle concurrency
- m.Lock()
- defer m.Unlock()
-
- if err := decodeKey(o, pathToRoot); err != nil {
+ if err := decodeKey(o, pathToRoot, o.Flags.AllSettings()); err != nil {
return err
}
@@ -217,7 +213,7 @@ func (o *runCmdOptions) decode(cmd *cobra.Command, args []string) error {
if name != "" {
// load from kamel.run.integration.$name (2)
pathToRoot += ".integration." + name
- if err := decodeKey(o, pathToRoot); err != nil {
+ if err := decodeKey(o, pathToRoot, o.Flags.AllSettings()); err != nil {
return err
}
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 03286b10d..625a850d4 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -60,7 +60,7 @@ func initializeRunCmdOptions(t *testing.T) (*runCmdOptions, *cobra.Command, Root
options, rootCmd := kamelTestPreAddCommandInit()
runCmdOptions := addTestRunCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return runCmdOptions, rootCmd, *options
}
@@ -75,7 +75,7 @@ func initializeRunCmdOptionsWithOutput(t *testing.T) (*runCmdOptions, *cobra.Com
options, rootCmd := kamelTestPreAddCommandInitWithClient(fakeClient)
runCmdOptions := addTestRunCmdWithOutput(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return runCmdOptions, rootCmd, *options
}
diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go
index 489da6c1f..b433dcf4c 100644
--- a/pkg/cmd/uninstall.go
+++ b/pkg/cmd/uninstall.go
@@ -24,8 +24,6 @@ import (
"time"
"github.com/spf13/cobra"
- "github.com/spf13/viper"
-
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -108,17 +106,13 @@ var defaultListOptions = metav1.ListOptions{
func (o *uninstallCmdOptions) decode(cmd *cobra.Command, _ []string) error {
path := pathToRoot(cmd)
- // Requires synchronization as viper bind flag is not able to handle concurrency
- m.Lock()
- defer m.Unlock()
-
- if err := decodeKey(o, path); err != nil {
+ if err := decodeKey(o, path, o.Flags.AllSettings()); err != nil {
return err
}
- o.OlmOptions.OperatorName = viper.GetString(path + ".olm-operator-name")
- o.OlmOptions.Package = viper.GetString(path + ".olm-package")
- o.OlmOptions.GlobalNamespace = viper.GetString(path + ".olm-global-namespace")
+ o.OlmOptions.OperatorName = o.Flags.GetString(path + ".olm-operator-name")
+ o.OlmOptions.Package = o.Flags.GetString(path + ".olm-package")
+ o.OlmOptions.GlobalNamespace = o.Flags.GetString(path + ".olm-global-namespace")
return nil
}
diff --git a/pkg/cmd/uninstall_test.go b/pkg/cmd/uninstall_test.go
index 846696022..6c20d90b2 100644
--- a/pkg/cmd/uninstall_test.go
+++ b/pkg/cmd/uninstall_test.go
@@ -43,7 +43,7 @@ func TestUninstallOlmFlags(t *testing.T) {
uninstallCmdOptions := addTestUninstallCmd(options, cmd)
- kamelTestPostAddCommandInit(t, cmd)
+ kamelTestPostAddCommandInit(t, cmd, options)
_, err := test.ExecuteCommand(cmd, "uninstall", "--olm=false", "--olm-operator-name", "my-operator")
require.NoError(t, err)
@@ -56,7 +56,7 @@ func TestUninstallSkipFlags(t *testing.T) {
uninstallCmdOptions := addTestUninstallCmd(options, cmd)
- kamelTestPostAddCommandInit(t, cmd)
+ kamelTestPostAddCommandInit(t, cmd, options)
_, err := test.ExecuteCommand(cmd, "uninstall", "--skip-crd", "--skip-cluster-roles", "--skip-integration-platform", "--skip-integration-profile")
require.NoError(t, err)
@@ -71,7 +71,7 @@ func TestUninstallAllFlag(t *testing.T) {
uninstallCmdOptions := addTestUninstallCmd(options, cmd)
- kamelTestPostAddCommandInit(t, cmd)
+ kamelTestPostAddCommandInit(t, cmd, options)
_, err := test.ExecuteCommand(cmd, "uninstall", "--all")
require.NoError(t, err)
diff --git a/pkg/cmd/util.go b/pkg/cmd/util.go
index aec422477..1ecdcf35e 100644
--- a/pkg/cmd/util.go
+++ b/pkg/cmd/util.go
@@ -59,13 +59,13 @@ func DeleteIntegration(ctx context.Context, c client.Client, name string, namesp
return c.Delete(ctx, &integration)
}
-func bindPFlagsHierarchy(cmd *cobra.Command) error {
+func bindPFlagsHierarchy(cmd *cobra.Command, v *viper.Viper) error {
for _, c := range cmd.Commands() {
- if err := bindPFlags(c); err != nil {
+ if err := bindPFlags(c, v); err != nil {
return err
}
- if err := bindPFlagsHierarchy(c); err != nil {
+ if err := bindPFlagsHierarchy(c, v); err != nil {
return err
}
}
@@ -73,7 +73,7 @@ func bindPFlagsHierarchy(cmd *cobra.Command) error {
return nil
}
-func bindPFlags(cmd *cobra.Command) error {
+func bindPFlags(cmd *cobra.Command, v *viper.Viper) error {
prefix := pathToRoot(cmd)
pl := p.NewClient()
@@ -82,7 +82,7 @@ func bindPFlags(cmd *cobra.Command) error {
name = strings.ReplaceAll(name, "_", "-")
name = strings.ReplaceAll(name, ".", "-")
- if err := viper.BindPFlag(prefix+"."+name, flag); err != nil {
+ if err := v.BindPFlag(prefix+"."+name, flag); err != nil {
log.Printf("error binding flag %s with prefix %s to viper: %v", flag.Name, prefix, err)
}
@@ -91,7 +91,7 @@ func bindPFlags(cmd *cobra.Command) error {
// possible to know what is the type of the flag
flagType := strings.ToUpper(flag.Value.Type())
if strings.Contains(flagType, "SLICE") || strings.Contains(flagType, "ARRAY") {
- if err := viper.BindPFlag(prefix+"."+pl.Plural(name), flag); err != nil {
+ if err := v.BindPFlag(prefix+"."+pl.Plural(name), flag); err != nil {
log.Printf("error binding plural flag %s with prefix %s to viper: %v", flag.Name, prefix, err)
}
}
@@ -113,9 +113,8 @@ func pathToRoot(cmd *cobra.Command) string {
return path
}
-func decodeKey(target interface{}, key string) error {
+func decodeKey(target interface{}, key string, settings map[string]any) error {
nodes := strings.Split(key, ".")
- settings := viper.AllSettings()
for _, node := range nodes {
v := settings[node]
@@ -154,14 +153,10 @@ func decodeKey(target interface{}, key string) error {
return nil
}
-func decode(target interface{}) func(*cobra.Command, []string) error {
+func decode(target interface{}, v *viper.Viper) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
- // Requires synchronization as viper bind flag is not able to handle concurrency
- m.Lock()
- defer m.Unlock()
-
path := pathToRoot(cmd)
- if err := decodeKey(target, path); err != nil {
+ if err := decodeKey(target, path, v.AllSettings()); err != nil {
return err
}
diff --git a/pkg/cmd/util_config.go b/pkg/cmd/util_config.go
index df7b7dcc8..6212426f3 100644
--- a/pkg/cmd/util_config.go
+++ b/pkg/cmd/util_config.go
@@ -57,7 +57,7 @@ func LoadConfiguration() (*Config, error) {
return loadConfiguration(viper.ConfigFileUsed())
}
-// LoadConfiguration loads a kamel configuration file from a specific location.
+// LoadConfigurationFrom loads a kamel configuration file from a specific location.
func LoadConfigurationFrom(location string) (*Config, error) {
return loadConfiguration(location)
}
diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go
index 1f635209d..e9bc20b90 100644
--- a/pkg/cmd/version.go
+++ b/pkg/cmd/version.go
@@ -50,7 +50,7 @@ func newCmdVersion(rootCmdOptions *RootCmdOptions) (*cobra.Command, *versionCmdO
Use: "version",
Short: "Display client version",
Long: `Display Camel K client version.`,
- PersistentPreRunE: decode(&options),
+ PersistentPreRunE: decode(&options, options.Flags),
PreRunE: options.preRunE,
RunE: options.run,
Annotations: make(map[string]string),
diff --git a/pkg/cmd/version_test.go b/pkg/cmd/version_test.go
index f57987711..dfd33a54b 100644
--- a/pkg/cmd/version_test.go
+++ b/pkg/cmd/version_test.go
@@ -42,7 +42,7 @@ func initializeVersionCmdOptions(t *testing.T, initObjs ...runtime.Object) (*ver
require.NoError(t, err)
options, rootCmd := kamelTestPreAddCommandInitWithClient(fakeClient)
versionCmdOptions := addTestVersionCmd(*options, rootCmd)
- kamelTestPostAddCommandInit(t, rootCmd)
+ kamelTestPostAddCommandInit(t, rootCmd, options)
return versionCmdOptions, rootCmd, *options
}
diff --git a/script/Makefile b/script/Makefile
index 4dd8283e5..f518b09e4 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -94,7 +94,7 @@ KAMELET_CATALOG_REPO_TAG := v4.0.1
DO_TEST_PREBUILD ?= true
TEST_PREBUILD = build
# Tests may run in parallel to each other. This count sets the amount of tests run in parallel. (default value usually is GOMAXPROCS)
-TEST_COMMON_PARALLEL_COUNT ?= 2
+TEST_COMMON_PARALLEL_COUNT ?= 4
TEST_ADVANCED_PARALLEL_COUNT ?= 4
# OLM (Operator Lifecycle Manager and Operator Hub): uncomment to override operator settings at build time