Skip to content
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
40 changes: 40 additions & 0 deletions e2e/common/cli/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,43 @@ func TestBuildDontRun(t *testing.T) {
})
})
}

func TestPipeBuildDontRun(t *testing.T) {
t.Parallel()
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
name := RandomizedSuffixName("pipe-deploy")
t.Run("build and dont run pipe", func(t *testing.T) {
g.Expect(KamelBind(t, ctx, ns, "timer-source?message=HelloPipe", "log-sink",
"--name", name,
"--annotation", "camel.apache.org/dont-run-after-build=true",
).Execute()).To(Succeed())
g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseBuildComplete))
g.Eventually(PipePhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.PipePhaseBuildComplete))
g.Consistently(IntegrationPhase(t, ctx, ns, name), 10*time.Second).Should(Equal(v1.IntegrationPhaseBuildComplete))
g.Consistently(PipePhase(t, ctx, ns, name), 10*time.Second).Should(Equal(v1.PipePhaseBuildComplete))
g.Eventually(Deployment(t, ctx, ns, name)).Should(BeNil())
// Pipe condition should indicate build is complete
g.Eventually(PipeCondition(t, ctx, ns, name, v1.PipeConditionReady), TestTimeoutShort).Should(
WithTransform(PipeConditionReason, Equal("BuildComplete")))
})
t.Run("deploy the pipe", func(t *testing.T) {
t.Skip("Skipping: deploy/undeploy pipe lifecycle needs further investigation")
g.Expect(Kamel(t, ctx, "deploy", name, "-n", ns).Execute()).To(Succeed())
g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseRunning))
g.Eventually(PipePhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.PipePhaseReady))
g.Eventually(Deployment(t, ctx, ns, name)).ShouldNot(BeNil())
g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).
Should(Equal(corev1.ConditionTrue))
g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutMedium).Should(ContainSubstring("HelloPipe"))
})
t.Run("undeploy the pipe", func(t *testing.T) {
t.Skip("Skipping: deploy/undeploy pipe lifecycle needs further investigation")
g.Expect(Kamel(t, ctx, "undeploy", name, "-n", ns).Execute()).To(Succeed())
g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseBuildComplete))
g.Eventually(PipePhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.PipePhaseBuildComplete))
g.Eventually(IntegrationPodsNumbers(t, ctx, ns, name)).Should(Equal(ptr.To(int32(0))))
g.Eventually(Deployment(t, ctx, ns, name)).Should(BeNil())
})
})
}
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/pipe_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ const (
PipePhaseError PipePhase = "Error"
// PipePhaseReady --.
PipePhaseReady PipePhase = "Ready"
// PipePhaseBuildComplete --.
PipePhaseBuildComplete PipePhase = "Build Complete"
)

