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

fix(trait): execute GC only in running phases #5883

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8746,6 +8746,8 @@ List of Services in the form [[apigroup/]version:]kind:[namespace/]name
The Service trait exposes the integration with a Service resource so that it can be accessed by other applications
(or integrations) in the same namespace.

NOTE: this trait is automatically disabled if the Knative Service trait is enabled.

It's enabled by default if the integration depends on a Camel component that can expose a HTTP endpoint.


Expand Down
2 changes: 2 additions & 0 deletions docs/modules/traits/pages/service.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
The Service trait exposes the integration with a Service resource so that it can be accessed by other applications
(or integrations) in the same namespace.

NOTE: this trait is automatically disabled if the Knative Service trait is enabled.

It's enabled by default if the integration depends on a Camel component that can expose a HTTP endpoint.


Expand Down
13 changes: 11 additions & 2 deletions e2e/common/traits/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package common
import (
"context"
"testing"
"time"

. "github.com/onsi/gomega"

Expand All @@ -38,11 +39,19 @@ func TestGarbageCollectorTrait(t *testing.T) {
t.Run("Delete outdated resources", func(t *testing.T) {
g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java").Execute()).To(Succeed())
g.Eventually(IntegrationPodPhase(t, ctx, ns, "platform-http-server"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty())
g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeClusterIP), TestTimeoutShort).ShouldNot(BeEmpty())
g.Eventually(Deployment(t, ctx, ns, "platform-http-server"), TestTimeoutShort).ShouldNot(BeNil())
genOneDeploymentUID := DeploymentUID(t, ctx, ns, "platform-http-server")()

// Update integration and disable service trait - existing service should be garbage collected
g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java", "-t", "service.enabled=false").Execute()).To(Succeed())
g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).Should(BeEmpty())
g.Eventually(ServicesByType(t, ctx, ns, corev1.ServiceTypeClusterIP), TestTimeoutShort).Should(BeEmpty())
g.Eventually(Deployment(t, ctx, ns, "platform-http-server"), TestTimeoutShort).ShouldNot(BeNil())

// IMPORTANT: The Deployment UID must not change, otherwise we won't honor rolling upgrades as we delete and create a
// new Deployment for every Integration change.
g.Consistently(DeploymentUID(t, ctx, ns, "platform-http-server"), 3*time.Second, 1*time.Minute).
Should(Equal(genOneDeploymentUID))
})
})
}
64 changes: 0 additions & 64 deletions e2e/knative/gc_test.go

This file was deleted.

16 changes: 6 additions & 10 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,16 +839,6 @@ func Service(t *testing.T, ctx context.Context, ns string, name string) func() *
}
}

func ServiceType(t *testing.T, ctx context.Context, ns string, name string) func() corev1.ServiceType {
return func() corev1.ServiceType {
svc := Service(t, ctx, ns, name)()
if svc == nil {
return ""
}
return svc.Spec.Type
}
}

// ServicesByType Find the service in the given namespace with the given type
func ServicesByType(t *testing.T, ctx context.Context, ns string, svcType corev1.ServiceType) func() []corev1.Service {
return func() []corev1.Service {
Expand Down Expand Up @@ -1850,6 +1840,12 @@ func DeploymentCondition(t *testing.T, ctx context.Context, ns string, name stri
}
}

func DeploymentUID(t *testing.T, ctx context.Context, ns string, name string) func() string {
return func() string {
return string(Deployment(t, ctx, ns, name)().GetUID())
}
}

func Build(t *testing.T, ctx context.Context, ns, name string) func() *v1.Build {
return func() *v1.Build {
build := v1.NewBuild(ns, name)
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/trait/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package trait
// The Service trait exposes the integration with a Service resource so that it can be accessed by other applications
// (or integrations) in the same namespace.
//
// NOTE: this trait is automatically disabled if the Knative Service trait is enabled.
//
// It's enabled by default if the integration depends on a Camel component that can expose a HTTP endpoint.
//
// +camel-k:trait=service.
Expand Down
4 changes: 3 additions & 1 deletion pkg/trait/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func (t *gcTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
return false, NewIntegrationConditionUserDisabled("GC"), nil
}

return e.IntegrationInPhase(v1.IntegrationPhaseInitialization) || e.IntegrationInRunningPhases(), nil, nil
// We need to execute this trait only when all resources have been created and
// deployed with a new generation if there is was any change during the Integration drift.
return e.IntegrationInRunningPhases(), nil, nil
}

func (t *gcTrait) Apply(e *Environment) error {
Expand Down
Loading