Skip to content

Commit

Permalink
Fix apache#2834: Add E2E for local files mounted in custom path
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpoth committed Jan 6, 2022
1 parent 384cee1 commit 25dc7f8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
4 changes: 3 additions & 1 deletion e2e/registry/files/LaughingRoute.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// camel-k: property=location=files/

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -21,7 +23,7 @@ public class LaughingRoute extends RouteBuilder {

@Override
public void configure() throws Exception {
from("file:files/")
from("file:{{location}}")
.convertBodyTo(String.class)
.log("${body}");
}
Expand Down
23 changes: 23 additions & 0 deletions e2e/registry/registry_maven_wagon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,26 @@ func TestLocalFilesAreMountedInContainerInDefaultPath(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}

func TestLocalFilesAreMountedInContainerInCustomPath(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
name := "laughing-route"
customMount := "this/is/a/custom/path/"

// Create integration that reads a file mounted into the container filesystem with a custom path
Expect(Kamel("run", "files/LaunghingRoute.java",
"--name", name,
"-p", fmt.Sprintf("location=%s", customMount),
"-d", fmt.Sprintf("file://files/laugh.txt:%slaugh.txt", customMount),
"-n", ns,
).Execute()).To(Succeed())

Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("haha"))

// Clean up
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}
10 changes: 6 additions & 4 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,15 @@ func uploadDependency(platform *v1.IntegrationPlatform, item string, integration
defer newStdW.Close()

path := item[7:]
i := strings.Index(path, ":")
targetPath := path
localPath := path
i := strings.Index(path, ":")
if i > 0 {
targetPath = path[i:]
targetPath = path[i+1:]
localPath = path[:i]
}
// spectrum expects absolute paths but let's allow users to specify relative paths
abs, err := filepath.Abs(path)
abs, err := filepath.Abs(localPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -955,7 +957,7 @@ func uploadDependency(platform *v1.IntegrationPlatform, item string, integration
dependency := fmt.Sprintf("mvn:%s:%s:%s:%s", groupId, artifactId, ext[1:], version)
fmt.Printf("Added %s to the Integration's dependency list \n", dependency)
integration.Spec.AddDependency(dependency)
// Everything else will be mounted on the container filesystem
// Everything else will be mounted on the container filesystem
} else if !strings.HasSuffix(item, ".pom") {
dependency := fmt.Sprintf("docker-mvn:%s:%s:%s:%s@%s", groupId, artifactId, ext[1:], version, targetPath)
fmt.Printf("Added %s to the Integration's dependency list \n", dependency)
Expand Down
9 changes: 5 additions & 4 deletions pkg/util/camel/camel_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func addDependencies(project *maven.Project, dependencies []string, catalog *Run
}
plugin := getOrCreateBuildPlugin(project, "com.googlecode.maven-download-plugin", "download-maven-plugin", "1.6.7")
exec := maven.Execution{
ID: fmt.Sprint(len(plugin.Executions)),
Phase: "package",
Goals: []string{
"artifact",
Expand Down Expand Up @@ -161,10 +162,10 @@ func addDependencies(project *maven.Project, dependencies []string, catalog *Run
return nil
}

func getOrCreateBuildPlugin(project *maven.Project, groupID string, artifactID string, version string) maven.Plugin {
for _, plugin := range project.Build.Plugins {
func getOrCreateBuildPlugin(project *maven.Project, groupID string, artifactID string, version string) *maven.Plugin {
for i, plugin := range project.Build.Plugins {
if plugin.GroupID == groupID && plugin.ArtifactID == artifactID && plugin.Version == version {
return plugin
return &project.Build.Plugins[i]
}
}
plugin := maven.Plugin{
Expand All @@ -174,7 +175,7 @@ func getOrCreateBuildPlugin(project *maven.Project, groupID string, artifactID s
Executions: []maven.Execution{},
}
project.Build.Plugins = append(project.Build.Plugins, plugin)
return plugin
return &project.Build.Plugins[len(project.Build.Plugins)-1]
}

func addDependenciesFromCatalog(project *maven.Project, catalog *RuntimeCatalog) {
Expand Down

0 comments on commit 25dc7f8

Please sign in to comment.