This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch 3308/add-publish-strategy-option-to-install in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 658a744caade7fb13935763f7f0e44384bc608f1 Author: Nicolas Filotto <[email protected]> AuthorDate: Mon Sep 12 15:19:39 2022 +0200 feat(cli): Allow to set build publish strategy options from install cmd --- e2e/namespace/install/cli/install_test.go | 15 +++++ pkg/cmd/install.go | 103 ++++++++++++++++++------------ 2 files changed, 76 insertions(+), 42 deletions(-) diff --git a/e2e/namespace/install/cli/install_test.go b/e2e/namespace/install/cli/install_test.go index aee7732c9..af8c68265 100644 --- a/e2e/namespace/install/cli/install_test.go +++ b/e2e/namespace/install/cli/install_test.go @@ -173,3 +173,18 @@ func TestInstallDebugLogging(t *testing.T) { Eventually(logs).Should(ContainSubstring("DEBUG level messages will be logged")) }) } + +func TestInstallWithPublishStrategyOptions(t *testing.T) { + WithNewTestNamespace(t, func(ns string) { + operatorID := fmt.Sprintf("camel-k-%s", ns) + Expect(KamelInstallWithID(operatorID, ns, "--build-publish-strategy-option", "foo1=bar1", "--build-publish-strategy-option", "foo2=bar2").Execute()).To(Succeed()) + Eventually(OperatorPod(ns)).ShouldNot(BeNil()) + Eventually(Platform(ns)).ShouldNot(BeNil()) + Eventually(func() map[string]string { + return Platform(ns)().Spec.Build.PublishStrategyOptions + }).Should(HaveKeyWithValue("foo1", "bar1")) + Eventually(func() map[string]string { + return Platform(ns)().Spec.Build.PublishStrategyOptions + }).Should(HaveKeyWithValue("foo2", "bar2")) + }) +} diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index 3a86bd435..060943048 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -108,6 +108,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *installCmdO cmd.Flags().String("operator-image-pull-policy", "", "Set the operator ImagePullPolicy used for the operator deployment") cmd.Flags().String("build-strategy", "", "Set the build strategy") cmd.Flags().String("build-publish-strategy", "", "Set the build publish strategy") + cmd.Flags().StringArray("build-publish-strategy-option", nil, "Add a build publish strategy option, as <name=value>") cmd.Flags().String("build-timeout", "", "Set how long the build process can last") cmd.Flags().String("trait-profile", "", "The profile to use for traits") @@ -171,47 +172,48 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *installCmdO type installCmdOptions struct { *RootCmdOptions - Wait bool `mapstructure:"wait"` - BuildahImage string `mapstructure:"buildah-image"` - ClusterSetupOnly bool `mapstructure:"cluster-setup"` - SkipOperatorSetup bool `mapstructure:"skip-operator-setup"` - SkipClusterSetup bool `mapstructure:"skip-cluster-setup"` - SkipRegistrySetup bool `mapstructure:"skip-registry-setup"` - SkipDefaultKameletsSetup bool `mapstructure:"skip-default-kamelets-setup"` - ExampleSetup bool `mapstructure:"example"` - Global bool `mapstructure:"global"` - KanikoBuildCache bool `mapstructure:"kaniko-build-cache"` - KanikoExecutorImage string `mapstructure:"kaniko-executor-image"` - KanikoWarmerImage string `mapstructure:"kaniko-warmer-image"` - Save bool `mapstructure:"save" kamel:"omitsave"` - Force bool `mapstructure:"force"` - Olm bool `mapstructure:"olm"` - ClusterType string `mapstructure:"cluster-type"` - OutputFormat string `mapstructure:"output"` - RuntimeVersion string `mapstructure:"runtime-version"` - BaseImage string `mapstructure:"base-image"` - OperatorID string `mapstructure:"operator-id"` - OperatorImage string `mapstructure:"operator-image"` - OperatorImagePullPolicy string `mapstructure:"operator-image-pull-policy"` - BuildStrategy string `mapstructure:"build-strategy"` - BuildPublishStrategy string `mapstructure:"build-publish-strategy"` - BuildTimeout string `mapstructure:"build-timeout"` - MavenExtensions []string `mapstructure:"maven-extensions"` - MavenLocalRepository string `mapstructure:"maven-local-repository"` - MavenProperties []string `mapstructure:"maven-properties"` - MavenRepositories []string `mapstructure:"maven-repositories"` - MavenSettings string `mapstructure:"maven-settings"` - MavenCASecret string `mapstructure:"maven-ca-secret"` - MavenCLIOptions []string `mapstructure:"maven-cli-options"` - HealthPort int32 `mapstructure:"health-port"` - Monitoring bool `mapstructure:"monitoring"` - MonitoringPort int32 `mapstructure:"monitoring-port"` - TraitProfile string `mapstructure:"trait-profile"` - Tolerations []string `mapstructure:"tolerations"` - NodeSelectors []string `mapstructure:"node-selectors"` - ResourcesRequirements []string `mapstructure:"operator-resources"` - LogLevel string `mapstructure:"log-level"` - EnvVars []string `mapstructure:"operator-env-vars"` + Wait bool `mapstructure:"wait"` + BuildahImage string `mapstructure:"buildah-image"` + ClusterSetupOnly bool `mapstructure:"cluster-setup"` + SkipOperatorSetup bool `mapstructure:"skip-operator-setup"` + SkipClusterSetup bool `mapstructure:"skip-cluster-setup"` + SkipRegistrySetup bool `mapstructure:"skip-registry-setup"` + SkipDefaultKameletsSetup bool `mapstructure:"skip-default-kamelets-setup"` + ExampleSetup bool `mapstructure:"example"` + Global bool `mapstructure:"global"` + KanikoBuildCache bool `mapstructure:"kaniko-build-cache"` + KanikoExecutorImage string `mapstructure:"kaniko-executor-image"` + KanikoWarmerImage string `mapstructure:"kaniko-warmer-image"` + Save bool `mapstructure:"save" kamel:"omitsave"` + Force bool `mapstructure:"force"` + Olm bool `mapstructure:"olm"` + ClusterType string `mapstructure:"cluster-type"` + OutputFormat string `mapstructure:"output"` + RuntimeVersion string `mapstructure:"runtime-version"` + BaseImage string `mapstructure:"base-image"` + OperatorID string `mapstructure:"operator-id"` + OperatorImage string `mapstructure:"operator-image"` + OperatorImagePullPolicy string `mapstructure:"operator-image-pull-policy"` + BuildStrategy string `mapstructure:"build-strategy"` + BuildPublishStrategy string `mapstructure:"build-publish-strategy"` + BuildPublishStrategyOptions []string `mapstructure:"build-publish-strategy-options"` + BuildTimeout string `mapstructure:"build-timeout"` + MavenExtensions []string `mapstructure:"maven-extensions"` + MavenLocalRepository string `mapstructure:"maven-local-repository"` + MavenProperties []string `mapstructure:"maven-properties"` + MavenRepositories []string `mapstructure:"maven-repositories"` + MavenSettings string `mapstructure:"maven-settings"` + MavenCASecret string `mapstructure:"maven-ca-secret"` + MavenCLIOptions []string `mapstructure:"maven-cli-options"` + HealthPort int32 `mapstructure:"health-port"` + Monitoring bool `mapstructure:"monitoring"` + MonitoringPort int32 `mapstructure:"monitoring-port"` + TraitProfile string `mapstructure:"trait-profile"` + Tolerations []string `mapstructure:"tolerations"` + NodeSelectors []string `mapstructure:"node-selectors"` + ResourcesRequirements []string `mapstructure:"operator-resources"` + LogLevel string `mapstructure:"log-level"` + EnvVars []string `mapstructure:"operator-env-vars"` registry v1.RegistrySpec registryAuth registry.Auth @@ -489,7 +491,11 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error { } } } - + if len(o.BuildPublishStrategyOptions) > 0 { + if err = o.addBuildPublishStrategyOptions(&platform.Spec.Build); err != nil { + return err + } + } if platform.Spec.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyKaniko { kanikoBuildCacheFlag := cobraCmd.Flags().Lookup("kaniko-build-cache") if kanikoBuildCacheFlag.Changed { @@ -734,6 +740,19 @@ func (o *installCmdOptions) validate(_ *cobra.Command, _ []string) error { return result } +// addBuildPublishStrategyOptions parses and adds all the build publish strategy options to the given IntegrationPlatformBuildSpec. +func (o *installCmdOptions) addBuildPublishStrategyOptions(build *v1.IntegrationPlatformBuildSpec) error { + for _, option := range o.BuildPublishStrategyOptions { + kv := strings.Split(option, "=") + if len(kv) == 2 { + build.AddOption(kv[0], kv[1]) + } else { + return fmt.Errorf("build publish strategy option '%s' not in the expected format (name=value)", option) + } + } + return nil +} + func decodeMavenSettings(mavenSettings string) (v1.ValueSource, error) { sub := make([]string, 0) rex := regexp.MustCompile(`^(configmap|secret):([a-zA-Z0-9][a-zA-Z0-9-]*)(/([a-zA-Z0-9].*))?$`)
