Skip to content

Commit

Permalink
Add time it takes to build a kit in the builder pod log apache#1186
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jun 10, 2020
1 parent 5fb5890 commit 16d8bc9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
8 changes: 8 additions & 0 deletions deploy/crd-integration-kit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ spec:
type: string
description: The IntegrationKit type
JSONPath: .metadata.labels.camel\.apache\.org\/kit\.type
- name: Build Started
type: date
description: The IntegrationKit build start time
JSONPath: .status.buildStartTimestamp
- name: Build Duration
type: string
description: The IntegrationKit build duration time
JSONPath: .status.buildDuration
- name: Image
type: string
description: The IntegrationKit image
Expand Down
8 changes: 4 additions & 4 deletions deploy/resources.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions pkg/apis/camel/v1/integrationkit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ type IntegrationKitStatus struct {
Platform string `json:"platform,omitempty"`
Conditions []IntegrationKitCondition `json:"conditions,omitempty"`
Version string `json:"version,omitempty"`

// startTimestamp is a timestamp representing the server time when this Kit
// creation process has been started
BuildStartTimestamp *metav1.Time `json:"buildStartTimestamp,omitempty"`

// completionTimestamp is a timestamp representing the server time when this Kit
// creation process was/ finished, whether that build failed or succeeded.
BuildCompletionTimestamp *metav1.Time `json:"buildCompletionTimestamp,omitempty"`

// duration contains time.Duration object describing the Kit creation time.
BuildDuration string `json:"buildDuration,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/camel/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/controller/integrationkit/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/pkg/errors"

Expand Down Expand Up @@ -130,6 +131,12 @@ func (action *buildAction) handleBuildRunning(ctx context.Context, kit *v1.Integ
switch build.Status.Phase {
case v1.BuildPhaseRunning:
action.L.Info("Build running")
if kit.Status.BuildStartTimestamp == nil {
kit.Status.BuildStartTimestamp = &metav1.Time{
Time: time.Now(),
}
return kit, err
}
case v1.BuildPhaseSucceeded:
// we should ensure that the integration kit is still in the right phase,
// if not there is a chance that the kit has been modified by the user
Expand Down Expand Up @@ -170,6 +177,11 @@ func (action *buildAction) handleBuildRunning(ctx context.Context, kit *v1.Integ
})
}

kit.Status.BuildCompletionTimestamp = &metav1.Time{Time: time.Now()}
if kit.Status.BuildStartTimestamp != nil {
kit.Status.BuildDuration = kit.Status.BuildCompletionTimestamp.Sub(kit.Status.BuildStartTimestamp.Time).String()
}

return kit, err
case v1.BuildPhaseError, v1.BuildPhaseInterrupted:
// we should ensure that the integration kit is still in the right phase,
Expand All @@ -185,6 +197,10 @@ func (action *buildAction) handleBuildRunning(ctx context.Context, kit *v1.Integ
// Let's copy the build failure to the integration kit status
kit.Status.Failure = build.Status.Failure
kit.Status.Phase = v1.IntegrationKitPhaseError
kit.Status.BuildCompletionTimestamp = &metav1.Time{Time: time.Now()}
if kit.Status.BuildStartTimestamp != nil {
kit.Status.BuildDuration = kit.Status.BuildCompletionTimestamp.Sub(kit.Status.BuildStartTimestamp.Time).String()
}

return kit, nil
}
Expand Down

0 comments on commit 16d8bc9

Please sign in to comment.