lburgazzoli commented on code in PR #4942: URL: https://github.com/apache/camel-k/pull/4942#discussion_r1409619250
########## pkg/controller/integration/integration_controller_import.go: ########## @@ -0,0 +1,249 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "context" + + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/client" + "github.com/apache/camel-k/v2/pkg/util/log" + "github.com/apache/camel-k/v2/pkg/util/patch" + appsv1 "k8s.io/api/apps/v1" + batchv1 "k8s.io/api/batch/v1" + k8serrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + servingv1 "knative.dev/serving/pkg/apis/serving/v1" + ctrl "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/reconcile" +) + +// nonManagedCamelAppEnqueueRequestsFromMapFunc represent the function to discover the Integration which has to be woke up: it creates a synthetic +// Integration if the Integration does not exist. This is used to import external Camel applications. +func nonManagedCamelAppEnqueueRequestsFromMapFunc(ctx context.Context, c client.Client, adp NonManagedCamelApplicationAdapter) []reconcile.Request { + if adp.GetIntegrationName() == "" { + return []reconcile.Request{} + } + it := v1.NewIntegration(adp.GetIntegrationNameSpace(), adp.GetIntegrationName()) + err := c.Get(ctx, ctrl.ObjectKeyFromObject(&it), &it) + if err != nil { + if k8serrors.IsNotFound(err) { + // We must perform this check to make sure the resource is not being deleted. + // In such case it makes no sense to create an Integration after it. + err := c.Get(ctx, ctrl.ObjectKeyFromObject(adp.GetAppObj()), adp.GetAppObj()) + if err != nil { + if k8serrors.IsNotFound(err) { + return []reconcile.Request{} + } + log.Errorf(err, "Some error happened while trying to get %s %s resource", adp.GetName(), adp.GetKind()) + } + createSyntheticIntegration(&it, adp) Review Comment: I'm not sure if it is a good idea to create a syntetic integration here, maybe we must create a dedicated informer ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org