Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(e2e): tests failure in Plain Quarkus runtime #6004

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions e2e/common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ func TestRunConfigProperties(t *testing.T) {
g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-value"))
})

t.Run("Property from ConfigMap as property file", func(t *testing.T) {
var cmData = make(map[string]string)
cmData["my.properties"] = "my.message=my-configmap-property-entry"
err := CreatePlainTextConfigmap(t, ctx, ns, "my-cm-test-properties", cmData)
g.Expect(err).To(BeNil())

g.Expect(KamelRun(t, ctx, ns, "./files/property-route.yaml", "-p", "configmap:my-cm-test-properties").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-configmap-property-entry"))
})

t.Run("Property from Secret", func(t *testing.T) {
var secData = make(map[string]string)
secData["my.message"] = "my-secret-property-value"
Expand All @@ -95,18 +83,6 @@ func TestRunConfigProperties(t *testing.T) {
g.Eventually(IntegrationLogs(t, ctx, ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-value"))
})

t.Run("Property from Secret as property file", func(t *testing.T) {
var secData = make(map[string]string)
secData["my.properties"] = "my.message=my-secret-property-entry"
err := CreatePlainTextSecret(t, ctx, ns, "my-sec-test-properties", secData)
g.Expect(err).To(BeNil())

g.Expect(KamelRun(t, ctx, ns, "./files/property-route.yaml", "--name", "property-route-secret", "-p", "secret:my-sec-test-properties").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "property-route-secret"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "property-route-secret", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationLogs(t, ctx, ns, "property-route-secret"), TestTimeoutShort).Should(ContainSubstring("my-secret-property-entry"))
})

t.Run("Property from Secret inlined", func(t *testing.T) {
var secData = make(map[string]string)
secData["my-message"] = "my-secret-external-value"
Expand Down Expand Up @@ -172,19 +148,6 @@ func TestRunConfigConfigmaps(t *testing.T) {
g.Eventually(IntegrationLogs(t, ctx, ns, "resource-configmap-key-location-route"), TestTimeoutShort).ShouldNot(ContainSubstring(cmDataMulti["my-configmap-key"]))
g.Eventually(IntegrationLogs(t, ctx, ns, "resource-configmap-key-location-route"), TestTimeoutShort).Should(ContainSubstring(cmDataMulti["my-configmap-key-2"]))
})

t.Run("Config configmap as property file", func(t *testing.T) {
// Store a configmap as property file
var cmDataProps = make(map[string]string)
cmDataProps["my.properties"] = "my.key.1=hello\nmy.key.2=world"
err = CreatePlainTextConfigmap(t, ctx, ns, "my-cm-properties", cmDataProps)
g.Expect(err).To(BeNil())

g.Expect(KamelRun(t, ctx, ns, "./files/config-configmap-properties-route.yaml", "--config", "configmap:my-cm-properties").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "config-configmap-properties-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, "config-configmap-properties-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationLogs(t, ctx, ns, "config-configmap-properties-route"), TestTimeoutShort).Should(ContainSubstring("hello world"))
})
})
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/common/traits/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestBuilderTrait(t *testing.T) {

// Check logs
g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom1"})).Should(ContainSubstring(`generated-bytecode.jar`))
g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom2"})).Should(ContainSubstring(`<artifactId>camel-k-runtime-bom</artifactId>`))
g.Eventually(Logs(t, ctx, integrationKitNamespace, builderKitName, corev1.PodLogOptions{Container: "custom2"})).Should(ContainSubstring(`<artifactId>camel-k-integration</artifactId>`))
})

t.Run("Run custom pipeline task error", func(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/integrationplatform/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ func (action *monitorAction) addPlainQuarkusCatalog(ctx context.Context, catalog
},
},
}
runtimesProps := clonedCatalog.Spec.Runtime.Capabilities["master"].RuntimeProperties
clonedCatalog.Spec.Runtime.Capabilities["master"] = v1.Capability{
Dependencies: []v1.MavenArtifact{},
Dependencies: []v1.MavenArtifact{},
RuntimeProperties: runtimesProps,
}
clonedCatalog.Spec.Runtime.Capabilities["resume-kafka"] = v1.Capability{
Dependencies: []v1.MavenArtifact{},
Expand All @@ -206,7 +208,7 @@ func (action *monitorAction) addPlainQuarkusCatalog(ctx context.Context, catalog
},
{
GroupID: "org.apache.camel.quarkus",
ArtifactID: "camel-quarkus-jaxb",
ArtifactID: "camel-quarkus-management",
},
{
GroupID: "org.jolokia",
Expand Down
8 changes: 7 additions & 1 deletion pkg/trait/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,13 @@ func (t *mountTrait) addSourcesProperties(e *Environment) {
if e.ApplicationProperties == nil {
e.ApplicationProperties = make(map[string]string)
}
if e.CamelCatalog.GetRuntimeProvider() == v1.RuntimeProviderPlainQuarkus {
isQuarkusNative := false
if qt := e.Catalog.GetTrait(quarkusTraitID); qt != nil {
if quarkus, ok := qt.(*quarkusTrait); ok && quarkus.isNativeIntegration(e) {
isQuarkusNative = true
}
}
if e.CamelCatalog.GetRuntimeProvider() == v1.RuntimeProviderPlainQuarkus && !isQuarkusNative {
e.ApplicationProperties["camel.main.source-location-enabled"] = boolean.TrueString
e.ApplicationProperties["camel.main.routes-include-pattern"] = fmt.Sprintf("file:%s/**", camel.SourcesMountPath)
} else {
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/source/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
camelTypeRegexp = regexp.MustCompile(`.*(org.apache.camel.*Component|DataFormat|Language)`)
jsonLibraryRegexp = regexp.MustCompile(`.*JsonLibrary\.Jackson.*`)
jsonLanguageRegexp = regexp.MustCompile(`.*\.json\(\).*`)
beanRegexp = regexp.MustCompile(`.*\.bean\(.*\).*`)
circuitBreakerRegexp = regexp.MustCompile(`.*\.circuitBreaker\(\).*`)
restConfigurationRegexp = regexp.MustCompile(`.*restConfiguration\(\).*`)
restRegexp = regexp.MustCompile(`.*rest\s*\([^)]*\).*`)
Expand All @@ -70,6 +71,13 @@ var (
}

sourceDependencies = map[*regexp.Regexp]catalog2deps{
beanRegexp: func(catalog *camel.RuntimeCatalog) []string {
res := make([]string, 0)
if bean := catalog.GetArtifactByScheme("bean"); bean != nil {
res = append(res, bean.GetDependencyID())
}
return res
},
jsonLibraryRegexp: func(catalog *camel.RuntimeCatalog) []string {
res := make([]string, 0)
if jsonDF := catalog.GetArtifactByDataFormat(defaultJSONDataFormat); jsonDF != nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/source/inspector_java_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,19 @@ public void configure() throws Exception {
require.NoError(t, err)
assert.Contains(t, meta.Dependencies.List(), "camel:rest-openapi")
}

func TestJavaBeanDependencies(t *testing.T) {
inspector := newTestJavaSourceInspector(t)

sourceSpec := &v1.SourceSpec{
DataSpec: v1.DataSpec{
Name: "test.java",
Content: "from(\"timer:foo\").bean(\"myBean\").to(\"log:bar\")",
},
}
assertExtract(t, inspector, sourceSpec.Content, func(meta *Metadata) {
assert.Contains(t, meta.Dependencies.List(), "camel:timer")
assert.Contains(t, meta.Dependencies.List(), "camel:bean")
assert.Contains(t, meta.Dependencies.List(), "camel:log")
})
}
10 changes: 10 additions & 0 deletions pkg/util/source/inspector_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,13 @@ func TestXMLRestOpenapiFirst(t *testing.T) {
require.NoError(t, err)
assert.Contains(t, meta.Dependencies.List(), "camel:rest-openapi")
}

func TestXMLBeanDependencies(t *testing.T) {
inspector := newTestXMLInspector(t)

assertExtract(t, inspector, "<from uri=\"timer:foo\"/><bean>something</bean><to uri=\"log:bar\"></to>", func(meta *Metadata) {
assert.Contains(t, meta.Dependencies.List(), "camel:timer")
assert.Contains(t, meta.Dependencies.List(), "camel:bean")
assert.Contains(t, meta.Dependencies.List(), "camel:log")
})
}
4 changes: 4 additions & 0 deletions pkg/util/source/inspector_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (i YAMLInspector) parseDefinition(def map[string]interface{}, meta *Metadat
//nolint:nestif
func (i YAMLInspector) parseStep(key string, content interface{}, meta *Metadata) error {
switch key {
case "bean":
if bean := i.catalog.GetArtifactByScheme("bean"); bean != nil {
meta.AddDependency(bean.GetDependencyID())
}
case "rest":
meta.ExposesHTTPServices = true
meta.RequiredCapabilities.Add(v1.CapabilityRest)
Expand Down
19 changes: 19 additions & 0 deletions pkg/util/source/inspector_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,22 @@ func TestYAMLRESTContractFirst(t *testing.T) {
})
})
}

const yamlBean = `
- from:
uri: "timer:foo"
steps:
- bean:
type: "#xyz"
- to: "log:bar"
`

func TestYamlBeanDependencies(t *testing.T) {
inspector := newTestYAMLInspector(t)

assertExtract(t, inspector, yamlBean, func(meta *Metadata) {
assert.Contains(t, meta.Dependencies.List(), "camel:timer")
assert.Contains(t, meta.Dependencies.List(), "camel:bean")
assert.Contains(t, meta.Dependencies.List(), "camel:log")
})
}
47 changes: 0 additions & 47 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,53 +43,6 @@ import (
yaml2 "gopkg.in/yaml.v2"
)

// Directories and file names:

// DefaultDependenciesDirectoryName --.
const DefaultDependenciesDirectoryName = "dependencies"

// DefaultPropertiesDirectoryName --.
const DefaultPropertiesDirectoryName = "properties"

// DefaultRoutesDirectoryName --.
const DefaultRoutesDirectoryName = "routes"

// DefaultWorkingDirectoryName --.
const DefaultWorkingDirectoryName = "workspace"

// CustomQuarkusDirectoryName --.
const CustomQuarkusDirectoryName = "quarkus"

// CustomAppDirectoryName --.
const CustomAppDirectoryName = "app"

// CustomLibDirectoryName --.
const CustomLibDirectoryName = "lib/main"

// ContainerDependenciesDirectory --.
var ContainerDependenciesDirectory = "/deployments/dependencies"

// ContainerPropertiesDirectory --.
var ContainerPropertiesDirectory = "/etc/camel/conf.d"

// ContainerRoutesDirectory --.
var ContainerRoutesDirectory = "/etc/camel/sources"

// ContainerResourcesDirectory --.
var ContainerResourcesDirectory = "/etc/camel/resources.d"

// ContainerQuarkusDirectoryName --.
const ContainerQuarkusDirectoryName = "/quarkus"

// ContainerAppDirectoryName --.
const ContainerAppDirectoryName = "/app"

// ContainerLibDirectoryName --.
const ContainerLibDirectoryName = "/lib/main"

// QuarkusDependenciesBaseDirectory --.
var QuarkusDependenciesBaseDirectory = "/quarkus-app"

// ListOfLazyEvaluatedEnvVars -- List of unevaluated environment variables.
// These are sensitive values or values that may have different values depending on
// where the integration is run (locally vs. the cloud). These environment variables
Expand Down
Loading