You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/03/01 14:34:40 UTC

[camel-k] 01/18: chore(cmd): remove deprecated flags

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 118e35291f61f85068a7eb8270a4ba88f2d62d34
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jan 24 11:09:49 2022 +0100

    chore(cmd): remove deprecated flags
    
    * --property-file
    * --configmap
    * -- secret
    
    Ref #2751
---
 .../modules/ROOT/pages/kamelets/kamelets-user.adoc |  2 +-
 e2e/common/languages/java_test.go                  |  2 +-
 examples/kafka/README.md                           |  2 +-
 examples/kafka/sasl_ssl/README.md                  |  4 +-
 examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java  |  2 +-
 examples/kafka/sasl_ssl/SaslSSLKafkaProducer.java  |  2 +-
 examples/kamelets/error-handler/readme.md          |  2 +-
 pkg/cmd/run.go                                     | 42 ++---------------
 pkg/cmd/run_test.go                                | 52 ----------------------
 9 files changed, 12 insertions(+), 98 deletions(-)

diff --git a/docs/modules/ROOT/pages/kamelets/kamelets-user.adoc b/docs/modules/ROOT/pages/kamelets/kamelets-user.adoc
index 7896031..b200d6f 100644
--- a/docs/modules/ROOT/pages/kamelets/kamelets-user.adoc
+++ b/docs/modules/ROOT/pages/kamelets/kamelets-user.adoc
@@ -198,7 +198,7 @@ Then the integration can be run with the following command:
 
 [source,shell]
 ----
-kamel run example.groovy --property-file example.properties
+kamel run example.groovy --property file:example.properties
 ----
 
 ==== 3. Implicit configuration using secrets
