This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9ff6f5b5d2b041aa5e8293f4b63100c61842561b Author: Antonin Stefanutti <[email protected]> AuthorDate: Mon Oct 28 11:17:21 2019 +0100 fix(Quarkus): Fix on the flight Camel catalog generation --- pkg/builder/runtime/main.go | 6 ++++++ pkg/builder/runtime/quarkus.go | 6 ++++++ pkg/trait/camel.go | 19 ++++++++++--------- pkg/trait/quarkus.go | 7 ++++++- pkg/util/camel/camel_runtime.go | 18 +++--------------- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pkg/builder/runtime/main.go b/pkg/builder/runtime/main.go index c8854f9..4f2cb3e 100644 --- a/pkg/builder/runtime/main.go +++ b/pkg/builder/runtime/main.go @@ -18,6 +18,7 @@ limitations under the License. package runtime import ( + "fmt" "io/ioutil" "path" @@ -45,6 +46,11 @@ func loadCamelCatalog(ctx *builder.Context) error { return err } + if catalog == nil { + return fmt.Errorf("unable to find catalog matching version requirement: camel=%s, runtime=%s", + ctx.Build.CamelVersion, ctx.Build.RuntimeVersion) + } + ctx.Catalog = catalog return nil diff --git a/pkg/builder/runtime/quarkus.go b/pkg/builder/runtime/quarkus.go index 7cf1736..265e0da 100644 --- a/pkg/builder/runtime/quarkus.go +++ b/pkg/builder/runtime/quarkus.go @@ -3,6 +3,7 @@ package runtime import ( "bufio" "bytes" + "fmt" "os" "path" @@ -28,6 +29,11 @@ func loadCamelQuarkusCatalog(ctx *builder.Context) error { return err } + if catalog == nil { + return fmt.Errorf("unable to find catalog matching version requirement: camel=%s, runtime=%s, camel-quarkus=%s, quarkus=%s", + ctx.Build.CamelVersion, ctx.Build.RuntimeVersion, ctx.Build.RuntimeProvider.Quarkus.CamelQuarkusVersion, ctx.Build.RuntimeProvider.Quarkus.QuarkusVersion) + } + ctx.Catalog = catalog return nil diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go index 2a07b37..d43d188 100644 --- a/pkg/trait/camel.go +++ b/pkg/trait/camel.go @@ -68,10 +68,6 @@ func (t *camelTrait) Apply(e *Environment) error { } } - if e.CamelCatalog == nil { - return fmt.Errorf("unable to find catalog for: %s", cv) - } - e.RuntimeVersion = rv if e.Integration != nil { @@ -94,17 +90,17 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, camelVersion string, ru return errors.New("unable to determine namespace") } - c, err := camel.LoadCatalog(e.C, e.Client, ns, camelVersion, runtimeVersion, nil) + catalog, err := camel.LoadCatalog(e.C, e.Client, ns, camelVersion, runtimeVersion, nil) if err != nil { return err } - if c == nil { + if catalog == nil { // if the catalog is not found in the cluster, try to create it if // the required versions (camel and runtime) are not expressed as // semver constraints if exactVersionRegexp.MatchString(camelVersion) && exactVersionRegexp.MatchString(runtimeVersion) { - c, err = camel.GenerateCatalog(e.C, e.Client, ns, e.Platform.Spec.Build.Maven, camelVersion, runtimeVersion) + catalog, err = camel.GenerateCatalog(e.C, e.Client, ns, e.Platform.Spec.Build.Maven, camelVersion, runtimeVersion) if err != nil { return err } @@ -112,7 +108,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, camelVersion string, ru // sanitize catalog name catalogName := "camel-catalog-" + strings.ToLower(camelVersion+"-"+runtimeVersion) - cx := v1alpha1.NewCamelCatalogWithSpecs(ns, catalogName, c.CamelCatalogSpec) + cx := v1alpha1.NewCamelCatalogWithSpecs(ns, catalogName, catalog.CamelCatalogSpec) cx.Labels = make(map[string]string) cx.Labels["app"] = "camel-k" cx.Labels["camel.apache.org/catalog.version"] = camelVersion @@ -127,7 +123,12 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, camelVersion string, ru } } - e.CamelCatalog = c + if catalog == nil { + return fmt.Errorf("unable to find catalog matching version requirement: camel=%s, runtime=%s", + camelVersion, runtimeVersion) + } + + e.CamelCatalog = catalog return nil } diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go index 208a551..1a3bff4 100644 --- a/pkg/trait/quarkus.go +++ b/pkg/trait/quarkus.go @@ -94,7 +94,7 @@ func (t *quarkusTrait) loadOrCreateCatalog(e *Environment, camelVersion string, } // sanitize catalog name - catalogName := "camel-catalog-quarkus" + strings.ToLower(camelVersion+"-"+runtimeVersion) + catalogName := "camel-catalog-quarkus-" + strings.ToLower(camelVersion+"-"+runtimeVersion) cx := v1alpha1.NewCamelCatalogWithSpecs(ns, catalogName, catalog.CamelCatalogSpec) cx.Labels = make(map[string]string) @@ -112,6 +112,11 @@ func (t *quarkusTrait) loadOrCreateCatalog(e *Environment, camelVersion string, } } + if catalog == nil { + return fmt.Errorf("unable to find catalog matching version requirement: camel=%s, runtime=%s, camel-quarkus=%s, quarkus=%s", + camelVersion, runtimeVersion, camelQuarkusVersion, quarkusVersion) + } + e.CamelCatalog = catalog return nil diff --git a/pkg/util/camel/camel_runtime.go b/pkg/util/camel/camel_runtime.go index b62b967..c9aea1b 100644 --- a/pkg/util/camel/camel_runtime.go +++ b/pkg/util/camel/camel_runtime.go @@ -19,7 +19,6 @@ package camel import ( "context" - "fmt" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" @@ -28,7 +27,7 @@ import ( "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/client" - controllerUtil "github.com/apache/camel-k/pkg/util/controller" + "github.com/apache/camel-k/pkg/util/controller" ) // LoadCatalog -- @@ -40,7 +39,7 @@ func LoadCatalog(ctx context.Context, client client.Client, namespace string, ca if provider == nil { integration, _ := labels.NewRequirement("camel.apache.org/runtime.provider", selection.DoesNotExist, []string{}) selector := labels.NewSelector().Add(*integration) - options = append(options, controllerUtil.MatchingSelector{Selector: selector}) + options = append(options, controller.MatchingSelector{Selector: selector}) } else if _, ok := provider.(v1alpha1.QuarkusRuntimeProvider); ok { options = append(options, k8sclient.MatchingLabels{ "camel.apache.org/runtime.provider": "quarkus", @@ -58,16 +57,5 @@ func LoadCatalog(ctx context.Context, client client.Client, namespace string, ca return nil, err } - if catalog != nil { - return catalog, nil - } - - switch provider := provider.(type) { - case v1alpha1.QuarkusRuntimeProvider: - return nil, fmt.Errorf("unable to find catalog matching version requirement: camel=%s, runtime=%s, camel-quarkus=%s, quarkus=%s", - camelVersion, runtimeVersion, provider.CamelQuarkusVersion, provider.QuarkusVersion) - default: - return nil, fmt.Errorf("unable to find catalog matching version requirement: camel=%s, runtime=%s", - camelVersion, runtimeVersion) - } + return catalog, nil }
