This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit bc63675eb9ca8473fddf0f9e108997cd336779d0 Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Wed Jan 3 15:26:48 2024 +0100 chore: monitor when missing delete event --- pkg/controller/integration/monitor_synthetic.go | 11 +++++++++++ pkg/controller/integration/monitor_synthetic_test.go | 13 +++++++++++-- pkg/trait/trait.go | 7 ++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/controller/integration/monitor_synthetic.go b/pkg/controller/integration/monitor_synthetic.go index cee622163..a51758814 100644 --- a/pkg/controller/integration/monitor_synthetic.go +++ b/pkg/controller/integration/monitor_synthetic.go @@ -65,5 +65,16 @@ func (action *monitorSyntheticAction) Handle(ctx context.Context, integration *v return integration, err } + if environment == nil { + // The application which generated the Integration has no longer the importing label. We may have missed the + // delete event, therefore we need to perform the operation here. + err := action.client.Delete(ctx, integration) + action.L.Infof("Deleting synthetic Integration %s", integration.Name) + if err != nil { + return integration, err + } + return nil, nil + } + return action.monitorPods(ctx, environment, integration) } diff --git a/pkg/controller/integration/monitor_synthetic_test.go b/pkg/controller/integration/monitor_synthetic_test.go index c2217218a..aa1f9b232 100644 --- a/pkg/controller/integration/monitor_synthetic_test.go +++ b/pkg/controller/integration/monitor_synthetic_test.go @@ -110,7 +110,7 @@ func TestMonitorSyntheticIntegrationCannotMonitorPods(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "my-deploy", - Annotations: map[string]string{ + Labels: map[string]string{ v1.IntegrationLabel: "my-imported-it", }, }, @@ -178,7 +178,7 @@ func TestMonitorSyntheticIntegrationDeployment(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "my-deploy", - Annotations: map[string]string{ + Labels: map[string]string{ v1.IntegrationLabel: "my-imported-it", }, }, @@ -249,6 +249,15 @@ func TestMonitorSyntheticIntegrationDeployment(t *testing.T) { // Check monitoring pods condition assert.Equal(t, corev1.ConditionTrue, handledIt.Status.GetCondition(v1.IntegrationConditionMonitoringPodsAvailable).Status) assert.Equal(t, v1.IntegrationConditionMonitoringPodsAvailableReason, handledIt.Status.GetCondition(v1.IntegrationConditionMonitoringPodsAvailable).Reason) + + // Remove label from deployment + deploy.Labels = nil + c, err = test.NewFakeClient(importedIt, deploy) + assert.Nil(t, err) + a.InjectClient(c) + handledIt, err = a.Handle(context.TODO(), importedIt) + assert.Nil(t, err) + assert.Nil(t, handledIt) } func TestMonitorSyntheticIntegrationCronJob(t *testing.T) { diff --git a/pkg/trait/trait.go b/pkg/trait/trait.go index 16794ee12..059b294f1 100644 --- a/pkg/trait/trait.go +++ b/pkg/trait/trait.go @@ -137,7 +137,8 @@ func newEnvironment(ctx context.Context, c client.Client, integration *v1.Integr return &env, nil } -// NewSyntheticEnvironment creates an environment suitable for a synthetic Integration. +// NewSyntheticEnvironment creates an environment suitable for a synthetic Integration. If the application which generated the synthetic Integration +// has no longer the label, it will return a nil result. func NewSyntheticEnvironment(ctx context.Context, c client.Client, integration *v1.Integration, kit *v1.IntegrationKit) (*Environment, error) { if integration == nil && kit == nil { return nil, errors.New("neither integration nor kit are set") @@ -173,6 +174,10 @@ func NewSyntheticEnvironment(ctx context.Context, c client.Client, integration * if err != nil { return nil, err } + // Verify if the application has still the expected label. If not, return nil. + if camelApp.GetLabels()[v1.IntegrationLabel] != integration.Name { + return nil, nil + } env.Resources.Add(camelApp) return &env, nil