You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by jp...@apache.org on 2022/06/03 08:24:58 UTC

[camel-k] branch release-1.9.x updated (6cd266c9e -> 8e76dc113)

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

jpoth pushed a change to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git


    from 6cd266c9e [TEST] Add autoscaling test
     new 95b1df62c Add verbose flag for the run command
     new d9f6ed8f0 Fix: use platform.Status instead of platform.Spec
     new 6e946b656 Fix #3257: fix uploading checksum files to the image registry on Windows
     new c7bcef95a feat(cli): Add option to specify registry url when uploading artifacts. Move options into file:// URI syntax
     new 00fe5d756 feat(cli): Add option to skip checksum files when uploading artifacts
     new 8e76dc113 feat(cli): Add option to skip uploading POM from JAR  when uploading artifacts to the image registry

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 e2e/registry/registry_maven_wagon_test.go |   6 +-
 pkg/cmd/root.go                           |  19 ++++
 pkg/cmd/run.go                            | 165 +++++++++++++++++++-----------
 pkg/cmd/run_test.go                       |  66 ------------
 pkg/trait/registry.go                     |   8 +-
 5 files changed, 130 insertions(+), 134 deletions(-)


[camel-k] 02/06: Fix: use platform.Status instead of platform.Spec

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit d9f6ed8f04363c0657fa9d8f612adbbf051cf623
Author: John Poth <po...@gmail.com>
AuthorDate: Wed May 18 12:25:21 2022 +0200

    Fix: use platform.Status instead of platform.Spec
    
    (cherry picked from commit 17eb25a86a1d2c9e6d059a6f22da0dca3207a3cc)
---
 pkg/cmd/run.go        | 18 ++++++++++--------
 pkg/trait/registry.go |  8 ++++----
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 147597d16..2607be584 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -597,13 +597,15 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 				if err != nil {
 					return nil, err
 				}
