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 2023/10/04 10:53:03 UTC
[camel-k] 05/09: fix(ci): errors identified by checks
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 1cf40d8c0462f82f9b044662f093f87a3d21027d
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Sep 26 11:10:37 2023 +0200
fix(ci): errors identified by checks
---
pkg/controller/catalog/initialize.go | 22 +++++++++++++++++++---
pkg/trait/builder.go | 35 ++++++++++++++++++++++-------------
pkg/trait/builder_test.go | 14 +++++++++++---
pkg/trait/trait_catalog.go | 6 +++---
4 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/pkg/controller/catalog/initialize.go b/pkg/controller/catalog/initialize.go
index 20cd365d7..61be5e2c5 100644
--- a/pkg/controller/catalog/initialize.go
+++ b/pkg/controller/catalog/initialize.go
@@ -22,6 +22,7 @@ import (
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
platformutil "github.com/apache/camel-k/v2/pkg/platform"
+ corev1 "k8s.io/api/core/v1"
)
// NewInitializeAction returns a action that initializes the catalog configuration when not provided by the user.
@@ -61,9 +62,24 @@ func (action *initializeAction) Handle(ctx context.Context, catalog *v1.CamelCat
func initialize(catalog *v1.CamelCatalog) (*v1.CamelCatalog, error) {
target := catalog.DeepCopy()
- // TODO - we may verify the existence of the catalog image (required by native build)
- // or any other condition that may make a CamelCatalog to fail.
- target.Status.Phase = v1.CamelCatalogPhaseReady
+
+ if catalog.Spec.GetQuarkusToolingImage() == "" {
+ target.Status.Phase = v1.CamelCatalogPhaseError
+ target.Status.SetCondition(
+ v1.CamelCatalogConditionReady,
+ corev1.ConditionTrue,
+ "Container image tool",
+ "Container image tool missing in catalog. This catalog is not compatible with Camel K version above 2.0",
+ )
+ } else {
+ target.Status.Phase = v1.CamelCatalogPhaseReady
+ target.Status.SetCondition(
+ v1.CamelCatalogConditionReady,
+ corev1.ConditionTrue,
+ "Container image tool",
+ "Container image tool found in catalog",
+ )
+ }
return target, nil
}
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index e59ee7da5..44c6763b6 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -68,22 +68,26 @@ func (t *builderTrait) Configure(e *Environment) (bool, error) {
return false, nil
}
- if trait := e.Catalog.GetTrait(quarkusTraitID); trait != nil {
- quarkus, ok := trait.(*quarkusTrait)
- isNativeIntegration := quarkus.isNativeIntegration(e)
- isNativeKit, err := quarkus.isNativeKit(e)
- if err != nil {
- return false, err
- }
- if ok && pointer.BoolDeref(quarkus.Enabled, true) && (isNativeIntegration || isNativeKit) {
- nativeArgsCd := filepath.Join("maven", "target", "native-sources")
- command := "cd " + nativeArgsCd + " && echo NativeImage version is $(native-image --version) && echo GraalVM expected version is $(cat graalvm.version) && echo WARN: Make sure they are compatible, otherwise the native compilation may results in error && native-image $(cat native-image.args)"
- // it should be performed as the last custom task
- t.Tasks = append(t.Tasks, fmt.Sprintf(`quarkus-native;%s;/bin/bash -c "%s"`, e.CamelCatalog.GetQuarkusToolingImage(), command))
+ if e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted) {
+ if trait := e.Catalog.GetTrait(quarkusTraitID); trait != nil {
+ quarkus, ok := trait.(*quarkusTrait)
+ isNativeIntegration := quarkus.isNativeIntegration(e)
+ isNativeKit, err := quarkus.isNativeKit(e)
+ if err != nil {
+ return false, err
+ }
+ if ok && pointer.BoolDeref(quarkus.Enabled, true) && (isNativeIntegration || isNativeKit) {
+ nativeArgsCd := filepath.Join("maven", "target", "native-sources")
+ command := "cd " + nativeArgsCd + " && echo NativeImage version is $(native-image --version) && echo GraalVM expected version is $(cat graalvm.version) && echo WARN: Make sure they are compatible, otherwise the native compilation may results in error && native-image $(cat native-image.args)"
+ // it should be performed as the last custom task
+ t.Tasks = append(t.Tasks, fmt.Sprintf(`quarkus-native;%s;/bin/bash -c "%s"`, e.CamelCatalog.GetQuarkusToolingImage(), command))
+ }
}
+
+ return true, nil
}
- return e.IntegrationKitInPhase(v1.IntegrationKitPhaseBuildSubmitted), nil
+ return false, nil
}
func (t *builderTrait) Apply(e *Environment) error {
@@ -406,7 +410,12 @@ func (t *builderTrait) customTasks() ([]v1.Task, error) {
// we may get a command in the following format `/bin/bash -c "ls && echo 'hello'`
// which should provide a string with {"/bin/bash", "-c", "ls && echo 'hello'"}.
+// if however we have a command which is not quoted, then we leave it the way it is.
func splitContainerCommand(command string) []string {
+ if !strings.Contains(command, "\"") {
+ // No quotes, just return
+ return []string{command}
+ }
matches := commandsRegexp.FindAllString(command, -1)
removeQuotes := make([]string, 0, len(matches))
for _, m := range matches {
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
index 9708a7485..9a5b29472 100644
--- a/pkg/trait/builder_test.go
+++ b/pkg/trait/builder_test.go
@@ -320,7 +320,7 @@ func TestMavenBuilderTraitJib(t *testing.T) {
func TestBuilderCustomTasks(t *testing.T) {
builderTrait := createNominalBuilderTraitTest()
builderTrait.Tasks = append(builderTrait.Tasks, "test;alpine;ls")
- builderTrait.Tasks = append(builderTrait.Tasks, `test;alpine;"mvn test"`)
+ builderTrait.Tasks = append(builderTrait.Tasks, `test;alpine;mvn test`)
tasks, err := builderTrait.customTasks()
@@ -372,7 +372,15 @@ func TestUserTaskSingleCommand(t *testing.T) {
command := `cat /path/to/a/resource`
podCommands := splitContainerCommand(command)
+ assert.Len(t, podCommands, 1)
+ assert.Equal(t, "cat /path/to/a/resource", podCommands[0])
+}
+
+func TestUserTaskMultiCommands(t *testing.T) {
+ command := `"cat /path/to/a/resource" "echo ciao"`
+ podCommands := splitContainerCommand(command)
+
assert.Len(t, podCommands, 2)
- assert.Equal(t, "cat", podCommands[0])
- assert.Equal(t, "/path/to/a/resource", podCommands[1])
+ assert.Equal(t, "cat /path/to/a/resource", podCommands[0])
+ assert.Equal(t, "echo ciao", podCommands[1])
}
diff --git a/pkg/trait/trait_catalog.go b/pkg/trait/trait_catalog.go
index b8ec893d1..025a9cc98 100644
--- a/pkg/trait/trait_catalog.go
+++ b/pkg/trait/trait_catalog.go
@@ -102,13 +102,13 @@ func (c *Catalog) apply(environment *Environment) error {
applicable = true
enabled, err := trait.Configure(environment)
if err != nil {
- return err
+ return fmt.Errorf("%s trait configuration failed: %w", trait.ID(), err)
}
if enabled {
err = trait.Apply(environment)
if err != nil {
- return err
+ return fmt.Errorf("%s trait execution failed: %w", trait.ID(), err)
}
environment.ExecutedTraits = append(environment.ExecutedTraits, trait)
@@ -117,7 +117,7 @@ func (c *Catalog) apply(environment *Environment) error {
for _, processor := range environment.PostStepProcessors {
err := processor(environment)
if err != nil {
- return fmt.Errorf("error executing post step action: %w", err)
+ return fmt.Errorf("%s trait executing post step action failed: %w", trait.ID(), err)
}
}
}