Skip to content

Commit

Permalink
apache#1199: logging status information in dev and wait mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Feb 22, 2020
1 parent 36e3699 commit b4549ba
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 51 deletions.
1 change: 1 addition & 0 deletions deploy/operator-role-kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ rules:
resources:
- events
verbs:
- create
- get
- list
- watch
Expand Down
1 change: 1 addition & 0 deletions deploy/operator-role-olm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ rules:
resources:
- events
verbs:
- create
- get
- list
- watch
Expand Down
1 change: 1 addition & 0 deletions deploy/operator-role-openshift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ rules:
resources:
- events
verbs:
- create
- get
- list
- watch
Expand Down
5 changes: 3 additions & 2 deletions e2e/dev_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func TestRunDevMode(t *testing.T) {
kamelRun := kamelWithContext(ctx, "run", "-n", ns, file, "--dev")
kamelRun.SetOut(pipew)

logScanner := util.NewLogScanner(ctx, piper, "Magicstring!", "Magicjordan!")
logScanner := util.NewLogScanner(ctx, piper, "Integration yaml in phase Running", "Magicstring!", "Magicjordan!")

go kamelRun.Execute()

Eventually(logScanner.IsFound("Magicstring!"), 5*time.Minute).Should(BeTrue())
Eventually(logScanner.IsFound("Integration yaml in phase Running"), 5*time.Minute).Should(BeTrue())
Eventually(logScanner.IsFound("Magicstring!"), 3*time.Minute).Should(BeTrue())
Expect(logScanner.IsFound("Magicjordan!")()).To(BeFalse())

util.ReplaceInFile(t, file, "string!", "jordan!")
Expand Down
23 changes: 9 additions & 14 deletions pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {

if collection == nil {
if o.Wait {
err = o.waitForPlatformReady(platform)
err = o.waitForPlatformReady(cobraCmd, platform)
if err != nil {
return err
}
Expand Down Expand Up @@ -418,25 +418,20 @@ func (o *installCmdOptions) printOutput(collection *kubernetes.Collection) error
return nil
}

func (o *installCmdOptions) waitForPlatformReady(platform *v1.IntegrationPlatform) error {
func (o *installCmdOptions) waitForPlatformReady(cmd *cobra.Command, platform *v1.IntegrationPlatform) error {
handler := func(i *v1.IntegrationPlatform) bool {
if i.Status.Phase != "" {
fmt.Println("platform \""+platform.Name+"\" in phase", i.Status.Phase)

if i.Status.Phase == v1.IntegrationPlatformPhaseReady {
// TODO display some error info when available in the status
return false
}

if i.Status.Phase == v1.IntegrationPlatformPhaseError {
fmt.Println("platform installation failed")
return false
}
if i.Status.Phase == v1.IntegrationPlatformPhaseReady || i.Status.Phase == v1.IntegrationPlatformPhaseError {
return false
}

return true
}

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

return watch.HandlePlatformStateChanges(o.Context, platform, handler)
}

Expand Down
24 changes: 10 additions & 14 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/magiconair/properties"
"github.com/pkg/errors"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -245,15 +246,14 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
}
if o.Wait || o.Dev {
for {
integrationPhase, err := o.waitForIntegrationReady(integration)
integrationPhase, err := o.waitForIntegrationReady(cmd, integration)
if err != nil {
return err
}

if integrationPhase == nil || *integrationPhase == v1.IntegrationPhaseError {
return fmt.Errorf("integration \"%s\" deployment failed", integration.Name)
} else if *integrationPhase == v1.IntegrationPhaseRunning {
fmt.Println("Running")
break
}

Expand Down Expand Up @@ -297,27 +297,23 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
return nil
}

func (o *runCmdOptions) waitForIntegrationReady(integration *v1.Integration) (*v1.IntegrationPhase, error) {
func (o *runCmdOptions) waitForIntegrationReady(cmd *cobra.Command, integration *v1.Integration) (*v1.IntegrationPhase, error) {
handler := func(i *v1.Integration) bool {
//
// TODO when we add health checks, we should Wait until they are passed
//
if i.Status.Phase != "" {
fmt.Println("integration \""+integration.Name+"\" in phase", i.Status.Phase)

if i.Status.Phase == v1.IntegrationPhaseRunning {
// TODO display some error info when available in the status
return false
}

if i.Status.Phase == v1.IntegrationPhaseError {
return false
}
if i.Status.Phase == v1.IntegrationPhaseRunning || i.Status.Phase == v1.IntegrationPhaseError {
return false
}

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
8 changes: 4 additions & 4 deletions pkg/controller/build/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"sync"
"time"

"github.com/apache/camel-k/pkg/events"
camelevent "github.com/apache/camel-k/pkg/event"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -208,13 +208,13 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result,

newTarget, err := a.Handle(ctx, target)
if err != nil {
events.NotifyBuildError(ctx, r.client, r.recorder, &instance, newTarget, err)
camelevent.NotifyBuildError(ctx, r.client, r.recorder, &instance, newTarget, err)
return reconcile.Result{}, err
}

if newTarget != nil {
if res, err := r.update(ctx, &instance, newTarget); err != nil {
events.NotifyBuildError(ctx, r.client, r.recorder, &instance, newTarget, err)
camelevent.NotifyBuildError(ctx, r.client, r.recorder, &instance, newTarget, err)
return res, err
}

Expand All @@ -231,7 +231,7 @@ func (r *ReconcileBuild) Reconcile(request reconcile.Request) (reconcile.Result,

// handle one action at time so the resource
// is always at its latest state
events.NotifyBuildUpdated(ctx, r.client, r.recorder, &instance, newTarget)
camelevent.NotifyBuildUpdated(ctx, r.client, r.recorder, &instance, newTarget)
break
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/integration/integration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package integration
import (
"context"

"github.com/apache/camel-k/pkg/events"
camelevent "github.com/apache/camel-k/pkg/event"
appsv1 "k8s.io/api/apps/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -260,13 +260,13 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R

newTarget, err := a.Handle(ctx, target)
if err != nil {
events.NotifyIntegrationError(ctx, r.client, r.recorder, &instance, newTarget, err)
camelevent.NotifyIntegrationError(ctx, r.client, r.recorder, &instance, newTarget, err)
return reconcile.Result{}, err
}

if newTarget != nil {
if res, err := r.update(ctx, &instance, newTarget); err != nil {
events.NotifyIntegrationError(ctx, r.client, r.recorder, &instance, newTarget, err)
camelevent.NotifyIntegrationError(ctx, r.client, r.recorder, &instance, newTarget, err)
return res, err
}

Expand All @@ -281,7 +281,7 @@ func (r *ReconcileIntegration) Reconcile(request reconcile.Request) (reconcile.R

// handle one action at time so the resource
// is always at its latest state
events.NotifyIntegrationUpdated(ctx, r.client, r.recorder, &instance, newTarget)
camelevent.NotifyIntegrationUpdated(ctx, r.client, r.recorder, &instance, newTarget)
break
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/integrationkit/integrationkit_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package integrationkit
import (
"context"

"github.com/apache/camel-k/pkg/events"
camelevent "github.com/apache/camel-k/pkg/event"
"github.com/apache/camel-k/pkg/platform"
"k8s.io/client-go/tools/record"

Expand Down Expand Up @@ -227,13 +227,13 @@ func (r *ReconcileIntegrationKit) Reconcile(request reconcile.Request) (reconcil

newTarget, err := a.Handle(ctx, target)
if err != nil {
events.NotifyIntegrationKitError(ctx, r.client, r.recorder, &instance, newTarget, err)
camelevent.NotifyIntegrationKitError(ctx, r.client, r.recorder, &instance, newTarget, err)
return reconcile.Result{}, err
}

if newTarget != nil {
if res, err := r.update(ctx, &instance, newTarget); err != nil {
events.NotifyIntegrationKitError(ctx, r.client, r.recorder, &instance, newTarget, err)
camelevent.NotifyIntegrationKitError(ctx, r.client, r.recorder, &instance, newTarget, err)
return res, err
}

Expand All @@ -248,7 +248,7 @@ func (r *ReconcileIntegrationKit) Reconcile(request reconcile.Request) (reconcil

// handle one action at time so the resource
// is always at its latest state
events.NotifyIntegrationKitUpdated(ctx, r.client, r.recorder, &instance, newTarget)
camelevent.NotifyIntegrationKitUpdated(ctx, r.client, r.recorder, &instance, newTarget)
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"time"

"github.com/apache/camel-k/pkg/events"
camelevent "github.com/apache/camel-k/pkg/event"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -151,13 +151,13 @@ func (r *ReconcileIntegrationPlatform) Reconcile(request reconcile.Request) (rec

target, err = a.Handle(ctx, target)
if err != nil {
events.NotifyIntegrationPlatformError(ctx, r.client, r.recorder, &instance, target, err)
camelevent.NotifyIntegrationPlatformError(ctx, r.client, r.recorder, &instance, target, err)
return reconcile.Result{}, err
}

if target != nil {
if err := r.client.Status().Patch(ctx, target, k8sclient.MergeFrom(&instance)); err != nil {
events.NotifyIntegrationPlatformError(ctx, r.client, r.recorder, &instance, target, err)
camelevent.NotifyIntegrationPlatformError(ctx, r.client, r.recorder, &instance, target, err)
return reconcile.Result{}, err
}

Expand All @@ -174,7 +174,7 @@ func (r *ReconcileIntegrationPlatform) Reconcile(request reconcile.Request) (rec

// handle one action at time so the resource
// is always at its latest state
events.NotifyIntegrationPlatformUpdated(ctx, r.client, r.recorder, &instance, target)
camelevent.NotifyIntegrationPlatformUpdated(ctx, r.client, r.recorder, &instance, target)
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/manager.go → pkg/event/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package events
package event

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestApplyDeploymentTraitWhileDeployingIntegrationDoesSucceed(t *testing.T)
conditions := environment.Integration.Status.Conditions
assert.Len(t, conditions, 1)
assert.Equal(t, v1.IntegrationConditionDeploymentAvailable, conditions[0].Type)
assert.Equal(t, "integration-name", conditions[0].Message)
assert.Equal(t, "deployment name is integration-name", conditions[0].Message)
}

func TestApplyDeploymentTraitWhileRunningIntegrationDoesSucceed(t *testing.T) {
Expand Down
Loading

0 comments on commit b4549ba

Please sign in to comment.