From 91a6ebfed577e021a1850709e177df20739b7c66 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 18 Apr 2018 15:35:37 -0700 Subject: [PATCH] ref(*): remove protobuf timestamps --- cmd/helm/history.go | 7 +-- cmd/helm/history_test.go | 4 +- cmd/helm/list.go | 5 +-- cmd/helm/list_test.go | 2 +- cmd/helm/printer.go | 3 +- cmd/helm/status.go | 13 +++--- cmd/helm/status_test.go | 38 +++++++--------- cmd/helm/template.go | 5 +-- pkg/chartutil/values.go | 4 +- pkg/chartutil/values_test.go | 4 +- pkg/hapi/release/hook.go | 4 +- pkg/hapi/release/info.go | 10 ++--- pkg/hapi/release/test_run.go | 12 +++--- pkg/hapi/release/test_suite.go | 6 +-- pkg/helm/fake.go | 11 +++-- pkg/lint/rules/template.go | 4 +- pkg/releasetesting/test_suite.go | 15 +++---- pkg/releasetesting/test_suite_test.go | 31 +++++++------- pkg/releaseutil/sorter.go | 4 +- pkg/releaseutil/sorter_test.go | 7 ++- pkg/tiller/release_install.go | 4 +- pkg/tiller/release_install_test.go | 6 +-- pkg/tiller/release_rollback.go | 4 +- pkg/tiller/release_rollback_test.go | 4 +- pkg/tiller/release_server.go | 4 +- pkg/tiller/release_server_test.go | 17 ++++---- pkg/tiller/release_uninstall.go | 4 +- pkg/tiller/release_uninstall_test.go | 14 +++--- pkg/tiller/release_update.go | 6 +-- pkg/tiller/release_update_test.go | 4 +- pkg/timeconv/doc.go | 23 ---------- pkg/timeconv/timeconv.go | 58 ------------------------- pkg/timeconv/timeconv_test.go | 62 --------------------------- 33 files changed, 121 insertions(+), 278 deletions(-) delete mode 100644 pkg/timeconv/doc.go delete mode 100644 pkg/timeconv/timeconv.go delete mode 100644 pkg/timeconv/timeconv_test.go diff --git a/cmd/helm/history.go b/cmd/helm/history.go index b37cf0989..c51cd7ec3 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -28,7 +28,6 @@ import ( "k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/helm" - "k8s.io/helm/pkg/timeconv" ) type releaseInfo struct { @@ -131,18 +130,20 @@ func getReleaseHistory(rls []*release.Release) (history releaseHistory) { for i := len(rls) - 1; i >= 0; i-- { r := rls[i] c := formatChartname(r.Chart) - t := timeconv.String(r.Info.LastDeployed) s := r.Info.Status.Code.String() v := r.Version d := r.Info.Description rInfo := releaseInfo{ Revision: v, - Updated: t, Status: s, Chart: c, Description: d, } + if !r.Info.LastDeployed.IsZero() { + rInfo.Updated = r.Info.LastDeployed.String() + + } history = append(history, rInfo) } diff --git a/cmd/helm/history_test.go b/cmd/helm/history_test.go index 3be4ffffe..88a49d29b 100644 --- a/cmd/helm/history_test.go +++ b/cmd/helm/history_test.go @@ -45,7 +45,7 @@ func TestHistoryCmd(t *testing.T) { mk("angry-bird", 2, rpb.Status_SUPERSEDED), mk("angry-bird", 1, rpb.Status_SUPERSEDED), }, - expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n1 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n2 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n", + expected: `REVISION\s+UPDATED\s+STATUS\s+CHART\s+DESCRIPTION \n1\s+(.*)\s+SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n2(.*)SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n3(.*)SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n4(.*)DEPLOYED\s+foo-0.1.0-beta.1\s+Release mock\n`, }, { name: "get history with max limit set", @@ -55,7 +55,7 @@ func TestHistoryCmd(t *testing.T) { mk("angry-bird", 4, rpb.Status_DEPLOYED), mk("angry-bird", 3, rpb.Status_SUPERSEDED), }, - expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n", + expected: `REVISION\s+UPDATED\s+STATUS\s+CHART\s+DESCRIPTION \n3\s+(.*)\s+SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n4\s+(.*)\s+DEPLOYED\s+foo-0.1.0-beta.1\s+Release mock\n`, }, { name: "get history with yaml output format", diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 427409fb8..0e0d49c35 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -27,7 +27,6 @@ import ( "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/helm" - "k8s.io/helm/pkg/timeconv" ) var listHelp = ` @@ -237,8 +236,8 @@ func formatList(rels []*release.Release, colWidth uint) string { md := r.Chart.Metadata c := fmt.Sprintf("%s-%s", md.Name, md.Version) t := "-" - if tspb := r.Info.LastDeployed; tspb != nil { - t = timeconv.String(tspb) + if tspb := r.Info.LastDeployed; !tspb.IsZero() { + t = tspb.String() } s := r.Info.Status.Code.String() v := r.Version diff --git a/cmd/helm/list_test.go b/cmd/helm/list_test.go index beb4bc26a..3d5051278 100644 --- a/cmd/helm/list_test.go +++ b/cmd/helm/list_test.go @@ -40,7 +40,7 @@ func TestListCmd(t *testing.T) { rels: []*release.Release{ helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}), }, - expected: "NAME \tREVISION\tUPDATED \tSTATUS \tCHART \tNAMESPACE\natlas\t1 \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\tdefault \n", + expected: `NAME\s+REVISION\s+UPDATED\s+STATUS\s+CHART\s+NAMESPACE\natlas\s+1\s+(.*)\s+DEPLOYED\s+foo-0.1.0-beta.1\s+default`, }, { name: "list, one deployed, one failed", diff --git a/cmd/helm/printer.go b/cmd/helm/printer.go index a13466765..57511b406 100644 --- a/cmd/helm/printer.go +++ b/cmd/helm/printer.go @@ -24,7 +24,6 @@ import ( "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/hapi/release" - "k8s.io/helm/pkg/timeconv" ) var printReleaseTemplate = `REVISION: {{.Release.Version}} @@ -61,7 +60,7 @@ func printRelease(out io.Writer, rel *release.Release) error { data := map[string]interface{}{ "Release": rel, "ComputedValues": cfgStr, - "ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC), + "ReleaseDate": rel.Info.LastDeployed.Format(time.ANSIC), } return tpl(printReleaseTemplate, data, out) } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 066137cbc..ebabff8dd 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -31,7 +31,6 @@ import ( "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/helm" - "k8s.io/helm/pkg/timeconv" ) var statusHelp = ` @@ -113,8 +112,8 @@ func (s *statusCmd) run() error { // PrintStatus prints out the status of a release. Shared because also used by // install / upgrade func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) { - if res.Info.LastDeployed != nil { - fmt.Fprintf(out, "LAST DEPLOYED: %s\n", timeconv.String(res.Info.LastDeployed)) + if !res.Info.LastDeployed.IsZero() { + fmt.Fprintf(out, "LAST DEPLOYED: %s\n", res.Info.LastDeployed) } fmt.Fprintf(out, "NAMESPACE: %s\n", res.Namespace) fmt.Fprintf(out, "STATUS: %s\n", res.Info.Status.Code) @@ -129,8 +128,8 @@ func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) { if res.Info.Status.LastTestSuiteRun != nil { lastRun := res.Info.Status.LastTestSuiteRun fmt.Fprintf(out, "TEST SUITE:\n%s\n%s\n\n%s\n", - fmt.Sprintf("Last Started: %s", timeconv.String(lastRun.StartedAt)), - fmt.Sprintf("Last Completed: %s", timeconv.String(lastRun.CompletedAt)), + fmt.Sprintf("Last Started: %s", lastRun.StartedAt), + fmt.Sprintf("Last Completed: %s", lastRun.CompletedAt), formatTestResults(lastRun.Results)) } @@ -148,8 +147,8 @@ func formatTestResults(results []*release.TestRun) string { n := r.Name s := strutil.PadRight(r.Status.String(), 10, ' ') i := r.Info - ts := timeconv.String(r.StartedAt) - tc := timeconv.String(r.CompletedAt) + ts := r.StartedAt + tc := r.CompletedAt tbl.AddRow(n, s, i, ts, tc) } return tbl.String() diff --git a/cmd/helm/status_test.go b/cmd/helm/status_test.go index a4f3ab151..649cd8f0d 100644 --- a/cmd/helm/status_test.go +++ b/cmd/helm/status_test.go @@ -20,26 +20,22 @@ import ( "fmt" "io" "testing" + "time" - "github.com/golang/protobuf/ptypes/timestamp" "github.com/spf13/cobra" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/helm" - "k8s.io/helm/pkg/timeconv" ) -var ( - date = timestamp.Timestamp{Seconds: 242085845, Nanos: 0} - dateString = timeconv.String(&date) -) +var date = time.Unix(242085845, 0) func TestStatusCmd(t *testing.T) { tests := []releaseCase{ { name: "get status of a deployed release", args: []string{"flummoxed-chickadee"}, - expected: outputWithStatus("DEPLOYED\n\n"), + expected: outputWithStatus("DEPLOYED"), rels: []*release.Release{ releaseMockWithStatus(&release.Status{ Code: release.Status_DEPLOYED, @@ -61,7 +57,7 @@ func TestStatusCmd(t *testing.T) { name: "get status of a deployed release with notes in json", args: []string{"flummoxed-chickadee"}, flags: []string{"-o", "json"}, - expected: `{"name":"flummoxed-chickadee","info":{"status":{"code":1,"notes":"release notes"},"first_deployed":{"seconds":242085845},"last_deployed":{"seconds":242085845}}}`, + expected: `{"name":"flummoxed-chickadee","info":{"status":{"code":1,"notes":"release notes"},"first_deployed":(.*),"last_deployed":(.*)}}`, rels: []*release.Release{ releaseMockWithStatus(&release.Status{ Code: release.Status_DEPLOYED, @@ -96,29 +92,29 @@ func TestStatusCmd(t *testing.T) { name: "get status of a deployed release with test suite", args: []string{"flummoxed-chickadee"}, expected: outputWithStatus( - fmt.Sprintf("DEPLOYED\n\nTEST SUITE:\nLast Started: %s\nLast Completed: %s\n\n", dateString, dateString) + + "DEPLOYED\n\nTEST SUITE:\nLast Started: (.*)\nLast Completed: (.*)\n\n" + "TEST \tSTATUS (.*)\tINFO (.*)\tSTARTED (.*)\tCOMPLETED (.*)\n" + - fmt.Sprintf("test run 1\tSUCCESS (.*)\textra info\t%s\t%s\n", dateString, dateString) + - fmt.Sprintf("test run 2\tFAILURE (.*)\t (.*)\t%s\t%s\n", dateString, dateString)), + "test run 1\tSUCCESS (.*)\textra info\t(.*)\t(.*)\n" + + "test run 2\tFAILURE (.*)\t (.*)\t(.*)\t(.*)\n"), rels: []*release.Release{ releaseMockWithStatus(&release.Status{ Code: release.Status_DEPLOYED, LastTestSuiteRun: &release.TestSuite{ - StartedAt: &date, - CompletedAt: &date, + StartedAt: date, + CompletedAt: date, Results: []*release.TestRun{ { Name: "test run 1", Status: release.TestRun_SUCCESS, Info: "extra info", - StartedAt: &date, - CompletedAt: &date, + StartedAt: date, + CompletedAt: date, }, { Name: "test run 2", Status: release.TestRun_FAILURE, - StartedAt: &date, - CompletedAt: &date, + StartedAt: date, + CompletedAt: date, }, }, }, @@ -134,17 +130,15 @@ func TestStatusCmd(t *testing.T) { } func outputWithStatus(status string) string { - return fmt.Sprintf("LAST DEPLOYED: %s\nNAMESPACE: \nSTATUS: %s", - dateString, - status) + return fmt.Sprintf(`LAST DEPLOYED:(.*)\nNAMESPACE: \nSTATUS: %s`, status) } func releaseMockWithStatus(status *release.Status) *release.Release { return &release.Release{ Name: "flummoxed-chickadee", Info: &release.Info{ - FirstDeployed: &date, - LastDeployed: &date, + FirstDeployed: date, + LastDeployed: date, Status: status, }, } diff --git a/cmd/helm/template.go b/cmd/helm/template.go index 76ea72a69..9b88c52bb 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -36,7 +36,6 @@ import ( "k8s.io/helm/pkg/hapi/release" util "k8s.io/helm/pkg/releaseutil" "k8s.io/helm/pkg/tiller" - "k8s.io/helm/pkg/timeconv" tversion "k8s.io/helm/pkg/version" ) @@ -180,7 +179,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { } options := chartutil.ReleaseOptions{ Name: t.releaseName, - Time: timeconv.Now(), + Time: time.Now(), Namespace: t.namespace, } @@ -252,7 +251,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { Config: config, Version: 1, Namespace: t.namespace, - Info: &release.Info{LastDeployed: timeconv.Timestamp(time.Now())}, + Info: &release.Info{LastDeployed: time.Now()}, } printRelease(os.Stdout, rel) } diff --git a/pkg/chartutil/values.go b/pkg/chartutil/values.go index f0e13a36a..18c5dd14a 100644 --- a/pkg/chartutil/values.go +++ b/pkg/chartutil/values.go @@ -23,9 +23,9 @@ import ( "io/ioutil" "log" "strings" + "time" "github.com/ghodss/yaml" - "github.com/golang/protobuf/ptypes/timestamp" "k8s.io/helm/pkg/hapi/chart" ) @@ -336,7 +336,7 @@ func coalesceTables(dst, src map[string]interface{}) map[string]interface{} { // for the composition of the final values struct type ReleaseOptions struct { Name string - Time *timestamp.Timestamp + Time time.Time Namespace string IsUpgrade bool IsInstall bool diff --git a/pkg/chartutil/values_test.go b/pkg/chartutil/values_test.go index 730ab4659..dede0f00f 100644 --- a/pkg/chartutil/values_test.go +++ b/pkg/chartutil/values_test.go @@ -22,13 +22,13 @@ import ( "fmt" "testing" "text/template" + "time" "github.com/golang/protobuf/ptypes/any" kversion "k8s.io/apimachinery/pkg/version" "k8s.io/helm/pkg/hapi/chart" - "k8s.io/helm/pkg/timeconv" "k8s.io/helm/pkg/version" ) @@ -106,7 +106,7 @@ where: o := ReleaseOptions{ Name: "Seven Voyages", - Time: timeconv.Now(), + Time: time.Now(), Namespace: "al Basrah", IsInstall: true, Revision: 5, diff --git a/pkg/hapi/release/hook.go b/pkg/hapi/release/hook.go index bdfc8edb6..546973fdb 100644 --- a/pkg/hapi/release/hook.go +++ b/pkg/hapi/release/hook.go @@ -1,6 +1,6 @@ package release -import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" +import "time" type Hook_Event int32 @@ -80,7 +80,7 @@ type Hook struct { // Events are the events that this hook fires on. Events []Hook_Event `json:"events,omitempty"` // LastRun indicates the date/time this was last run. - LastRun *google_protobuf.Timestamp `json:"last_run,omitempty"` + LastRun time.Time `json:"last_run,omitempty"` // Weight indicates the sort order for execution among similar Hook type Weight int32 `json:"weight,omitempty"` // DeletePolicies are the policies that indicate when to delete the hook diff --git a/pkg/hapi/release/info.go b/pkg/hapi/release/info.go index 10f947792..8eaa6579c 100644 --- a/pkg/hapi/release/info.go +++ b/pkg/hapi/release/info.go @@ -1,14 +1,14 @@ package release -import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" +import "time" // Info describes release information. type Info struct { - Status *Status `json:"status,omitempty"` - FirstDeployed *google_protobuf.Timestamp `json:"first_deployed,omitempty"` - LastDeployed *google_protobuf.Timestamp `json:"last_deployed,omitempty"` + Status *Status `json:"status,omitempty"` + FirstDeployed time.Time `json:"first_deployed,omitempty"` + LastDeployed time.Time `json:"last_deployed,omitempty"` // Deleted tracks when this object was deleted. - Deleted *google_protobuf.Timestamp `json:"deleted,omitempty"` + Deleted time.Time `json:"deleted,omitempty"` // Description is human-friendly "log entry" about this release. Description string `json:"Description,omitempty"` } diff --git a/pkg/hapi/release/test_run.go b/pkg/hapi/release/test_run.go index 5a804e0b6..126560bd5 100644 --- a/pkg/hapi/release/test_run.go +++ b/pkg/hapi/release/test_run.go @@ -1,6 +1,6 @@ package release -import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" +import "time" type TestRun_Status int32 @@ -29,9 +29,9 @@ func (x TestRun_Status) String() string { } type TestRun struct { - Name string `json:"name,omitempty"` - Status TestRun_Status `json:"status,omitempty"` - Info string `json:"info,omitempty"` - StartedAt *google_protobuf.Timestamp `json:"started_at,omitempty"` - CompletedAt *google_protobuf.Timestamp `json:"completed_at,omitempty"` + Name string `json:"name,omitempty"` + Status TestRun_Status `json:"status,omitempty"` + Info string `json:"info,omitempty"` + StartedAt time.Time `json:"started_at,omitempty"` + CompletedAt time.Time `json:"completed_at,omitempty"` } diff --git a/pkg/hapi/release/test_suite.go b/pkg/hapi/release/test_suite.go index bf4b33ea9..1567f560b 100644 --- a/pkg/hapi/release/test_suite.go +++ b/pkg/hapi/release/test_suite.go @@ -1,13 +1,13 @@ package release -import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" +import "time" // TestSuite comprises of the last run of the pre-defined test suite of a release version type TestSuite struct { // StartedAt indicates the date/time this test suite was kicked off - StartedAt *google_protobuf.Timestamp `json:"started_at,omitempty"` + StartedAt time.Time `json:"started_at,omitempty"` // CompletedAt indicates the date/time this test suite was completed - CompletedAt *google_protobuf.Timestamp `json:"completed_at,omitempty"` + CompletedAt time.Time `json:"completed_at,omitempty"` // Results are the results of each segment of the test Results []*TestRun `json:"results,omitempty"` } diff --git a/pkg/helm/fake.go b/pkg/helm/fake.go index 08b017fa2..a84c9464d 100644 --- a/pkg/helm/fake.go +++ b/pkg/helm/fake.go @@ -21,8 +21,7 @@ import ( "fmt" "math/rand" "sync" - - "github.com/golang/protobuf/ptypes/timestamp" + "time" "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/chart" @@ -188,7 +187,7 @@ type MockReleaseOptions struct { // ReleaseMock creates a mock release object based on options set by MockReleaseOptions. This function should typically not be used outside of testing. func ReleaseMock(opts *MockReleaseOptions) *release.Release { - date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} + date := time.Unix(242085845, 0) name := opts.Name if name == "" { @@ -226,8 +225,8 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release { return &release.Release{ Name: name, Info: &release.Info{ - FirstDeployed: &date, - LastDeployed: &date, + FirstDeployed: date, + LastDeployed: date, Status: &release.Status{Code: scode}, Description: "Release mock", }, @@ -241,7 +240,7 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release { Kind: "Job", Path: "pre-install-hook.yaml", Manifest: MockHookTemplate, - LastRun: &date, + LastRun: date, Events: []release.Hook_Event{release.Hook_PRE_INSTALL}, }, }, diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 4b6bbae4e..e08c99fbd 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "path/filepath" + "time" "github.com/ghodss/yaml" @@ -28,7 +29,6 @@ import ( "k8s.io/helm/pkg/engine" cpb "k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/lint/support" - "k8s.io/helm/pkg/timeconv" tversion "k8s.io/helm/pkg/version" ) @@ -53,7 +53,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b return } - options := chartutil.ReleaseOptions{Name: "testRelease", Time: timeconv.Now(), Namespace: namespace} + options := chartutil.ReleaseOptions{Name: "testRelease", Time: time.Now(), Namespace: namespace} caps := &chartutil.Capabilities{ APIVersions: chartutil.DefaultVersionSet, KubeVersion: chartutil.DefaultKubeVersion, diff --git a/pkg/releasetesting/test_suite.go b/pkg/releasetesting/test_suite.go index b12a4a315..3e8160c16 100644 --- a/pkg/releasetesting/test_suite.go +++ b/pkg/releasetesting/test_suite.go @@ -19,21 +19,20 @@ package releasetesting import ( "fmt" "strings" + "time" "github.com/ghodss/yaml" - "github.com/golang/protobuf/ptypes/timestamp" "k8s.io/kubernetes/pkg/apis/core" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hooks" util "k8s.io/helm/pkg/releaseutil" - "k8s.io/helm/pkg/timeconv" ) // TestSuite what tests are run, results, and metadata type TestSuite struct { - StartedAt *timestamp.Timestamp - CompletedAt *timestamp.Timestamp + StartedAt time.Time + CompletedAt time.Time TestManifests []string Results []*release.TestRun } @@ -55,7 +54,7 @@ func NewTestSuite(rel *release.Release) *TestSuite { // Run executes tests in a test suite and stores a result within a given environment func (ts *TestSuite) Run(env *Environment) error { - ts.StartedAt = timeconv.Now() + ts.StartedAt = time.Now() if len(ts.TestManifests) == 0 { // TODO: make this better, adding test run status on test suite is weird @@ -68,7 +67,7 @@ func (ts *TestSuite) Run(env *Environment) error { return err } - test.result.StartedAt = timeconv.Now() + test.result.StartedAt = time.Now() if err := env.streamRunning(test.result.Name); err != nil { return err } @@ -104,11 +103,11 @@ func (ts *TestSuite) Run(env *Environment) error { } } - test.result.CompletedAt = timeconv.Now() + test.result.CompletedAt = time.Now() ts.Results = append(ts.Results, test.result) } - ts.CompletedAt = timeconv.Now() + ts.CompletedAt = time.Now() return nil } diff --git a/pkg/releasetesting/test_suite_test.go b/pkg/releasetesting/test_suite_test.go index a87e742f4..324c8afa2 100644 --- a/pkg/releasetesting/test_suite_test.go +++ b/pkg/releasetesting/test_suite_test.go @@ -22,7 +22,6 @@ import ( "testing" "time" - "github.com/golang/protobuf/ptypes/timestamp" "k8s.io/kubernetes/pkg/apis/core" "k8s.io/helm/pkg/hapi" @@ -89,10 +88,10 @@ func TestRun(t *testing.T) { for range ch { // drain } - if ts.StartedAt == nil { + if ts.StartedAt.IsZero() { t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt) } - if ts.CompletedAt == nil { + if ts.CompletedAt.IsZero() { t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt) } if len(ts.Results) != 2 { @@ -100,10 +99,10 @@ func TestRun(t *testing.T) { } result := ts.Results[0] - if result.StartedAt == nil { + if result.StartedAt.IsZero() { t.Errorf("Expected test StartedAt to not be nil. Got: %v", result.StartedAt) } - if result.CompletedAt == nil { + if result.CompletedAt.IsZero() { t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt) } if result.Name != "finding-nemo" { @@ -113,10 +112,10 @@ func TestRun(t *testing.T) { t.Errorf("Expected test result to be successful, got: %v", result.Status) } result2 := ts.Results[1] - if result2.StartedAt == nil { + if result2.StartedAt.IsZero() { t.Errorf("Expected test StartedAt to not be nil. Got: %v", result2.StartedAt) } - if result2.CompletedAt == nil { + if result2.CompletedAt.IsZero() { t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result2.CompletedAt) } if result2.Name != "gold-rush" { @@ -145,10 +144,10 @@ func TestRunEmptyTestSuite(t *testing.T) { if msg.Msg != "No Tests Found" { t.Errorf("Expected message 'No Tests Found', Got: %v", msg.Msg) } - if ts.StartedAt == nil { + if ts.StartedAt.IsZero() { t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt) } - if ts.CompletedAt == nil { + if ts.CompletedAt.IsZero() { t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt) } if len(ts.Results) != 0 { @@ -174,11 +173,11 @@ func TestRunSuccessWithTestFailureHook(t *testing.T) { for range ch { // drain } - if ts.StartedAt == nil { + if ts.StartedAt.IsZero() { t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt) } - if ts.CompletedAt == nil { + if ts.CompletedAt.IsZero() { t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt) } @@ -187,11 +186,11 @@ func TestRunSuccessWithTestFailureHook(t *testing.T) { } result := ts.Results[0] - if result.StartedAt == nil { + if result.StartedAt.IsZero() { t.Errorf("Expected test StartedAt to not be nil. Got: %v", result.StartedAt) } - if result.CompletedAt == nil { + if result.CompletedAt.IsZero() { t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt) } @@ -226,12 +225,12 @@ func chartStub() *chart.Chart { } func releaseStub() *release.Release { - date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} + date := time.Unix(242085845, 0) return &release.Release{ Name: "lost-fish", Info: &release.Info{ - FirstDeployed: &date, - LastDeployed: &date, + FirstDeployed: date, + LastDeployed: date, Status: &release.Status{Code: release.Status_DEPLOYED}, Description: "a release stub", }, diff --git a/pkg/releaseutil/sorter.go b/pkg/releaseutil/sorter.go index 482c52686..cd90e5816 100644 --- a/pkg/releaseutil/sorter.go +++ b/pkg/releaseutil/sorter.go @@ -57,8 +57,8 @@ func SortByDate(list []*rspb.Release) { s := &sorter{list: list} s.less = func(i, j int) bool { - ti := s.list[i].Info.LastDeployed.Seconds - tj := s.list[j].Info.LastDeployed.Seconds + ti := s.list[i].Info.LastDeployed.Second() + tj := s.list[j].Info.LastDeployed.Second() return ti < tj } sort.Sort(s) diff --git a/pkg/releaseutil/sorter_test.go b/pkg/releaseutil/sorter_test.go index a028e67e8..2b48a2e5c 100644 --- a/pkg/releaseutil/sorter_test.go +++ b/pkg/releaseutil/sorter_test.go @@ -21,7 +21,6 @@ import ( "time" rspb "k8s.io/helm/pkg/hapi/release" - "k8s.io/helm/pkg/timeconv" ) // note: this test data is shared with filter_test.go. @@ -34,7 +33,7 @@ var releases = []*rspb.Release{ } func tsRelease(name string, vers int32, dur time.Duration, code rspb.Status_Code) *rspb.Release { - tmsp := timeconv.Timestamp(time.Now().Add(time.Duration(dur))) + tmsp := time.Now().Add(time.Duration(dur)) info := &rspb.Info{Status: &rspb.Status{Code: code}, LastDeployed: tmsp} return &rspb.Release{ Name: name, @@ -65,8 +64,8 @@ func TestSortByDate(t *testing.T) { SortByDate(releases) check(t, "ByDate", func(i, j int) bool { - ti := releases[i].Info.LastDeployed.Seconds - tj := releases[j].Info.LastDeployed.Seconds + ti := releases[i].Info.LastDeployed.Second() + tj := releases[j].Info.LastDeployed.Second() return ti < tj }) } diff --git a/pkg/tiller/release_install.go b/pkg/tiller/release_install.go index 43cb67ae6..d4ae89a66 100644 --- a/pkg/tiller/release_install.go +++ b/pkg/tiller/release_install.go @@ -20,13 +20,13 @@ import ( "bytes" "fmt" "strings" + "time" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hooks" relutil "k8s.io/helm/pkg/releaseutil" - "k8s.io/helm/pkg/timeconv" ) // InstallRelease installs a release and stores the release record. @@ -69,7 +69,7 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas } revision := 1 - ts := timeconv.Now() + ts := time.Now() options := chartutil.ReleaseOptions{ Name: name, Time: ts, diff --git a/pkg/tiller/release_install_test.go b/pkg/tiller/release_install_test.go index 01e81a2ff..02803966d 100644 --- a/pkg/tiller/release_install_test.go +++ b/pkg/tiller/release_install_test.go @@ -270,7 +270,7 @@ func TestInstallRelease_DryRun(t *testing.T) { t.Fatalf("Expected 1 hook, got %d", l) } - if res.Hooks[0].LastRun != nil { + if !res.Hooks[0].LastRun.IsZero() { t.Error("Expected hook to not be marked as run.") } @@ -289,8 +289,8 @@ func TestInstallRelease_NoHooks(t *testing.T) { t.Errorf("Failed install: %s", err) } - if hl := res.Hooks[0].LastRun; hl != nil { - t.Errorf("Expected that no hooks were run. Got %d", hl) + if !res.Hooks[0].LastRun.IsZero() { + t.Errorf("Expected that no hooks were run. Got %s", res.Hooks[0].LastRun) } } diff --git a/pkg/tiller/release_rollback.go b/pkg/tiller/release_rollback.go index 38fb328f5..6084dc074 100644 --- a/pkg/tiller/release_rollback.go +++ b/pkg/tiller/release_rollback.go @@ -19,11 +19,11 @@ package tiller import ( "bytes" "fmt" + "time" "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hooks" - "k8s.io/helm/pkg/timeconv" ) // RollbackRelease rolls back to a previous version of the given release. @@ -93,7 +93,7 @@ func (s *ReleaseServer) prepareRollback(req *hapi.RollbackReleaseRequest) (*rele Config: previousRelease.Config, Info: &release.Info{ FirstDeployed: currentRelease.Info.FirstDeployed, - LastDeployed: timeconv.Now(), + LastDeployed: time.Now(), Status: &release.Status{ Code: release.Status_PENDING_ROLLBACK, Notes: previousRelease.Info.Status.Notes, diff --git a/pkg/tiller/release_rollback_test.go b/pkg/tiller/release_rollback_test.go index 0f12ef8e3..e7db8a154 100644 --- a/pkg/tiller/release_rollback_test.go +++ b/pkg/tiller/release_rollback_test.go @@ -211,8 +211,8 @@ func TestRollbackReleaseNoHooks(t *testing.T) { t.Fatalf("Failed rollback: %s", err) } - if hl := res.Hooks[0].LastRun; hl != nil { - t.Errorf("Expected that no hooks were run. Got %d", hl) + if hl := res.Hooks[0].LastRun; !hl.IsZero() { + t.Errorf("Expected that no hooks were run. Got %s", hl) } } diff --git a/pkg/tiller/release_server.go b/pkg/tiller/release_server.go index 4f1c9c9b5..a5f2b2cdd 100644 --- a/pkg/tiller/release_server.go +++ b/pkg/tiller/release_server.go @@ -24,6 +24,7 @@ import ( "path" "regexp" "strings" + "time" "github.com/technosophos/moniker" "gopkg.in/yaml.v2" @@ -38,7 +39,6 @@ import ( "k8s.io/helm/pkg/kube" relutil "k8s.io/helm/pkg/releaseutil" "k8s.io/helm/pkg/tiller/environment" - "k8s.io/helm/pkg/timeconv" "k8s.io/helm/pkg/version" ) @@ -383,7 +383,7 @@ func (s *ReleaseServer) execHook(hs []*release.Hook, name, namespace, hook strin if err := s.deleteHookIfShouldBeDeletedByDeletePolicy(h, hooks.HookSucceeded, name, namespace, hook, s.env.KubeClient); err != nil { return err } - h.LastRun = timeconv.Now() + h.LastRun = time.Now() } return nil diff --git a/pkg/tiller/release_server_test.go b/pkg/tiller/release_server_test.go index 1c7188e51..20baf40b4 100644 --- a/pkg/tiller/release_server_test.go +++ b/pkg/tiller/release_server_test.go @@ -27,7 +27,6 @@ import ( "time" "github.com/ghodss/yaml" - "github.com/golang/protobuf/ptypes/timestamp" "k8s.io/client-go/kubernetes/fake" "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/kubectl/resource" @@ -223,12 +222,12 @@ func releaseStub() *release.Release { } func namedReleaseStub(name string, status release.Status_Code) *release.Release { - date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} + date := time.Unix(242085845, 0) return &release.Release{ Name: name, Info: &release.Info{ - FirstDeployed: &date, - LastDeployed: &date, + FirstDeployed: date, + LastDeployed: date, Status: &release.Status{Code: status}, Description: "Named Release Stub", }, @@ -260,14 +259,14 @@ func namedReleaseStub(name string, status release.Status_Code) *release.Release } func upgradeReleaseVersion(rel *release.Release) *release.Release { - date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} + date := time.Unix(242085845, 0) rel.Info.Status.Code = release.Status_SUPERSEDED return &release.Release{ Name: rel.Name, Info: &release.Info{ FirstDeployed: rel.Info.FirstDeployed, - LastDeployed: &date, + LastDeployed: date, Status: &release.Status{Code: release.Status_DEPLOYED}, }, Chart: rel.Chart, @@ -367,12 +366,12 @@ func releaseWithKeepStub(rlsName string) *release.Release { }, } - date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} + date := time.Unix(242085845, 0) return &release.Release{ Name: rlsName, Info: &release.Info{ - FirstDeployed: &date, - LastDeployed: &date, + FirstDeployed: date, + LastDeployed: date, Status: &release.Status{Code: release.Status_DEPLOYED}, }, Chart: ch, diff --git a/pkg/tiller/release_uninstall.go b/pkg/tiller/release_uninstall.go index b5cbf8314..2cb9f1123 100644 --- a/pkg/tiller/release_uninstall.go +++ b/pkg/tiller/release_uninstall.go @@ -19,12 +19,12 @@ package tiller import ( "fmt" "strings" + "time" "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hooks" relutil "k8s.io/helm/pkg/releaseutil" - "k8s.io/helm/pkg/timeconv" ) // UninstallRelease deletes all of the resources associated with this release, and marks the release DELETED. @@ -61,7 +61,7 @@ func (s *ReleaseServer) UninstallRelease(req *hapi.UninstallReleaseRequest) (*ha s.Log("uninstall: Deleting %s", req.Name) rel.Info.Status.Code = release.Status_DELETING - rel.Info.Deleted = timeconv.Now() + rel.Info.Deleted = time.Now() rel.Info.Description = "Deletion in progress (or silently failed)" res := &hapi.UninstallReleaseResponse{Release: rel} diff --git a/pkg/tiller/release_uninstall_test.go b/pkg/tiller/release_uninstall_test.go index 1986855b2..4bc226273 100644 --- a/pkg/tiller/release_uninstall_test.go +++ b/pkg/tiller/release_uninstall_test.go @@ -45,12 +45,12 @@ func TestUninstallRelease(t *testing.T) { t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code) } - if res.Release.Hooks[0].LastRun.Seconds == 0 { + if res.Release.Hooks[0].LastRun.IsZero() { t.Error("Expected LastRun to be greater than zero.") } - if res.Release.Info.Deleted.Seconds <= 0 { - t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds) + if res.Release.Info.Deleted.Second() <= 0 { + t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Second()) } if res.Release.Info.Description != "Deletion complete" { @@ -84,8 +84,8 @@ func TestUninstallPurgeRelease(t *testing.T) { t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code) } - if res.Release.Info.Deleted.Seconds <= 0 { - t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds) + if res.Release.Info.Deleted.Second() <= 0 { + t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Second()) } rels, err := rs.GetHistory(&hapi.GetHistoryRequest{Name: "angry-panda"}) if err != nil { @@ -166,7 +166,7 @@ func TestUninstallReleaseNoHooks(t *testing.T) { } // The default value for a protobuf timestamp is nil. - if res.Release.Hooks[0].LastRun != nil { - t.Errorf("Expected LastRun to be zero, got %d.", res.Release.Hooks[0].LastRun.Seconds) + if !res.Release.Hooks[0].LastRun.IsZero() { + t.Errorf("Expected LastRun to be zero, got %s.", res.Release.Hooks[0].LastRun) } } diff --git a/pkg/tiller/release_update.go b/pkg/tiller/release_update.go index 12bfb3f9c..41d2d4007 100644 --- a/pkg/tiller/release_update.go +++ b/pkg/tiller/release_update.go @@ -19,12 +19,12 @@ package tiller import ( "fmt" "strings" + "time" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hooks" - "k8s.io/helm/pkg/timeconv" ) // UpdateRelease takes an existing release and new information, and upgrades the release. @@ -93,7 +93,7 @@ func (s *ReleaseServer) prepareUpdate(req *hapi.UpdateReleaseRequest) (*release. // the release object. revision := lastRelease.Version + 1 - ts := timeconv.Now() + ts := time.Now() options := chartutil.ReleaseOptions{ Name: req.Name, Time: ts, @@ -172,7 +172,7 @@ func (s *ReleaseServer) performUpdateForce(req *hapi.UpdateReleaseRequest) (*rel // From here on out, the release is considered to be in Status_DELETING or Status_DELETED // state. There is no turning back. oldRelease.Info.Status.Code = release.Status_DELETING - oldRelease.Info.Deleted = timeconv.Now() + oldRelease.Info.Deleted = time.Now() oldRelease.Info.Description = "Deletion in progress (or silently failed)" s.recordRelease(oldRelease, true) diff --git a/pkg/tiller/release_update_test.go b/pkg/tiller/release_update_test.go index a8ae94ad1..aafa0912b 100644 --- a/pkg/tiller/release_update_test.go +++ b/pkg/tiller/release_update_test.go @@ -397,8 +397,8 @@ func TestUpdateReleaseNoHooks(t *testing.T) { t.Fatalf("Failed updated: %s", err) } - if hl := res.Hooks[0].LastRun; hl != nil { - t.Errorf("Expected that no hooks were run. Got %d", hl) + if hl := res.Hooks[0].LastRun; !hl.IsZero() { + t.Errorf("Expected that no hooks were run. Got %s", hl) } } diff --git a/pkg/timeconv/doc.go b/pkg/timeconv/doc.go deleted file mode 100644 index 235167391..000000000 --- a/pkg/timeconv/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors All rights reserved. - -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 timeconv contains utilities for converting time. - -The gRPC/Protobuf libraries contain time implementations that require conversion -to and from Go times. This library provides utilities and convenience functions -for performing conversions. -*/ -package timeconv // import "k8s.io/helm/pkg/timeconv" diff --git a/pkg/timeconv/timeconv.go b/pkg/timeconv/timeconv.go deleted file mode 100644 index 24ff10f4e..000000000 --- a/pkg/timeconv/timeconv.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors All rights reserved. - -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 timeconv - -import ( - "time" - - "github.com/golang/protobuf/ptypes/timestamp" -) - -// Now creates a timestamp.Timestamp representing the current time. -func Now() *timestamp.Timestamp { - return Timestamp(time.Now()) -} - -// Timestamp converts a time.Time to a protobuf *timestamp.Timestamp. -func Timestamp(t time.Time) *timestamp.Timestamp { - return ×tamp.Timestamp{ - Seconds: t.Unix(), - Nanos: int32(t.Nanosecond()), - } -} - -// Time converts a protobuf *timestamp.Timestamp to a time.Time. -func Time(ts *timestamp.Timestamp) time.Time { - return time.Unix(ts.Seconds, int64(ts.Nanos)) -} - -// Format formats a *timestamp.Timestamp into a string. -// -// This follows the rules for time.Time.Format(). -func Format(ts *timestamp.Timestamp, layout string) string { - return Time(ts).Format(layout) -} - -// String formats the timestamp into a user-friendly string. -// -// Currently, this uses the 'time.ANSIC' format string, but there is no guarantee -// that this will not change. -// -// This is a convenience function for formatting timestamps for user display. -func String(ts *timestamp.Timestamp) string { - return Format(ts, time.ANSIC) -} diff --git a/pkg/timeconv/timeconv_test.go b/pkg/timeconv/timeconv_test.go deleted file mode 100644 index f673df3c9..000000000 --- a/pkg/timeconv/timeconv_test.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors All rights reserved. - -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 timeconv - -import ( - "testing" - "time" -) - -func TestNow(t *testing.T) { - now := time.Now() - ts := Now() - var drift int64 = 5 - if ts.Seconds < int64(now.Second())-drift { - t.Errorf("Unexpected time drift: %d", ts.Seconds) - } -} - -func TestTimestamp(t *testing.T) { - now := time.Now() - ts := Timestamp(now) - - if now.Unix() != ts.Seconds { - t.Errorf("Unexpected time drift: %d to %d", now.Second(), ts.Seconds) - } - - if now.Nanosecond() != int(ts.Nanos) { - t.Errorf("Unexpected nano drift: %d to %d", now.Nanosecond(), ts.Nanos) - } -} - -func TestTime(t *testing.T) { - nowts := Now() - now := Time(nowts) - - if now.Unix() != nowts.Seconds { - t.Errorf("Unexpected time drift %d", now.Unix()) - } -} - -func TestFormat(t *testing.T) { - now := time.Now() - nowts := Timestamp(now) - - if now.Format(time.ANSIC) != Format(nowts, time.ANSIC) { - t.Error("Format mismatch") - } -}