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 #1446 and #1395: completely update integration resource on redepl… #1447

Merged
merged 1 commit into from
May 5, 2020
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
4 changes: 2 additions & 2 deletions deploy/resources.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const (
IntegrationPhaseDeploying IntegrationPhase = "Deploying"
// IntegrationPhaseRunning --
IntegrationPhaseRunning IntegrationPhase = "Running"
// IntegrationPhaseUpdating is a phase where the operator is not supposed to interact with the resource
IntegrationPhaseUpdating IntegrationPhase = "Updating"
// IntegrationPhaseError --
IntegrationPhaseError IntegrationPhase = "Error"

Expand Down
24 changes: 17 additions & 7 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import (
"strings"
"syscall"

"github.com/spf13/pflag"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/trait"
Expand All @@ -47,6 +45,7 @@ import (
"github.com/magiconair/properties"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -299,6 +298,12 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
return err
}
}
if o.Logs || o.Dev || o.Wait {
go watch.HandleIntegrationEvents(o.Context, integration, func(event *corev1.Event) bool {
fmt.Fprintln(cmd.OutOrStdout(), event.Message)
return true
})
}
if o.Wait || o.Dev {
for {
integrationPhase, err := o.waitForIntegrationReady(cmd, integration)
Expand Down Expand Up @@ -380,11 +385,6 @@ func (o *runCmdOptions) waitForIntegrationReady(cmd *cobra.Command, integration
return true
}

go watch.HandleIntegrationEvents(o.Context, integration, func(event *corev1.Event) bool {
fmt.Fprintln(cmd.OutOrStdout(), event.Message)
return true
})

return watch.HandleIntegrationStateChanges(o.Context, integration, handler)
}

Expand Down Expand Up @@ -586,8 +586,18 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string)
if err != nil {
return nil, err
}
// Hold the resource from the operator controller
clone.Status.Phase = v1.IntegrationPhaseUpdating
err = c.Status().Update(o.Context, clone)
// Update the spec
integration.ResourceVersion = clone.ResourceVersion
err = c.Update(o.Context, &integration)
if err != nil {
return nil, err
}
// Reset the status
integration.Status = v1.IntegrationStatus{}
err = c.Status().Update(o.Context, &integration)
}

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/integration/integration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R
NewDeployAction(),
NewMonitorAction(),
NewErrorAction(),
NewNoopAction(),
}

for _, a := range actions {
Expand Down
49 changes: 49 additions & 0 deletions pkg/controller/integration/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
"context"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
)

// NewNoopAction is used to put an integration resource out of the operator lifecycle.
//
// The resource must be updated by an external entity (e.g. the kamel CLI) to a new state when ready
// to start a new workflow.
func NewNoopAction() Action {
return &noopAction{}
}

type noopAction struct {
baseAction
}

func (action *noopAction) Name() string {
return "noop"
}

func (action *noopAction) CanHandle(integration *v1.Integration) bool {
return integration.Status.Phase == v1.IntegrationPhaseUpdating
}

func (action *noopAction) Handle(ctx context.Context, integration *v1.Integration) (*v1.Integration, error) {
// Do nothing and return no object to update
return nil, nil
}