You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2022/12/01 08:18:40 UTC
[camel-k] branch release-1.10.x updated: fix(trait): trait error "camel-catalog already exists" during upgrade
This is an automated email from the ASF dual-hosted git repository.
tsato pushed a commit to branch release-1.10.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/release-1.10.x by this push:
new d866855b8 fix(trait): trait error "camel-catalog already exists" during upgrade
d866855b8 is described below
commit d866855b82279b5bf5b19f28cf7972bffe731785
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Wed Nov 30 13:02:24 2022 +0900
fix(trait): trait error "camel-catalog already exists" during upgrade
---
pkg/trait/camel.go | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index 179714ccf..d20de26e0 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -25,6 +25,7 @@ import (
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
@@ -64,8 +65,7 @@ func (t *camelTrait) Apply(e *Environment) error {
rv := t.determineRuntimeVersion(e)
if e.CamelCatalog == nil {
- err := t.loadOrCreateCatalog(e, rv)
- if err != nil {
+ if err := t.loadOrCreateCatalog(e, rv); err != nil {
return err
}
}
@@ -113,7 +113,8 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
if exactVersionRegexp.MatchString(runtimeVersion) {
ctx, cancel := context.WithTimeout(e.Ctx, e.Platform.Status.Build.GetTimeout().Duration)
defer cancel()
- catalog, err = camel.GenerateCatalog(ctx, e.Client, ns, e.Platform.Status.Build.Maven, runtime, []maven.Dependency{})
+ catalog, err = camel.GenerateCatalog(ctx, e.Client,
+ ns, e.Platform.Status.Build.Maven, runtime, []maven.Dependency{})
if err != nil {
return err
}
@@ -128,12 +129,22 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
cx.Labels["camel.apache.org/runtime.provider"] = string(runtime.Provider)
cx.Labels["camel.apache.org/catalog.generated"] = True
- err = e.Client.Create(e.Ctx, &cx)
- if err != nil {
- return errors.Wrapf(err, "unable to create catalog runtime=%s, provider=%s, name=%s",
- runtime.Version,
- runtime.Provider,
- catalogName)
+ if err := e.Client.Create(e.Ctx, &cx); err != nil {
+ if k8serrors.IsAlreadyExists(err) {
+ // It's still possible that catalog wasn't yet found at the time of loading
+ // but then created in the background before the client tries to create it.
+ // In this case, simply try loading again and reuse the existing catalog.
+ catalog, err = camel.LoadCatalog(e.Ctx, e.Client, ns, runtime)
+ if err != nil {
+ // unexpected error
+ return errors.Wrapf(err, "catalog %q already exists but unable to load", catalogName)
+ }
+ } else {
+ return errors.Wrapf(err, "unable to create catalog runtime=%s, provider=%s, name=%s",
+ runtime.Version,
+ runtime.Provider,
+ catalogName)
+ }
}
}
}