You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/11/04 16:10:48 UTC
[camel-k] 24/38: feat(quarkus): Support generating Camel Quarkus
catalog on the flight
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 86df7cf10e3903110f8ae62eb424a90f3a9dcb38
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Oct 25 12:17:41 2019 +0200
feat(quarkus): Support generating Camel Quarkus catalog on the flight
---
pkg/trait/quarkus.go | 50 +++++++++++++++++++++++++++++++++++----
pkg/util/camel/catalog.go | 60 +++++++++++++++++++++++++++++------------------
2 files changed, 82 insertions(+), 28 deletions(-)
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index 9dfe8ba..208a551 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -23,6 +23,8 @@ import (
"github.com/pkg/errors"
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
+
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/builder/runtime"
"github.com/apache/camel-k/pkg/metadata"
@@ -30,6 +32,7 @@ import (
"github.com/apache/camel-k/pkg/util/camel"
"github.com/apache/camel-k/pkg/util/defaults"
"github.com/apache/camel-k/pkg/util/envvar"
+ "github.com/apache/camel-k/pkg/util/maven"
)
type quarkusTrait struct {
@@ -62,17 +65,54 @@ func (t *quarkusTrait) loadOrCreateCatalog(e *Environment, camelVersion string,
return errors.New("unable to determine namespace")
}
- c, err := camel.LoadCatalog(e.C, e.Client, ns, camelVersion, runtimeVersion, v1alpha1.QuarkusRuntimeProvider{
- CamelQuarkusVersion: t.determineCamelQuarkusVersion(e),
- QuarkusVersion: t.determineQuarkusVersion(e),
+ camelQuarkusVersion := t.determineCamelQuarkusVersion(e)
+ quarkusVersion := t.determineQuarkusVersion(e)
+
+ catalog, err := camel.LoadCatalog(e.C, e.Client, ns, camelVersion, runtimeVersion, v1alpha1.QuarkusRuntimeProvider{
+ CamelQuarkusVersion: camelQuarkusVersion,
+ QuarkusVersion: quarkusVersion,
})
if err != nil {
return err
}
- e.CamelCatalog = c
+ if catalog == nil {
+ // if the catalog is not found in the cluster, try to create it if
+ // the required versions (camel, runtime and provider) are not expressed as
+ // semver constraints
+ if exactVersionRegexp.MatchString(camelVersion) && exactVersionRegexp.MatchString(runtimeVersion) &&
+ exactVersionRegexp.MatchString(camelQuarkusVersion) && exactVersionRegexp.MatchString(quarkusVersion) {
+ catalog, err = camel.GenerateCatalogWithProvider(e.C, e.Client, ns, e.Platform.Spec.Build.Maven, camelVersion, runtimeVersion,
+ "quarkus",
+ &maven.Dependency{
+ GroupID: "org.apache.camel.quarkus",
+ ArtifactID: "camel-catalog-quarkus",
+ Version: camelQuarkusVersion,
+ })
+ if err != nil {
+ return err
+ }
+
+ // sanitize catalog name
+ catalogName := "camel-catalog-quarkus" + strings.ToLower(camelVersion+"-"+runtimeVersion)
+
+ 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
+ cx.Labels["camel.apache.org/catalog.loader.version"] = camelVersion
+ cx.Labels["camel.apache.org/runtime.version"] = runtimeVersion
+ cx.Labels["camel.apache.org/runtime.provider"] = "quarkus"
+ cx.Labels["camel.apache.org/catalog.generated"] = True
+
+ err = e.Client.Create(e.C, &cx)
+ if err != nil && !k8serrors.IsAlreadyExists(err) {
+ return err
+ }
+ }
+ }
- // TODO: generate a catalog if nil
+ e.CamelCatalog = catalog
return nil
}
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index 4505334..b83eebc 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -67,7 +67,14 @@ func catalogForRuntimeProvider(provider interface{}) (*RuntimeCatalog, error) {
}
// GenerateCatalog --
-func GenerateCatalog(ctx context.Context, client k8sclient.Reader, namespace string, mvn v1alpha1.MavenSpec, camelVersion string, runtimeVersion string) (*RuntimeCatalog, error) {
+func GenerateCatalog(ctx context.Context, client k8sclient.Reader, namespace string, mvn v1alpha1.MavenSpec,
+ camelVersion string, runtimeVersion string) (*RuntimeCatalog, error) {
+ return GenerateCatalogWithProvider(ctx, client, namespace, mvn, camelVersion, runtimeVersion, "", nil)
+}
+
+// GenerateCatalogWithProvider --
+func GenerateCatalogWithProvider(ctx context.Context, client k8sclient.Reader, namespace string, mvn v1alpha1.MavenSpec,
+ camelVersion string, runtimeVersion string, providerName string, providerDependency *maven.Dependency) (*RuntimeCatalog, error) {
root := os.TempDir()
tmpDir, err := ioutil.TempDir(root, "camel-catalog")
if err != nil {
@@ -80,13 +87,16 @@ func GenerateCatalog(ctx context.Context, client k8sclient.Reader, namespace str
return nil, err
}
- project := generateMavenProject(camelVersion, runtimeVersion)
+ project := generateMavenProject(camelVersion, runtimeVersion, providerDependency)
mc := maven.NewContext(tmpDir, project)
mc.LocalRepository = mvn.LocalRepository
mc.Timeout = mvn.Timeout.Duration
mc.AddSystemProperty("catalog.path", tmpDir)
mc.AddSystemProperty("catalog.file", "catalog.yaml")
+ if providerName != "" {
+ mc.AddSystemProperty("catalog.runtime", providerName)
+ }
settings, err := kubernetes.ResolveValueSource(ctx, client, namespace, &mvn.Settings)
if err != nil {
@@ -114,33 +124,37 @@ func GenerateCatalog(ctx context.Context, client k8sclient.Reader, namespace str
return NewRuntimeCatalog(catalog.Spec), nil
}
-func generateMavenProject(camelVersion string, runtimeVersion string) maven.Project {
+func generateMavenProject(camelVersion string, runtimeVersion string, providerDependency *maven.Dependency) maven.Project {
p := maven.NewProjectWithGAV("org.apache.camel.k.integration", "camel-k-catalog-generator", defaults.Version)
- p.Build = &maven.Build{
- DefaultGoal: "generate-resources",
- Plugins: []maven.Plugin{
+ plugin := maven.Plugin{
+ GroupID: "org.apache.camel.k",
+ ArtifactID: "camel-k-maven-plugin",
+ Version: runtimeVersion,
+ Executions: []maven.Execution{
{
- GroupID: "org.apache.camel.k",
- ArtifactID: "camel-k-maven-plugin",
- Version: runtimeVersion,
- Executions: []maven.Execution{
- {
- ID: "generate-catalog",
- Goals: []string{
- "generate-catalog",
- },
- },
- },
- Dependencies: []maven.Dependency{
- {
- GroupID: "org.apache.camel",
- ArtifactID: "camel-catalog",
- Version: camelVersion,
- },
+ ID: "generate-catalog",
+ Goals: []string{
+ "generate-catalog",
},
},
},
+ Dependencies: []maven.Dependency{
+ {
+ GroupID: "org.apache.camel",
+ ArtifactID: "camel-catalog",
+ Version: camelVersion,
+ },
+ },
+ }
+
+ if providerDependency != nil {
+ plugin.Dependencies = append(plugin.Dependencies, *providerDependency)
+ }
+
+ p.Build = &maven.Build{
+ DefaultGoal: "generate-resources",
+ Plugins: []maven.Plugin{plugin},
}
return p