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

[BACKPORT-2.2.x] fix(#4776): Fix catalog loading in camel trait #5117

Merged
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
32 changes: 18 additions & 14 deletions pkg/trait/camel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func (t *camelTrait) InfluencesBuild(this, prev map[string]interface{}) bool {

func (t *camelTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
if t.RuntimeVersion == "" {
t.RuntimeVersion = determineRuntimeVersion(e)
if runtimeVersion, err := determineRuntimeVersion(e); err != nil {
return false, nil, err
} else {
t.RuntimeVersion = runtimeVersion
}
}

return true, nil, nil
Expand Down Expand Up @@ -99,8 +103,8 @@ func (t *camelTrait) Apply(e *Environment) error {
}

func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string) error {
ns := e.DetermineCatalogNamespace()
if ns == "" {
catalogNamespace := e.DetermineCatalogNamespace()
if catalogNamespace == "" {
return errors.New("unable to determine namespace")
}

Expand All @@ -109,7 +113,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
Provider: v1.RuntimeProviderQuarkus,
}

catalog, err := camel.LoadCatalog(e.Ctx, e.Client, ns, runtime)
catalog, err := camel.LoadCatalog(e.Ctx, e.Client, catalogNamespace, runtime)
if err != nil {
return err
}
Expand All @@ -122,15 +126,15 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
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{})
catalogNamespace, e.Platform.Status.Build.Maven, runtime, []maven.Dependency{})
if err != nil {
return err
}

// sanitize catalog name
catalogName := "camel-catalog-" + strings.ToLower(runtimeVersion)

cx := v1.NewCamelCatalogWithSpecs(ns, catalogName, catalog.CamelCatalogSpec)
cx := v1.NewCamelCatalogWithSpecs(catalogNamespace, catalogName, catalog.CamelCatalogSpec)
cx.Labels = make(map[string]string)
cx.Labels["app"] = "camel-k"
cx.Labels["camel.apache.org/runtime.version"] = runtime.Version
Expand All @@ -142,7 +146,7 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
// 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)
catalog, err = camel.LoadCatalog(e.Ctx, e.Client, catalogNamespace, runtime)
if err != nil {
// unexpected error
return fmt.Errorf("catalog %q already exists but unable to load: %w", catalogName, err)
Expand All @@ -156,13 +160,13 @@ func (t *camelTrait) loadOrCreateCatalog(e *Environment, runtimeVersion string)
}
}

// verify that the catalog was generated
// verify that the catalog has been generated
ct, err := kubernetes.GetUnstructured(
e.Ctx,
e.Client,
schema.GroupVersionKind{Group: "camel.apache.org", Version: "v1", Kind: "CamelCatalog"},
catalogName,
e.Integration.Namespace,
catalogNamespace,
)
if ct == nil || err != nil {
return fmt.Errorf("unable to create catalog runtime=%s, provider=%s, name=%s: %w",
Expand Down Expand Up @@ -265,15 +269,15 @@ func (t *camelTrait) computeConfigMaps(e *Environment) []ctrl.Object {
return maps
}

func determineRuntimeVersion(e *Environment) string {
func determineRuntimeVersion(e *Environment) (string, error) {
if e.Integration != nil && e.Integration.Status.RuntimeVersion != "" {
return e.Integration.Status.RuntimeVersion
return e.Integration.Status.RuntimeVersion, nil
}
if e.IntegrationKit != nil && e.IntegrationKit.Status.RuntimeVersion != "" {
return e.IntegrationKit.Status.RuntimeVersion
return e.IntegrationKit.Status.RuntimeVersion, nil
}
if e.Platform != nil && e.Platform.Status.Build.RuntimeVersion != "" {
return e.Platform.Status.Build.RuntimeVersion
return e.Platform.Status.Build.RuntimeVersion, nil
}
return ""
return "", errors.New("unable to determine runtime version")
}
Loading