diff --git a/e2e/common/languages/java_test.go b/e2e/common/languages/java_test.go
index 60443bc..cbfc0da 100644
--- a/e2e/common/languages/java_test.go
+++ b/e2e/common/languages/java_test.go
@@ -46,7 +46,7 @@ func TestRunSimpleJavaExamples(t *testing.T) {
 		})
 
 		t.Run("run java with properties", func(t *testing.T) {
-			Expect(Kamel("run", "-n", ns, "files/Prop.java", "--property-file", "files/prop.properties").Execute()).To(Succeed())
+			Expect(Kamel("run", "-n", ns, "files/Prop.java", "--property", "file:files/prop.properties").Execute()).To(Succeed())
 			Eventually(IntegrationPodPhase(ns, "prop"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
 			Eventually(IntegrationConditionStatus(ns, "prop", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
 			Eventually(IntegrationLogs(ns, "prop"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
diff --git a/examples/kafka/README.md b/examples/kafka/README.md
index 77b2435..a651849 100644
--- a/examples/kafka/README.md
+++ b/examples/kafka/README.md
@@ -21,7 +21,7 @@ IMPORTANT: The kafka.host value in application.properties needs to be set to the
 
 Finally run this sample using the command:
 ```
-./kamel run examples/kafka/SampleKafkaConsumer.java --configmap=kafka.props
+./kamel run examples/kafka/SampleKafkaConsumer.java --config=configmap:kafka.props
 ```
 
 To create messages to be read use the producer command from the Strimzi page:
diff --git a/examples/kafka/sasl_ssl/README.md b/examples/kafka/sasl_ssl/README.md
index 5ec7d1f..d6a5a29 100644
--- a/examples/kafka/sasl_ssl/README.md
+++ b/examples/kafka/sasl_ssl/README.md
@@ -19,7 +19,7 @@ kubectl create secret generic kafka-props --from-file application.properties
 At this stage, run a producer integration to fill the topic with a message, every 10 seconds:
 
 ```
-kamel run --secret kafka-props SaslSSLKafkaProducer.java --dev
+kamel run --config secret:kafka-props SaslSSLKafkaProducer.java --dev
 ```
 
 The producer will create a new message every 10 seconds, push into the topic and log some information.
@@ -38,7 +38,7 @@ The producer will create a new message every 10 seconds, push into the topic and
 Now, open another shell and run the consumer integration using the command:
 
 ```
-kamel run --secret kafka-props SaslSSLKafkaConsumer.java --dev
+kamel run --config secret:kafka-props SaslSSLKafkaConsumer.java --dev
 ```
 
 A consumer will start logging the events found in the Topic:
diff --git a/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java b/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java
index 30072db..42ed3f5 100644
--- a/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java
+++ b/examples/kafka/sasl_ssl/SaslSSLKafkaConsumer.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-// kamel run --secret kafka-props SaslSSLKafkaConsumer.java --dev
+// kamel run --config secret:kafka-props SaslSSLKafkaConsumer.java --dev
 
 import org.apache.camel.builder.RouteBuilder;
 
diff --git a/examples/kafka/sasl_ssl/SaslSSLKafkaProducer.java b/examples/kafka/sasl_ssl/SaslSSLKafkaProducer.java
index 11e3f19..85caeb5 100644
--- a/examples/kafka/sasl_ssl/SaslSSLKafkaProducer.java
+++ b/examples/kafka/sasl_ssl/SaslSSLKafkaProducer.java
@@ -16,7 +16,7 @@
  */
 
 // kubectl create secret generic kafka-props --from-file application.properties
-// kamel run --secret kafka-props SaslSSLKafkaProducer.java --dev
+// kamel run --config secret:kafka-props SaslSSLKafkaProducer.java --dev
 
 import org.apache.camel.builder.RouteBuilder;
 
diff --git a/examples/kamelets/error-handler/readme.md b/examples/kamelets/error-handler/readme.md
index 2c400dc..27c17ef 100644
--- a/examples/kamelets/error-handler/readme.md
+++ b/examples/kamelets/error-handler/readme.md
@@ -114,7 +114,7 @@ As soon as the `Integration` starts, it will log the events on the `ok` log chan
 If you're curious to know what was going on in the DLC side, you can use the example you found in [kafka sasl ssl consumer](../kafka/sasl_ssl/):
 
 ```
-kamel run --secret kafka-props SaslSSLKafkaConsumer.java --dev
+kamel run --config secret:kafka-props SaslSSLKafkaConsumer.java --dev
 ...
 [1] 2021-04-29 08:57:08,636 INFO  [org.apa.kaf.com.uti.AppInfoParser] (Camel (camel-1) thread #0 - KafkaConsumer[my-first-test]) Kafka commitId: 448719dc99a19793
 [1] 2021-04-29 08:57:08,636 INFO  [org.apa.kaf.com.uti.AppInfoParser] (Camel (camel-1) thread #0 - KafkaConsumer[my-first-test]) Kafka startTimeMs: 1619686628635
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 9f91312..3d0aa32 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -80,8 +80,6 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().StringArray("build-property", nil, "Add a build time property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
 	cmd.Flags().StringArray("config", nil, "Add a runtime configuration from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key], where name represents the local file path or the configmap/secret name and key optionally represents the configmap/secret key to be filtered)")
 	cmd.Flags().StringArray("resource", nil, "Add a runtime resource from a Configmap, a Secret or a file (syntax: [configmap|secret|file]:name[/key][@path], where name represents the local file path or the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path)")
-	cmd.Flags().StringArray("configmap", nil, "[Deprecated] Add a ConfigMap")
-	cmd.Flags().StringArray("secret", nil, "[Deprecated] Add a Secret")
 	cmd.Flags().StringArray("maven-repository", nil, "Add a maven repository")
 	cmd.Flags().Bool("logs", false, "Print integration logs")
 	cmd.Flags().Bool("sync", false, "Synchronize the local source file with the cluster, republishing at each change")
@@ -94,7 +92,6 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().StringArray("open-api", nil, "Add an OpenAPI spec (syntax: [configmap|file]:name)")
 	cmd.Flags().StringArrayP("volume", "v", nil, "Mount a volume into the integration container. E.g \"-v pvcname:/container/path\"")
 	cmd.Flags().StringArrayP("env", "e", nil, "Set an environment variable in the integration container. E.g \"-e MY_VAR=my-value\"")
-	cmd.Flags().StringArray("property-file", nil, "[Deprecated] Bind a property file to the integration. E.g. \"--property-file integration.properties\"")
 	cmd.Flags().StringArray("annotation", nil, "Add an annotation to the integration. E.g. \"--annotation my.company=hello\"")
 	cmd.Flags().StringArray("label", nil, "Add a label to the integration. E.g. \"--label my.company=hello\"")
 	cmd.Flags().StringArray("source", nil, "Add source file to your integration, this is added to the list of files listed as arguments of the command")
@@ -129,17 +126,13 @@ type runCmdOptions struct {
 	Properties      []string `mapstructure:"properties" yaml:",omitempty"`
 	BuildProperties []string `mapstructure:"build-properties" yaml:",omitempty"`
 	Configs         []string `mapstructure:"configs" yaml:",omitempty"`
-	ConfigMaps      []string `mapstructure:"configmaps" yaml:",omitempty"`
-	Secrets         []string `mapstructure:"secrets" yaml:",omitempty"`
 	Repositories    []string `mapstructure:"maven-repositories" yaml:",omitempty"`
 	Traits          []string `mapstructure:"traits" yaml:",omitempty"`
 	Volumes         []string `mapstructure:"volumes" yaml:",omitempty"`
 	EnvVars         []string `mapstructure:"envs" yaml:",omitempty"`
-	// Deprecated: since 1.5
-	PropertyFiles []string `mapstructure:"property-files" yaml:",omitempty"`
-	Labels        []string `mapstructure:"labels" yaml:",omitempty"`
-	Annotations   []string `mapstructure:"annotations" yaml:",omitempty"`
-	Sources       []string `mapstructure:"sources" yaml:",omitempty"`
+	Labels          []string `mapstructure:"labels" yaml:",omitempty"`
+	Annotations     []string `mapstructure:"annotations" yaml:",omitempty"`
+	Sources         []string `mapstructure:"sources" yaml:",omitempty"`
 }
 
 func (o *runCmdOptions) decode(cmd *cobra.Command, args []string) error {
@@ -224,25 +217,9 @@ func (o *runCmdOptions) validate() error {
 		}
 	}
 
-	// Deprecation warning
-	if o.PropertyFiles != nil && len(o.PropertyFiles) > 0 {
-		fmt.Println("Warn: --property-file has been deprecated. You should use --property file:/path/to/conf.properties instead.")
-	}
-	if o.ConfigMaps != nil && len(o.ConfigMaps) > 0 {
-		fmt.Println("Warn: --configmap has been deprecated. You should use --config configmap:my-configmap instead.")
-	}
-	if o.Secrets != nil && len(o.Secrets) > 0 {
-		fmt.Println("Warn: --secret has been deprecated. You should use --config secret:my-secret instead.")
-	}
-
-	err := validatePropertyFiles(o.PropertyFiles)
-	if err != nil {
-		return err
-	}
-
 	propertyFiles := filterBuildPropertyFiles(o.Properties)
 	propertyFiles = append(propertyFiles, filterBuildPropertyFiles(o.BuildProperties)...)
-	err = validatePropertyFiles(propertyFiles)
+	err := validatePropertyFiles(propertyFiles)
 	if err != nil {
 		return err
 	}
@@ -424,7 +401,6 @@ func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sou
 	files = append(files, filterFileLocation(o.Configs)...)
 	files = append(files, filterFileLocation(o.Properties)...)
 	files = append(files, filterFileLocation(o.BuildProperties)...)
-	files = append(files, o.PropertyFiles...)
 	files = append(files, filterFileLocation(o.OpenAPIs)...)
 
 	for _, s := range files {
@@ -593,10 +569,6 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 	for _, item := range o.Dependencies {
 		integration.Spec.AddDependency(item)
 	}
-	for _, item := range o.PropertyFiles {
-		// Deprecated: making it compatible with newer mechanism
-		o.Properties = append(o.Properties, "file:"+item)
-	}
 
 	props, err := mergePropertiesWithPrecedence(o.Properties)
 	if err != nil {
@@ -625,12 +597,6 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 		o.Traits = append(o.Traits, buildPropsTraits...)
 	}
 
-	for _, item := range o.ConfigMaps {
-		integration.Spec.AddConfiguration("configmap", item)
-	}
-	for _, item := range o.Secrets {
-		integration.Spec.AddConfiguration("secret", item)
-	}
 	for _, item := range o.Volumes {
 		o.Traits = append(o.Traits, fmt.Sprintf("mount.volumes=%s", item))
 	}
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index dc35ee4..98740d6 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -87,18 +87,6 @@ func TestRunCompressionFlag(t *testing.T) {
 	assert.Equal(t, true, runCmdOptions.Compression)
 }
 
-func TestRunConfigMapFlag(t *testing.T) {
-	runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
-	_, err := test.ExecuteCommand(rootCmd, cmdRun,
-		"--configmap", "configMap1",
-		"--configmap", "configMap2",
-		integrationSource)
-	assert.Nil(t, err)
-	assert.Len(t, runCmdOptions.ConfigMaps, 2)
-	assert.Equal(t, "configMap1", runCmdOptions.ConfigMaps[0])
-	assert.Equal(t, "configMap2", runCmdOptions.ConfigMaps[1])
-}
-
 func TestRunDependencyFlag(t *testing.T) {
 	runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
 	_, err := test.ExecuteCommand(rootCmd, cmdRun,
@@ -236,15 +224,6 @@ func TestRunPropertyFlag(t *testing.T) {
 	assert.Equal(t, "property3", runCmdOptions.Properties[2])
 }
 
-func TestRunPropertyFileFlagMissingFileExtension(t *testing.T) {
-	_, rootCmd, _ := initializeRunCmdOptions(t)
-	_, err := test.ExecuteCommand(rootCmd, cmdRun,
-		"--property-file", "file1",
-		"--property-file", "file2",
-		integrationSource)
-	assert.NotNil(t, err)
-}
-
 const TestPropertyFileContent = `
 a=b
 # There's an issue in the properties lib: https://github.com/magiconair/properties/issues/59
@@ -274,25 +253,6 @@ func TestAddPropertyFile(t *testing.T) {
 	assert.Equal(t, `trait.properties=i = j\nk`, properties[2])
 }
 
-func TestRunPropertyFileFlag(t *testing.T) {
-	var tmpFile *os.File
-	var err error
-	if tmpFile, err = ioutil.TempFile("", "camel-k-*.properties"); err != nil {
-		t.Error(err)
-	}
-
-	assert.Nil(t, tmpFile.Close())
-	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestPropertyFileContent), 0o400))
-
-	runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
-	_, errExecute := test.ExecuteCommand(rootCmd, cmdRun,
-		"--property-file", tmpFile.Name(),
-		integrationSource)
-	assert.Nil(t, errExecute)
-	assert.Len(t, runCmdOptions.PropertyFiles, 1)
-	assert.Equal(t, tmpFile.Name(), runCmdOptions.PropertyFiles[0])
-}
-
 func TestRunProperty(t *testing.T) {
 	properties, err := convertToTraitParameter(`key=value\nnewline`, "trait.properties")
 	assert.Nil(t, err)
@@ -319,18 +279,6 @@ func TestRunSaveFlag(t *testing.T) {
 	assert.Equal(t, true, runCmdOptions.Save)
 }
 
-func TestRunSecretFlag(t *testing.T) {
-	runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
-	_, err := test.ExecuteCommand(rootCmd, cmdRun,
-		"--secret", "secret1",
-		"--secret", "secret2",
-		integrationSource)
-	assert.Nil(t, err)
-	assert.Len(t, runCmdOptions.Secrets, 2)
-	assert.Equal(t, "secret1", runCmdOptions.Secrets[0])
-	assert.Equal(t, "secret2", runCmdOptions.Secrets[1])
-}
-
 func TestRunSourceFlag(t *testing.T) {
 	runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
 	_, err := test.ExecuteCommand(rootCmd, cmdRun, "--source", "source1", integrationSource)