Skip to content

Commit

Permalink
chore: monitor when missing delete event
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Jan 9, 2024
1 parent a1601b7 commit bc63675
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions pkg/controller/integration/monitor_synthetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 11 additions & 2 deletions pkg/controller/integration/monitor_synthetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/trait/trait.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc63675

Please sign in to comment.