-				if platform.Spec.Build.Registry.CA != "" {
-					o.PrintfVerboseOutf(cmd, "We've noticed the image registry is configured with a custom certificate [%s] \n", platform.Spec.Build.Registry.CA)
+				ca := platform.Status.Build.Registry.CA
+				if ca != "" {
+					o.PrintfVerboseOutf(cmd, "We've noticed the image registry is configured with a custom certificate [%s] \n", ca)
 					o.PrintVerboseOut(cmd, "Please make sure Kamel CLI is configured to use it or the operation will fail.")
 					o.PrintVerboseOut(cmd, "More information can be found here https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file")
 				}
-				if platform.Spec.Build.Registry.Secret != "" {
-					o.PrintfVerboseOutf(cmd, "We've noticed the image registry is configured with a Secret [%s] \n", platform.Spec.Build.Registry.Secret)
+				secret := platform.Status.Build.Registry.Secret
+				if secret != "" {
+					o.PrintfVerboseOutf(cmd, "We've noticed the image registry is configured with a Secret [%s] \n", secret)
 					o.PrintVerboseOut(cmd, "Please configure Docker authentication correctly or the operation will fail (by default it's $HOME/.docker/config.json).")
 					o.PrintVerboseOut(cmd, "More information can be found here https://docs.docker.com/engine/reference/commandline/login/")
 				}
@@ -964,7 +966,7 @@ func (o *runCmdOptions) extractGav(src *zip.File, localPath string, cmd *cobra.C
 
 func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options, cmd *cobra.Command) error {
 	artifactHTTPPath := getArtifactHTTPPath(dependency, platform, ns)
-	options.Target = fmt.Sprintf("%s/%s:%s", platform.Spec.Build.Registry.Address, artifactHTTPPath, dependency.Version)
+	options.Target = fmt.Sprintf("%s/%s:%s", platform.Status.Build.Registry.Address, artifactHTTPPath, dependency.Version)
 	if runtimeos.GOOS == "windows" {
 		// workaround for https://github.com/container-tools/spectrum/issues/8
 		// work with relative paths instead
@@ -1055,7 +1057,7 @@ func uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string,
 	if err = writeChecksumToFile(filepath, hash); err != nil {
 		return err
 	}
-	options.Target = fmt.Sprintf("%s/%s%s:%s", platform.Spec.Build.Registry.Address, artifactHTTPPath, ext, dependency.Version)
+	options.Target = fmt.Sprintf("%s/%s%s:%s", platform.Status.Build.Registry.Address, artifactHTTPPath, ext, dependency.Version)
 	_, err = spectrum.Build(options, fmt.Sprintf("%s:.", filepath))
 	return err
 }
@@ -1072,7 +1074,7 @@ func writeChecksumToFile(filepath string, hash hash.Hash) error {
 }
 
 func (o *runCmdOptions) getSpectrumOptions(platform *v1.IntegrationPlatform, cmd *cobra.Command) spectrum.Options {
-	insecure := platform.Spec.Build.Registry.Insecure
+	insecure := platform.Status.Build.Registry.Insecure
 	var stdout io.Writer
 	if o.Verbose {
 		stdout = cmd.OutOrStdout()
@@ -1097,7 +1099,7 @@ func getArtifactHTTPPath(dependency maven.Dependency, platform *v1.IntegrationPl
 	// Some vendors don't allow '/' or '.' in repository name so let's replace them with '_'
 	artifactHTTPPath = strings.ReplaceAll(artifactHTTPPath, "/", "_")
 	artifactHTTPPath = strings.ReplaceAll(artifactHTTPPath, ".", "_")
-	organization := platform.Spec.Build.Registry.Organization
+	organization := platform.Status.Build.Registry.Organization
 	if organization == "" {
 		organization = ns
 	}
diff --git a/pkg/trait/registry.go b/pkg/trait/registry.go
index b1f47741e..acf6b377a 100644
--- a/pkg/trait/registry.go
+++ b/pkg/trait/registry.go
@@ -64,7 +64,7 @@ func (t *registryTrait) Configure(e *Environment) (bool, error) {
 }
 
 func (t *registryTrait) Apply(e *Environment) error {
-	registryAddress := e.Platform.Spec.Build.Registry.Address
+	registryAddress := e.Platform.Status.Build.Registry.Address
 	if registryAddress == "" && e.Platform.Status.Cluster == v1.IntegrationPlatformClusterOpenShift {
 		registryAddress = "image-registry.openshift-image-registry.svc:5000"
 	}
@@ -72,8 +72,8 @@ func (t *registryTrait) Apply(e *Environment) error {
 		return errors.New("could not figure out Image Registry URL, please set it manually")
 	}
 	build := getBuilderTask(e.BuildTasks)
-	registryCa := e.Platform.Spec.Build.Registry.CA
-	registrySecret := e.Platform.Spec.Build.Registry.Secret
+	registryCa := e.Platform.Status.Build.Registry.CA
+	registrySecret := e.Platform.Status.Build.Registry.Secret
 	if e.Platform.Status.Cluster == v1.IntegrationPlatformClusterOpenShift {
 		if registryCa == "" {
 			ca, err := getOpenShiftImageRegistryCA(e)
@@ -108,7 +108,7 @@ func (t *registryTrait) Apply(e *Environment) error {
 }
 
 func addRegistryAndExtensionToMaven(registryAddress string, build *v1.BuilderTask, platform *v1.IntegrationPlatform) {
-	organization := platform.Spec.Build.Registry.Organization
+	organization := platform.Status.Build.Registry.Organization
 	if organization == "" {
 		organization = platform.Namespace
 	}


[camel-k] 05/06: feat(cli): Add option to skip checksum files when uploading artifacts

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 00fe5d756d8d8fbde7843676d7c8b2eb42eee59e
Author: John Poth <po...@gmail.com>
AuthorDate: Mon May 23 17:26:13 2022 +0200

    feat(cli): Add option to skip checksum files when uploading artifacts
    
    (cherry picked from commit 5ef7236fa51bb93d30d07e597ed5854ef41e8d92)
---
 pkg/cmd/run.go | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 955b4aaeb..249460dce 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -94,7 +94,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 
 	cmd.Flags().String("name", "", "The integration name")
 	cmd.Flags().StringArrayP("connect", "c", nil, "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>]\" for local files (experimental)")
+	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>&skipChecksums=<true>]\" for local files (experimental)")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
@@ -813,6 +813,10 @@ func (o *runCmdOptions) getRegistry(platform *v1.IntegrationPlatform) string {
 	return platform.Status.Build.Registry.Address
 }
 
+func (o *runCmdOptions) skipChecksums() bool {
+	return o.RegistryOptions.Get("skipChecksums") == "true"
+}
+
 func (o *runCmdOptions) getTargetPath() string {
 	return o.RegistryOptions.Get("targetPath")
 }
@@ -993,6 +997,10 @@ func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path
 		return err
 	}
 	o.PrintfVerboseOutf(cmd, "Uploaded: %s to %s \n", path, options.Target)
+	if o.skipChecksums() {
+		o.PrintfVerboseOutf(cmd, "Skipping generating and uploading checksum files for %s \n", path)
+		return nil
+	}
 	return o.uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
 }
 


[camel-k] 01/06: Add verbose flag for the run command

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 95b1df62c7ef2186b27c24c2e2f815eae934bbb9
Author: John Poth <po...@gmail.com>
AuthorDate: Tue Apr 12 12:36:32 2022 +0200

    Add verbose flag for the run command
    
    (cherry picked from commit 24f63caf4e71952b384d5b152c3269f8d00dedd6)
---
 pkg/cmd/root.go | 19 ++++++++++++++++++
 pkg/cmd/run.go  | 60 ++++++++++++++++++++++++++++++---------------------------
 2 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index a01a02a5d..b137bf1bc 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -46,6 +46,7 @@ type RootCmdOptions struct {
 	_client       client.Client      `mapstructure:"-"`
 	KubeConfig    string             `mapstructure:"kube-config"`
 	Namespace     string             `mapstructure:"namespace"`
+	Verbose       bool               `mapstructure:"verbose" yaml:",omitempty"`
 }
 
 // NewKamelCommand --.
@@ -82,6 +83,7 @@ func kamelPreAddCommandInit(options *RootCmdOptions) *cobra.Command {
 
 	cmd.PersistentFlags().StringVar(&options.KubeConfig, "kube-config", os.Getenv("KUBECONFIG"), "Path to the kube config file to use for CLI requests")
 	cmd.PersistentFlags().StringVarP(&options.Namespace, "namespace", "n", "", "Namespace to use for all operations")
+	cmd.PersistentFlags().BoolVarP(&options.Verbose, "verbose", "V", false, "Verbose logging")
 
 	return &cmd
 }
@@ -237,3 +239,20 @@ func (command *RootCmdOptions) GetCamelCmdClient() (*v1.CamelV1Client, error) {
 func (command *RootCmdOptions) NewCmdClient() (client.Client, error) {
 	return client.NewOutOfClusterClient(command.KubeConfig)
 }
+
+func (command *RootCmdOptions) PrintVerboseOut(cmd *cobra.Command, a ...interface{}) {
+	if command.Verbose {
+		fmt.Fprintln(cmd.OutOrStdout(), a...)
+	}
+}
+
+func (command *RootCmdOptions) PrintfVerboseOutf(cmd *cobra.Command, format string, a ...interface{}) {
+	if command.Verbose {
+		fmt.Fprintf(cmd.OutOrStdout(), format, a...)
+	}
+}
+func (command *RootCmdOptions) PrintfVerboseErrf(cmd *cobra.Command, format string, a ...interface{}) {
+	if command.Verbose {
+		fmt.Fprintf(cmd.ErrOrStderr(), format, a...)
+	}
+}
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index ac1cbd202..147597d16 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -598,17 +598,17 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 					return nil, err
 				}
 				if platform.Spec.Build.Registry.CA != "" {
-					fmt.Printf("We've noticed the image registry is configured with a custom certificate [%s] \n", platform.Spec.Build.Registry.CA)
-					fmt.Println("Please make sure Kamel CLI is configured to use it or the operation will fail.")
-					fmt.Println("More information can be found here https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file")
+					o.PrintfVerboseOutf(cmd, "We've noticed the image registry is configured with a custom certificate [%s] \n", platform.Spec.Build.Registry.CA)
+					o.PrintVerboseOut(cmd, "Please make sure Kamel CLI is configured to use it or the operation will fail.")
+					o.PrintVerboseOut(cmd, "More information can be found here https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file")
 				}
 				if platform.Spec.Build.Registry.Secret != "" {
-					fmt.Printf("We've noticed the image registry is configured with a Secret [%s] \n", platform.Spec.Build.Registry.Secret)
-					fmt.Println("Please configure Docker authentication correctly or the operation will fail (by default it's $HOME/.docker/config.json).")
-					fmt.Println("More information can be found here https://docs.docker.com/engine/reference/commandline/login/")
+					o.PrintfVerboseOutf(cmd, "We've noticed the image registry is configured with a Secret [%s] \n", platform.Spec.Build.Registry.Secret)
+					o.PrintVerboseOut(cmd, "Please configure Docker authentication correctly or the operation will fail (by default it's $HOME/.docker/config.json).")
+					o.PrintVerboseOut(cmd, "More information can be found here https://docs.docker.com/engine/reference/commandline/login/")
 				}
 			}
-			if err := uploadFileOrDirectory(platform, item, name, cmd, integration); err != nil {
+			if err := o.uploadFileOrDirectory(platform, item, name, cmd, integration); err != nil {
 				return nil, errors.Wrap(err, fmt.Sprintf("Error trying to upload %s to the Image Registry.", item))
 			}
 		} else {
@@ -787,10 +787,10 @@ func resolvePodTemplate(ctx context.Context, cmd *cobra.Command, templateSrc str
 	return err
 }
 
-func uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integrationName string, cmd *cobra.Command, integration *v1.Integration) error {
+func (o *runCmdOptions) uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integrationName string, cmd *cobra.Command, integration *v1.Integration) error {
 	path := strings.TrimPrefix(item, "file://")
 	localPath, targetPath := getPaths(path, runtimeos.GOOS, filepath.IsAbs(path))
-	options := getSpectrumOptions(platform, cmd)
+	options := o.getSpectrumOptions(platform, cmd)
 	dirName, err := getDirName(localPath)
 	if err != nil {
 		return err
@@ -812,25 +812,25 @@ func uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integr
 		switch {
 		case isPom(path):
 			gav := extractGavFromPom(path, gav)
-			return uploadAsMavenArtifact(gav, path, platform, integration.Namespace, options)
+			return o.uploadAsMavenArtifact(gav, path, platform, integration.Namespace, options, cmd)
 		case isJar(path):
 			// Try to upload pom in JAR and extract it's GAV
-			gav = uploadPomFromJar(gav, path, platform, integration.Namespace, options)
+			gav = o.uploadPomFromJar(gav, path, platform, integration.Namespace, options, cmd)
 			// add JAR to dependency list
 			dependency := fmt.Sprintf("mvn:%s:%s:%s:%s", gav.GroupID, gav.ArtifactID, gav.Type, gav.Version)
-			fmt.Printf("Added %s to the Integration's dependency list \n", dependency)
+			o.PrintfVerboseOutf(cmd, "Added %s to the Integration's dependency list \n", dependency)
 			integration.Spec.AddDependency(dependency)
 			// Upload JAR
-			return uploadAsMavenArtifact(gav, path, platform, integration.Namespace, options)
+			return o.uploadAsMavenArtifact(gav, path, platform, integration.Namespace, options, cmd)
 		default:
 			mountPath, err := getMountPath(targetPath, dirName, path)
 			if err != nil {
 				return err
 			}
 			dependency := fmt.Sprintf("registry-mvn:%s:%s:%s:%s@%s", gav.GroupID, gav.ArtifactID, gav.Type, gav.Version, mountPath)
-			fmt.Printf("Added %s to the Integration's dependency list \n", dependency)
+			o.PrintfVerboseOutf(cmd, "Added %s to the Integration's dependency list \n", dependency)
 			integration.Spec.AddDependency(dependency)
-			return uploadAsMavenArtifact(gav, path, platform, integration.Namespace, options)
+			return o.uploadAsMavenArtifact(gav, path, platform, integration.Namespace, options, cmd)
 		}
 	})
 }
@@ -867,7 +867,7 @@ func getMountPath(targetPath string, dirName string, path string) (string, error
 }
 
 // nolint:errcheck
-func uploadPomFromJar(gav maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options) maven.Dependency {
+func (o *runCmdOptions) uploadPomFromJar(gav maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options, cmd *cobra.Command) maven.Dependency {
 	util.WithTempDir("camel-k", func(tmpDir string) error {
 		pomPath := filepath.Join(tmpDir, "pom.xml")
 		jar, err := zip.OpenReader(path)
@@ -886,7 +886,7 @@ func uploadPomFromJar(gav maven.Dependency, path string, platform *v1.Integratio
 				pomExtracted = extractFromZip(pomPath, f)
 			} else if regPomProperties.MatchString(f.Name) {
 				foundProperties = true
-				if dep, ok := extractGav(f, path); ok {
+				if dep, ok := o.extractGav(f, path, cmd); ok {
 					gav = dep
 				}
 			}
@@ -897,7 +897,7 @@ func uploadPomFromJar(gav maven.Dependency, path string, platform *v1.Integratio
 		if pomExtracted {
 			gav.Type = "pom"
 			// Swallow error as this is not a mandatory step
-			uploadAsMavenArtifact(gav, pomPath, platform, ns, options)
+			o.uploadAsMavenArtifact(gav, pomPath, platform, ns, options, cmd)
 		}
 		return nil
 	})
@@ -922,7 +922,7 @@ func extractFromZip(dst string, src *zip.File) bool {
 	return err == nil
 }
 
-func extractGav(src *zip.File, localPath string) (maven.Dependency, bool) {
+func (o *runCmdOptions) extractGav(src *zip.File, localPath string, cmd *cobra.Command) (maven.Dependency, bool) {
 	rc, err := src.Open()
 	if err != nil {
 		return maven.Dependency{}, false
@@ -930,28 +930,28 @@ func extractGav(src *zip.File, localPath string) (maven.Dependency, bool) {
 	defer rc.Close()
 	data, err := ioutil.ReadAll(rc)
 	if err != nil {
-		fmt.Printf("Error while reading pom.properties from [%s], switching to default: \n %s err \n", localPath, err)
+		o.PrintfVerboseErrf(cmd, "Error while reading pom.properties from [%s], switching to default: \n %s err \n", localPath, err)
 		return maven.Dependency{}, false
 	}
 	prop, err := properties.Load(data, properties.UTF8)
 	if err != nil {
-		fmt.Printf("Error while reading pom.properties from [%s], switching to default: \n %s err \n", localPath, err)
+		o.PrintfVerboseErrf(cmd, "Error while reading pom.properties from [%s], switching to default: \n %s err \n", localPath, err)
 		return maven.Dependency{}, false
 	}
 
 	groupID, ok := prop.Get("groupId")
 	if !ok {
-		fmt.Printf("Couldn't find groupId property while reading pom.properties from [%s], switching to default \n", localPath)
+		o.PrintfVerboseErrf(cmd, "Couldn't find groupId property while reading pom.properties from [%s], switching to default \n", localPath)
 		return maven.Dependency{}, false
 	}
 	artifactID, ok := prop.Get("artifactId")
 	if !ok {
-		fmt.Printf("Couldn't find artifactId property while reading pom.properties from [%s], switching to default \n", localPath)
+		o.PrintfVerboseErrf(cmd, "Couldn't find artifactId property while reading pom.properties from [%s], switching to default \n", localPath)
 		return maven.Dependency{}, false
 	}
 	version, ok := prop.Get("version")
 	if !ok {
-		fmt.Printf("Couldn't find version property while reading pom.properties from [%s], switching to default \n", localPath)
+		o.PrintfVerboseErrf(cmd, "Couldn't find version property while reading pom.properties from [%s], switching to default \n", localPath)
 		return maven.Dependency{}, false
 	}
 	return maven.Dependency{
@@ -962,7 +962,7 @@ func extractGav(src *zip.File, localPath string) (maven.Dependency, bool) {
 	}, true
 }
 
-func uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options) error {
+func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options, cmd *cobra.Command) error {
 	artifactHTTPPath := getArtifactHTTPPath(dependency, platform, ns)
 	options.Target = fmt.Sprintf("%s/%s:%s", platform.Spec.Build.Registry.Address, artifactHTTPPath, dependency.Version)
 	if runtimeos.GOOS == "windows" {
@@ -978,7 +978,7 @@ func uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v
 	if err != nil {
 		return err
 	}
-	fmt.Printf("Uploaded: %s to %s \n", path, options.Target)
+	o.PrintfVerboseOutf(cmd, "Uploaded: %s to %s \n", path, options.Target)
 	return uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
 }
 
@@ -1071,15 +1071,19 @@ func writeChecksumToFile(filepath string, hash hash.Hash) error {
 	return err
 }
 
-func getSpectrumOptions(platform *v1.IntegrationPlatform, cmd *cobra.Command) spectrum.Options {
+func (o *runCmdOptions) getSpectrumOptions(platform *v1.IntegrationPlatform, cmd *cobra.Command) spectrum.Options {
 	insecure := platform.Spec.Build.Registry.Insecure
+	var stdout io.Writer
+	if o.Verbose {
+		stdout = cmd.OutOrStdout()
+	}
 	options := spectrum.Options{
 		PullInsecure:  true,
 		PushInsecure:  insecure,
 		PullConfigDir: "",
 		PushConfigDir: "",
 		Base:          "",
-		Stdout:        cmd.OutOrStdout(),
+		Stdout:        stdout,
 		Stderr:        cmd.OutOrStderr(),
 		Recursive:     false,
 	}


[camel-k] 04/06: feat(cli): Add option to specify registry url when uploading artifacts. Move options into file:// URI syntax

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit c7bcef95a7e3f3dc717b6aa4b5b6a7f3ae50935d
Author: John Poth <po...@gmail.com>
AuthorDate: Thu May 19 18:18:52 2022 +0200

    feat(cli): Add option to specify registry url when uploading artifacts. Move options into file:// URI syntax
    
    (cherry picked from commit d545b70be9b7483716bf10c16fad3e05e9c09df7)
---
 e2e/registry/registry_maven_wagon_test.go |  4 +-
 pkg/cmd/run.go                            | 66 ++++++++++++++++++-------------
 pkg/cmd/run_test.go                       | 66 -------------------------------
 3 files changed, 41 insertions(+), 95 deletions(-)

diff --git a/e2e/registry/registry_maven_wagon_test.go b/e2e/registry/registry_maven_wagon_test.go
index 76e2bbc99..7a978d46d 100644
--- a/e2e/registry/registry_maven_wagon_test.go
+++ b/e2e/registry/registry_maven_wagon_test.go
@@ -89,7 +89,7 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {
 			Expect(Kamel("run", "files/LaughingRoute.java",
 				"--name", name,
 				"-p", fmt.Sprintf("location=%s", customPath),
-				"-d", fmt.Sprintf("file://files/laugh.txt:%slaugh.txt", customPath),
+				"-d", fmt.Sprintf("file://files/laugh.txt?targetPath=%slaugh.txt", customPath),
 				"-n", ns,
 			).Execute()).To(Succeed())
 
@@ -104,7 +104,7 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {
 			Expect(Kamel("run", "files/LaughingRoute.java",
 				"--name", name,
 				"-p", "location=files/",
-				"-d", fmt.Sprintf("file://files/laughs/:files/"),
+				"-d", fmt.Sprintf("file://files/laughs/?targetPath=files/"),
 				"-n", ns,
 			).Execute()).To(Succeed())
 
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 4f2235cfb..955b4aaeb 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -34,6 +34,7 @@ import (
 	"io"
 	"io/fs"
 	"io/ioutil"
+	"net/url"
 	"os"
 	"os/signal"
 	"path/filepath"
@@ -93,7 +94,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 
 	cmd.Flags().String("name", "", "The integration name")
 	cmd.Flags().StringArrayP("connect", "c", nil, "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[:targetPath]\" for local files (experimental)")
+	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>]\" for local files (experimental)")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
@@ -153,6 +154,7 @@ type runCmdOptions struct {
 	Labels          []string `mapstructure:"labels" yaml:",omitempty"`
 	Annotations     []string `mapstructure:"annotations" yaml:",omitempty"`
 	Sources         []string `mapstructure:"sources" yaml:",omitempty"`
+	RegistryOptions url.Values
 }
 
 func (o *runCmdOptions) decode(cmd *cobra.Command, args []string) error {
@@ -789,9 +791,36 @@ func resolvePodTemplate(ctx context.Context, cmd *cobra.Command, templateSrc str
 	return err
 }
 
+func parseFileURI(uri string) *url.URL {
+	file := new(url.URL)
+	file.Scheme = "file"
+	path := strings.TrimPrefix(uri, "file://")
+	i := strings.IndexByte(path, '?')
+	if i > 0 {
+		file.Path = path[:i]
+		file.RawQuery = path[i+1:]
+	} else {
+		file.Path = path
+	}
+	return file
+}
+
+func (o *runCmdOptions) getRegistry(platform *v1.IntegrationPlatform) string {
+	registry := o.RegistryOptions.Get("registry")
+	if registry != "" {
+		return registry
+	}
+	return platform.Status.Build.Registry.Address
+}
+
+func (o *runCmdOptions) getTargetPath() string {
+	return o.RegistryOptions.Get("targetPath")
+}
+
 func (o *runCmdOptions) uploadFileOrDirectory(platform *v1.IntegrationPlatform, item string, integrationName string, cmd *cobra.Command, integration *v1.Integration) error {
-	path := strings.TrimPrefix(item, "file://")
-	localPath, targetPath := getPaths(path, runtimeos.GOOS, filepath.IsAbs(path))
+	uri := parseFileURI(item)
+	o.RegistryOptions = uri.Query()
+	localPath, targetPath := uri.Path, o.getTargetPath()
 	options := o.getSpectrumOptions(platform, cmd)
 	dirName, err := getDirName(localPath)
 	if err != nil {
@@ -837,23 +866,6 @@ func (o *runCmdOptions) uploadFileOrDirectory(platform *v1.IntegrationPlatform,
 	})
 }
 
-func getPaths(path string, os string, isAbs bool) (localPath string, targetPath string) {
-	localPath = path
-	targetPath = ""
-	parts := strings.Split(path, ":")
-	if len(parts) > 1 {
-		if os != "windows" || !isAbs {
-			localPath = parts[0]
-			targetPath = parts[1]
-		} else if isAbs && len(parts) == 3 {
-			// special case on Windows for absolute paths e.g C:\foo\bar\test.csv:remote/path
-			localPath = fmt.Sprintf("%s:%s", parts[0], parts[1])
-			targetPath = parts[2]
-		}
-	}
-	return localPath, targetPath
-}
-
 func getMountPath(targetPath string, dirName string, path string) (string, error) {
 	// if the target path is a file then use that as the exact mount path
 	if filepath.Ext(targetPath) != "" {
@@ -966,7 +978,7 @@ func (o *runCmdOptions) extractGav(src *zip.File, localPath string, cmd *cobra.C
 
 func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path string, platform *v1.IntegrationPlatform, ns string, options spectrum.Options, cmd *cobra.Command) error {
 	artifactHTTPPath := getArtifactHTTPPath(dependency, platform, ns)
-	options.Target = fmt.Sprintf("%s/%s:%s", platform.Status.Build.Registry.Address, artifactHTTPPath, dependency.Version)
+	options.Target = fmt.Sprintf("%s/%s:%s", o.getRegistry(platform), artifactHTTPPath, dependency.Version)
 	if runtimeos.GOOS == "windows" {
 		// workaround for https://github.com/container-tools/spectrum/issues/8
 		// work with relative paths instead
@@ -981,7 +993,7 @@ func (o *runCmdOptions) uploadAsMavenArtifact(dependency maven.Dependency, path
 		return err
 	}
 	o.PrintfVerboseOutf(cmd, "Uploaded: %s to %s \n", path, options.Target)
-	return uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
+	return o.uploadChecksumFiles(path, options, platform, artifactHTTPPath, dependency)
 }
 
 // Deprecated: workaround for https://github.com/container-tools/spectrum/issues/8
@@ -1029,18 +1041,18 @@ func extractGavFromPom(path string, gav maven.Dependency) maven.Dependency {
 	return gav
 }
 
-func uploadChecksumFiles(path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
+func (o *runCmdOptions) uploadChecksumFiles(path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
 	return util.WithTempDir("camel-k", func(tmpDir string) error {
 		// #nosec G401
-		if err := uploadChecksumFile(md5.New(), tmpDir, "_md5", path, options, platform, artifactHTTPPath, dependency); err != nil {
+		if err := o.uploadChecksumFile(md5.New(), tmpDir, "_md5", path, options, platform, artifactHTTPPath, dependency); err != nil {
 			return err
 		}
 		// #nosec G401
-		return uploadChecksumFile(sha1.New(), tmpDir, "_sha1", path, options, platform, artifactHTTPPath, dependency)
+		return o.uploadChecksumFile(sha1.New(), tmpDir, "_sha1", path, options, platform, artifactHTTPPath, dependency)
 	})
 }
 
-func uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
+func (o *runCmdOptions) uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string, options spectrum.Options, platform *v1.IntegrationPlatform, artifactHTTPPath string, dependency maven.Dependency) error {
 	file, err := os.Open(path)
 	if err != nil {
 		return err
@@ -1066,7 +1078,7 @@ func uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string,
 	if err = writeChecksumToFile(filepath, hash); err != nil {
 		return err
 	}
-	options.Target = fmt.Sprintf("%s/%s%s:%s", platform.Status.Build.Registry.Address, artifactHTTPPath, ext, dependency.Version)
+	options.Target = fmt.Sprintf("%s/%s%s:%s", o.getRegistry(platform), artifactHTTPPath, ext, dependency.Version)
 	_, err = spectrum.Build(options, fmt.Sprintf("%s:.", filepath))
 	return err
 }
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index f2fe2e6b4..b865fb7ce 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -680,69 +680,3 @@ func TestMissingTrait(t *testing.T) {
 	assert.Equal(t, "Error: bogus.fail=i-must-fail is not a valid trait property\n", output)
 	assert.NotNil(t, err)
 }
-
-func TestGetsPaths(t *testing.T) {
-	tests := []struct {
-		path       string
-		localPath  string
-		remotePath string
-		os         string
-		isAbs      bool
-	}{
-		{
-			path:       "C:\\USER\\HOME\\:remote/path",
-			localPath:  "C:\\USER\\HOME\\",
-			remotePath: "remote/path",
-			os:         "windows",
-			isAbs:      true,
-		},
-		{
-			path:       "src\\main\\resources:remote/path",
-			localPath:  "src\\main\\resources",
-			remotePath: "remote/path",
-			os:         "windows",
-		},
-		{
-			path:       "C:\\USER\\HOME\\",
-			localPath:  "C:\\USER\\HOME\\",
-			remotePath: "",
-			os:         "windows",
-			isAbs:      true,
-		},
-		{
-			path:       "src\\main\\resources",
-			localPath:  "src\\main\\resources",
-			remotePath: "",
-			os:         "windows",
-		},
-		{
-			path:       "/home/user/name/dir:/remote/path",
-			localPath:  "/home/user/name/dir",
-			remotePath: "/remote/path",
-			os:         "linux",
-			isAbs:      true,
-		}, {
-			path:       "/home/user/name/dir",
-			localPath:  "/home/user/name/dir",
-			remotePath: "",
-			os:         "linux",
-			isAbs:      true,
-		}, {
-			path:       "src/main/resources:remote/path",
-			localPath:  "src/main/resources",
-			remotePath: "remote/path",
-			os:         "linux",
-		}, {
-			path:       "src/main/resources",
-			localPath:  "src/main/resources",
-			remotePath: "",
-			os:         "linux",
-		},
-	}
-	for _, test := range tests {
-		localPath, targetPath := getPaths(test.path, test.os, test.isAbs)
-		assert.Equal(t, test.localPath, localPath)
-		assert.Equal(t, test.remotePath, targetPath)
-
-	}
-}


[camel-k] 03/06: Fix #3257: fix uploading checksum files to the image registry on Windows

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 6e946b656642ad56066ac7b01bb09430ae7c25d1
Author: John Poth <po...@gmail.com>
AuthorDate: Wed May 18 11:50:47 2022 +0200

    Fix #3257: fix uploading checksum files to the image registry on Windows
    
    (cherry picked from commit 0ec183bbbff0347ff4bda18f7286f67e57fbc879)
---
 pkg/cmd/run.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 2607be584..4f2235cfb 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -1053,6 +1053,15 @@ func uploadChecksumFile(hash hash.Hash, tmpDir string, ext string, path string,
 
 	filename := "maven_" + filepath.Base(path) + ext
 	filepath := filepath.Join(tmpDir, filename)
+	if runtimeos.GOOS == "windows" {
+		// workaround for https://github.com/container-tools/spectrum/issues/8
+		// work with relative paths instead
+		rel, err := getRelativeToWorkingDirectory(path)
+		if err != nil {
+			return err
+		}
+		filepath = rel
+	}
 
 	if err = writeChecksumToFile(filepath, hash); err != nil {
 		return err


[camel-k] 06/06: feat(cli): Add option to skip uploading POM from JAR when uploading artifacts to the image registry

Posted by jp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch release-1.9.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 8e76dc113640cbb9911b274120cbe459dacf45fb
Author: John Poth <po...@gmail.com>
AuthorDate: Tue May 24 09:31:40 2022 +0200

    feat(cli): Add option to skip uploading POM from JAR  when uploading artifacts to the image registry
    
    (cherry picked from commit f5e39aaa4dcf97ce9ef9fd4e0d8517ca0a35f61f)
---
 e2e/registry/registry_maven_wagon_test.go |  2 +-
 pkg/cmd/run.go                            | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/e2e/registry/registry_maven_wagon_test.go b/e2e/registry/registry_maven_wagon_test.go
index 7a978d46d..4abebc239 100644
--- a/e2e/registry/registry_maven_wagon_test.go
+++ b/e2e/registry/registry_maven_wagon_test.go
@@ -50,7 +50,7 @@ func TestImageRegistryIsAMavenRepository(t *testing.T) {
 		t.Run("image registry is a maven repository", func(t *testing.T) {
 			// Create integration that should decrypt an encrypted message to "foobar" and log it
 			name := "foobar-decryption"
-			jar, err := filepath.Abs("files/sample-decryption-1.0.jar")
+			jar, err := filepath.Abs("files/sample-decryption-1.0.jar?skipPOM=true")
 			assert.Nil(t, err)
 			pom, err := filepath.Abs("files/sample-decryption-1.0.pom")
 			assert.Nil(t, err)
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 249460dce..2e55e1a99 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -94,7 +94,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 
 	cmd.Flags().String("name", "", "The integration name")
 	cmd.Flags().StringArrayP("connect", "c", nil, "A Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>&skipChecksums=<true>]\" for local files (experimental)")
+	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, \"-d mvn:org.my:app:1.0\" for a Maven dependency or \"file://localPath[?targetPath=<path>&registry=<registry URL>&skipChecksums=<true>&skipPOM=<true>]\" for local files (experimental)")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax: [my-key=my-value|file:/path/to/my-conf.properties])")
@@ -817,6 +817,10 @@ func (o *runCmdOptions) skipChecksums() bool {
 	return o.RegistryOptions.Get("skipChecksums") == "true"
 }
 
+func (o *runCmdOptions) skipPom() bool {
+	return o.RegistryOptions.Get("skipPOM") == "true"
+}
+
 func (o *runCmdOptions) getTargetPath() string {
 	return o.RegistryOptions.Get("targetPath")
 }
@@ -913,9 +917,13 @@ func (o *runCmdOptions) uploadPomFromJar(gav maven.Dependency, path string, plat
 			}
 		}
 		if pomExtracted {
-			gav.Type = "pom"
-			// Swallow error as this is not a mandatory step
-			o.uploadAsMavenArtifact(gav, pomPath, platform, ns, options, cmd)
+			if o.skipPom() {
+				o.PrintfVerboseOutf(cmd, "Skipping uploading extracted POM from %s \n", path)
+			} else {
+				gav.Type = "pom"
+				// Swallow error as this is not a mandatory step
+				o.uploadAsMavenArtifact(gav, pomPath, platform, ns, options, cmd)
+			}
 		}
 		return nil
 	})