refactor(hooks): replace hook execution Successful bool with HookPhase

Signed-off-by: Jacob LeGrone <git@jacob.work>
pull/6054/head
Jacob LeGrone 5 years ago
parent 047dd5911a
commit 4f6814afb5
No known key found for this signature in database
GPG Key ID: 5FD0852F235368C1

@ -84,16 +84,34 @@ func TestStatusCmd(t *testing.T) {
Status: release.StatusDeployed,
},
&release.Hook{
Name: "foo",
Name: "never-run-test",
Events: []release.HookEvent{release.HookTest},
},
&release.Hook{
Name: "bar",
Name: "passing-test",
Events: []release.HookEvent{release.HookTest},
LastRun: release.HookExecution{
StartedAt: mustParseTime("2006-01-02T15:04:05Z"),
CompletedAt: mustParseTime("2006-01-02T15:04:07Z"),
Successful: true,
Phase: release.HookPhaseSucceeded,
},
},
&release.Hook{
Name: "failing-test",
Events: []release.HookEvent{release.HookTest},
LastRun: release.HookExecution{
StartedAt: mustParseTime("2006-01-02T15:10:05Z"),
CompletedAt: mustParseTime("2006-01-02T15:10:07Z"),
Phase: release.HookPhaseFailed,
},
},
&release.Hook{
Name: "passing-pre-install",
Events: []release.HookEvent{release.HookPreInstall},
LastRun: release.HookExecution{
StartedAt: mustParseTime("2006-01-02T15:00:05Z"),
CompletedAt: mustParseTime("2006-01-02T15:00:07Z"),
Phase: release.HookPhaseSucceeded,
},
},
),

@ -3,8 +3,13 @@ LAST DEPLOYED: 2016-01-16 00:00:00 +0000 UTC
NAMESPACE: default
STATUS: deployed
TEST SUITE: bar
TEST SUITE: passing-test
Last Started: 2006-01-02 15:04:05 +0000 UTC
Last Completed: 2006-01-02 15:04:07 +0000 UTC
Successful: true
Phase: Succeeded
TEST SUITE: failing-test
Last Started: 2006-01-02 15:10:05 +0000 UTC
Last Completed: 2006-01-02 15:10:07 +0000 UTC
Phase: Failed

@ -53,24 +53,28 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
}
// Get the time at which the hook was applied to the cluster
start := time.Now()
err = cfg.KubeClient.WatchUntilReady(resources, timeout)
h.LastRun = release.HookExecution{
StartedAt: start,
CompletedAt: time.Now(),
Successful: err == nil,
StartedAt: time.Now(),
Phase: release.HookPhaseUnknown,
}
// Execute the hook
err = cfg.KubeClient.WatchUntilReady(resources, timeout)
// Note the time of success/failure
h.LastRun.CompletedAt = time.Now()
// Mark hook as succeeded or failed
if err != nil {
// If a hook is failed, checkout the annotation of the hook to determine whether the hook should be deleted
h.LastRun.Phase = release.HookPhaseFailed
// If a hook is failed, check the annotation of the hook to determine whether the hook should be deleted
// under failed condition. If so, then clear the corresponding resource object in the hook
if err := cfg.deleteHookByPolicy(h, release.HookFailed); err != nil {
return err
}
return err
}
h.LastRun.Phase = release.HookPhaseSucceeded
}
// If all hooks are succeeded, checkout the annotation of each hook to determine whether the hook should be deleted
// If all hooks are successful, check the annotation of each hook to determine whether the hook should be deleted
// under succeeded condition. If so, then clear the corresponding resource object in each hook
for _, h := range executingHooks {
if err := cfg.deleteHookByPolicy(h, release.HookSucceeded); err != nil {

@ -57,7 +57,7 @@ func PrintRelease(out io.Writer, rel *release.Release) {
h.Name,
fmt.Sprintf("Last Started: %s", h.LastRun.StartedAt),
fmt.Sprintf("Last Completed: %s", h.LastRun.CompletedAt),
fmt.Sprintf("Successful: %t", h.LastRun.Successful),
fmt.Sprintf("Phase: %s", h.LastRun.Phase),
)
}
}

@ -82,8 +82,23 @@ type Hook struct {
type HookExecution struct {
// StartedAt indicates the date/time this hook was started
StartedAt time.Time `json:"started_at,omitempty"`
// CompletedAt indicates the date/time this hook was completed
// CompletedAt indicates the date/time this hook was completed.
CompletedAt time.Time `json:"completed_at,omitempty"`
// Successful indicates whether the hook completed successfully
Successful bool `json:"successful"`
// Phase indicates whether the hook completed successfully
Phase HookPhase `json:"phase"`
}
// A HookPhase indicates the state of a hook execution
type HookPhase string
const (
// HookPhaseUnknown indicates that a hook is in an unknown state
HookPhaseUnknown HookPhase = "Unknown"
// HookPhaseSucceeded indicates that hook execution succeeded
HookPhaseSucceeded HookPhase = "Succeeded"
// HookPhaseFailed indicates that hook execution failed
HookPhaseFailed HookPhase = "Failed"
)
// Strng converts a hook phase to a printable string
func (x HookPhase) String() string { return string(x) }

@ -32,9 +32,3 @@ type UninstallReleaseResponse struct {
// Info is an uninstall message
Info string `json:"info,omitempty"`
}
// TestReleaseResponse represents a message from executing a test
type TestReleaseResponse struct {
Msg string `json:"msg,omitempty"`
Status TestRunStatus `json:"status,omitempty"`
}

@ -1,41 +0,0 @@
/*
Copyright The Helm Authors.
Licensed 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 release
import "time"
// TestRunStatus is the status of a test run
type TestRunStatus string
// Indicates the results of a test run
const (
TestRunUnknown TestRunStatus = "unknown"
TestRunSuccess TestRunStatus = "success"
TestRunFailure TestRunStatus = "failure"
TestRunRunning TestRunStatus = "running"
)
// Strng converts a test run status to a printable string
func (x TestRunStatus) String() string { return string(x) }
// TestRun describes the run of a test
type TestRun struct {
Name string `json:"name,omitempty"`
Status TestRunStatus `json:"status,omitempty"`
Info string `json:"info,omitempty"`
StartedAt time.Time `json:"started_at,omitempty"`
CompletedAt time.Time `json:"completed_at,omitempty"`
}
Loading…
Cancel
Save