Skip to content

Commit

Permalink
fix(e2e): add test to make sure
Browse files Browse the repository at this point in the history
Deployment is not recreated on update.
  • Loading branch information
squakez committed Oct 10, 2024
1 parent b594c39 commit 559585b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 76 deletions.
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

0 comments on commit 559585b

Please sign in to comment.