// +kubebuilder:object:root=true
Expand Down
9 changes: 4 additions & 5 deletions pkg/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ func newCmdDeploy(rootCmdOptions *RootCmdOptions) (*cobra.Command, *deployCmdOpt
RootCmdOptions: rootCmdOptions,
}
cmd := cobra.Command{
Use: "deploy my-it",
Short: "Deploy an Integration",
Long: "Deploy an Integration that was previously built",
Use: "deploy <name>",
Short: "Deploy an Integration or Pipe that was previously built",
PreRunE: decode(&options, options.Flags),
RunE: options.run,
}
Expand All @@ -48,7 +47,7 @@ type deployCmdOptions struct {

func (o *deployCmdOptions) validate(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("deploy requires an Integration name argument")
return errors.New("deploy requires an Integration or Pipe name argument")
}

return nil
Expand All @@ -67,7 +66,7 @@ func (o *deployCmdOptions) run(cmd *cobra.Command, args []string) error {

existing, err := getIntegration(o.Context, c, name, o.Namespace)
if err != nil {
return fmt.Errorf("could not get Integration "+name+": %w", err)
return fmt.Errorf("could not get Integration or Pipe "+name+": %w", err)
}
if existing.Status.Phase != v1.IntegrationPhaseBuildComplete {
return fmt.Errorf("could not run an Integration in %s status", existing.Status.Phase)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func TestDeployMissingInput(t *testing.T) {
cmd, _ := initializeDeployCmdOptions(t)
_, err := ExecuteCommand(cmd, cmdDeploy)
require.Error(t, err)
assert.Equal(t, "deploy requires an Integration name argument", err.Error())
assert.Equal(t, "deploy requires an Integration or Pipe name argument", err.Error())
}

func TestDeployMissingIntegration(t *testing.T) {
cmd, _ := initializeDeployCmdOptions(t)
_, err := ExecuteCommand(cmd, cmdDeploy, "missing-it")
require.Error(t, err)
assert.Equal(t, "could not get Integration missing-it: integrations.camel.apache.org \"missing-it\" not found", err.Error())
assert.Equal(t, "could not get Integration or Pipe missing-it: integrations.camel.apache.org \"missing-it\" not found", err.Error())
}

func TestDeployCantDeployRunningIntegration(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/undeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func newCmdUndeploy(rootCmdOptions *RootCmdOptions) (*cobra.Command, *undeployCm
RootCmdOptions: rootCmdOptions,
}
cmd := cobra.Command{
Use: "undeploy [integration1] [integration2] ...",
Short: "Undeploy one or more integrations previously deployed.",
Long: `Clear the state of one or more integrations causing them to move back to a Build Complete status.`,
Use: "undeploy [name1] [name2] ...",
Short: "Undeploy one or more Integrations or Pipes previously deployed.",
Long: `Clear the state of one or more Integrations or Pipes causing them to move back to a Build Complete status.`,
PreRunE: decode(&options, options.Flags),
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
Expand All @@ -55,7 +55,7 @@ type undeployCmdOptions struct {

func (o *undeployCmdOptions) validate(args []string) error {
if len(args) == 0 {
return errors.New("undeploy requires an Integration name argument")
return errors.New("undeploy requires an Integration or Pipe name argument")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/undeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestUndeployNoArgs(t *testing.T) {
cmd, _ := initializeUndeployCmdOptions(t)
_, err := ExecuteCommand(cmd, cmdUndeploy)
require.Error(t, err)
assert.Equal(t, "undeploy requires an Integration name argument", err.Error())
assert.Equal(t, "undeploy requires an Integration or Pipe name argument", err.Error())
}

func TestUndeployMissingIntegrations(t *testing.T) {
Expand Down
13 changes: 12 additions & 1 deletion pkg/controller/pipe/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (action *monitorAction) Name() string {
func (action *monitorAction) CanHandle(pipe *v1.Pipe) bool {
return pipe.Status.Phase == v1.PipePhaseCreating ||
pipe.Status.Phase == v1.PipePhaseError ||
pipe.Status.Phase == v1.PipePhaseReady
pipe.Status.Phase == v1.PipePhaseReady ||
pipe.Status.Phase == v1.PipePhaseBuildComplete
}

func (action *monitorAction) Handle(ctx context.Context, pipe *v1.Pipe) (*v1.Pipe, error) {
Expand Down Expand Up @@ -128,6 +129,16 @@ func (action *monitorAction) Handle(ctx context.Context, pipe *v1.Pipe) (*v1.Pip
target.Status.Phase = v1.PipePhaseError
setPipeReadyCondition(target, &it)

case v1.IntegrationPhaseBuildComplete:
target.Status.Phase = v1.PipePhaseBuildComplete
c := v1.PipeCondition{
Type: v1.PipeConditionReady,
Status: corev1.ConditionFalse,
Reason: "BuildComplete",
Message: fmt.Sprintf("Integration %q build completed successfully", it.GetName()),
}
target.Status.SetConditions(c)

default:
target.Status.Phase = v1.PipePhaseCreating

Expand Down
44 changes: 44 additions & 0 deletions pkg/controller/pipe/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,47 @@ func TestPipeIntegrationPipeTraitAnnotations(t *testing.T) {
assert.Equal(t, corev1.ConditionFalse, handledPipe.Status.GetCondition(v1.PipeConditionReady).Status)
assert.Equal(t, "Integration \"my-pipe\" is in \"Creating\" phase", handledPipe.Status.GetCondition(v1.PipeConditionReady).Message)
}

func TestPipeIntegrationBuildComplete(t *testing.T) {
pipe := &v1.Pipe{
TypeMeta: metav1.TypeMeta{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: v1.PipeKind,
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "ns",
Name: "my-pipe",
},
Spec: v1.PipeSpec{
Source: v1.Endpoint{
URI: ptr.To("timer:tick"),
},
Sink: v1.Endpoint{
URI: ptr.To("log:info"),
},
},
Status: v1.PipeStatus{
Phase: v1.PipePhaseCreating,
},
}

c, err := internal.NewFakeClient(pipe)
require.NoError(t, err)
it, err := CreateIntegrationFor(context.TODO(), c, pipe)
require.NoError(t, err)
it.Status.Phase = v1.IntegrationPhaseBuildComplete
c, err = internal.NewFakeClient(pipe, it)
require.NoError(t, err)

a := NewMonitorAction()
a.InjectLogger(log.Log)
a.InjectClient(c)
assert.Equal(t, "monitor", a.Name())
assert.True(t, a.CanHandle(pipe))
handledPipe, err := a.Handle(context.TODO(), pipe)
require.NoError(t, err)
assert.Equal(t, v1.PipePhaseBuildComplete, handledPipe.Status.Phase)
assert.Equal(t, corev1.ConditionFalse, handledPipe.Status.GetCondition(v1.PipeConditionReady).Status)
assert.Equal(t, "BuildComplete", handledPipe.Status.GetCondition(v1.PipeConditionReady).Reason)
assert.Equal(t, "Integration \"my-pipe\" build completed successfully", handledPipe.Status.GetCondition(v1.PipeConditionReady).Message)
}
Loading