ref(*): remove protobuf timestamps

pull/3945/head
Adam Reese 6 years ago
parent 6345f04190
commit 91a6ebfed5
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -28,7 +28,6 @@ import (
"k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/chart"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/timeconv"
) )
type releaseInfo struct { type releaseInfo struct {
@ -131,18 +130,20 @@ func getReleaseHistory(rls []*release.Release) (history releaseHistory) {
for i := len(rls) - 1; i >= 0; i-- { for i := len(rls) - 1; i >= 0; i-- {
r := rls[i] r := rls[i]
c := formatChartname(r.Chart) c := formatChartname(r.Chart)
t := timeconv.String(r.Info.LastDeployed)
s := r.Info.Status.Code.String() s := r.Info.Status.Code.String()
v := r.Version v := r.Version
d := r.Info.Description d := r.Info.Description
rInfo := releaseInfo{ rInfo := releaseInfo{
Revision: v, Revision: v,
Updated: t,
Status: s, Status: s,
Chart: c, Chart: c,
Description: d, Description: d,
} }
if !r.Info.LastDeployed.IsZero() {
rInfo.Updated = r.Info.LastDeployed.String()
}
history = append(history, rInfo) history = append(history, rInfo)
} }

@ -45,7 +45,7 @@ func TestHistoryCmd(t *testing.T) {
mk("angry-bird", 2, rpb.Status_SUPERSEDED), mk("angry-bird", 2, rpb.Status_SUPERSEDED),
mk("angry-bird", 1, 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", 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", 4, rpb.Status_DEPLOYED),
mk("angry-bird", 3, rpb.Status_SUPERSEDED), 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", name: "get history with yaml output format",

@ -27,7 +27,6 @@ import (
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/timeconv"
) )
var listHelp = ` var listHelp = `
@ -237,8 +236,8 @@ func formatList(rels []*release.Release, colWidth uint) string {
md := r.Chart.Metadata md := r.Chart.Metadata
c := fmt.Sprintf("%s-%s", md.Name, md.Version) c := fmt.Sprintf("%s-%s", md.Name, md.Version)
t := "-" t := "-"
if tspb := r.Info.LastDeployed; tspb != nil { if tspb := r.Info.LastDeployed; !tspb.IsZero() {
t = timeconv.String(tspb) t = tspb.String()
} }
s := r.Info.Status.Code.String() s := r.Info.Status.Code.String()
v := r.Version v := r.Version

@ -40,7 +40,7 @@ func TestListCmd(t *testing.T) {
rels: []*release.Release{ rels: []*release.Release{
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}), 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", name: "list, one deployed, one failed",

@ -24,7 +24,6 @@ import (
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/timeconv"
) )
var printReleaseTemplate = `REVISION: {{.Release.Version}} var printReleaseTemplate = `REVISION: {{.Release.Version}}
@ -61,7 +60,7 @@ func printRelease(out io.Writer, rel *release.Release) error {
data := map[string]interface{}{ data := map[string]interface{}{
"Release": rel, "Release": rel,
"ComputedValues": cfgStr, "ComputedValues": cfgStr,
"ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC), "ReleaseDate": rel.Info.LastDeployed.Format(time.ANSIC),
} }
return tpl(printReleaseTemplate, data, out) return tpl(printReleaseTemplate, data, out)
} }

@ -31,7 +31,6 @@ import (
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/timeconv"
) )
var statusHelp = ` var statusHelp = `
@ -113,8 +112,8 @@ func (s *statusCmd) run() error {
// PrintStatus prints out the status of a release. Shared because also used by // PrintStatus prints out the status of a release. Shared because also used by
// install / upgrade // install / upgrade
func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) { func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) {
if res.Info.LastDeployed != nil { if !res.Info.LastDeployed.IsZero() {
fmt.Fprintf(out, "LAST DEPLOYED: %s\n", timeconv.String(res.Info.LastDeployed)) fmt.Fprintf(out, "LAST DEPLOYED: %s\n", res.Info.LastDeployed)
} }
fmt.Fprintf(out, "NAMESPACE: %s\n", res.Namespace) fmt.Fprintf(out, "NAMESPACE: %s\n", res.Namespace)
fmt.Fprintf(out, "STATUS: %s\n", res.Info.Status.Code) 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 { if res.Info.Status.LastTestSuiteRun != nil {
lastRun := res.Info.Status.LastTestSuiteRun lastRun := res.Info.Status.LastTestSuiteRun
fmt.Fprintf(out, "TEST SUITE:\n%s\n%s\n\n%s\n", 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 Started: %s", lastRun.StartedAt),
fmt.Sprintf("Last Completed: %s", timeconv.String(lastRun.CompletedAt)), fmt.Sprintf("Last Completed: %s", lastRun.CompletedAt),
formatTestResults(lastRun.Results)) formatTestResults(lastRun.Results))
} }
@ -148,8 +147,8 @@ func formatTestResults(results []*release.TestRun) string {
n := r.Name n := r.Name
s := strutil.PadRight(r.Status.String(), 10, ' ') s := strutil.PadRight(r.Status.String(), 10, ' ')
i := r.Info i := r.Info
ts := timeconv.String(r.StartedAt) ts := r.StartedAt
tc := timeconv.String(r.CompletedAt) tc := r.CompletedAt
tbl.AddRow(n, s, i, ts, tc) tbl.AddRow(n, s, i, ts, tc)
} }
return tbl.String() return tbl.String()

@ -20,26 +20,22 @@ import (
"fmt" "fmt"
"io" "io"
"testing" "testing"
"time"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/timeconv"
) )
var ( var date = time.Unix(242085845, 0)
date = timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
dateString = timeconv.String(&date)
)
func TestStatusCmd(t *testing.T) { func TestStatusCmd(t *testing.T) {
tests := []releaseCase{ tests := []releaseCase{
{ {
name: "get status of a deployed release", name: "get status of a deployed release",
args: []string{"flummoxed-chickadee"}, args: []string{"flummoxed-chickadee"},
expected: outputWithStatus("DEPLOYED\n\n"), expected: outputWithStatus("DEPLOYED"),
rels: []*release.Release{ rels: []*release.Release{
releaseMockWithStatus(&release.Status{ releaseMockWithStatus(&release.Status{
Code: release.Status_DEPLOYED, Code: release.Status_DEPLOYED,
@ -61,7 +57,7 @@ func TestStatusCmd(t *testing.T) {
name: "get status of a deployed release with notes in json", name: "get status of a deployed release with notes in json",
args: []string{"flummoxed-chickadee"}, args: []string{"flummoxed-chickadee"},
flags: []string{"-o", "json"}, 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{ rels: []*release.Release{
releaseMockWithStatus(&release.Status{ releaseMockWithStatus(&release.Status{
Code: release.Status_DEPLOYED, Code: release.Status_DEPLOYED,
@ -96,29 +92,29 @@ func TestStatusCmd(t *testing.T) {
name: "get status of a deployed release with test suite", name: "get status of a deployed release with test suite",
args: []string{"flummoxed-chickadee"}, args: []string{"flummoxed-chickadee"},
expected: outputWithStatus( 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" + "TEST \tSTATUS (.*)\tINFO (.*)\tSTARTED (.*)\tCOMPLETED (.*)\n" +
fmt.Sprintf("test run 1\tSUCCESS (.*)\textra info\t%s\t%s\n", dateString, dateString) + "test run 1\tSUCCESS (.*)\textra info\t(.*)\t(.*)\n" +
fmt.Sprintf("test run 2\tFAILURE (.*)\t (.*)\t%s\t%s\n", dateString, dateString)), "test run 2\tFAILURE (.*)\t (.*)\t(.*)\t(.*)\n"),
rels: []*release.Release{ rels: []*release.Release{
releaseMockWithStatus(&release.Status{ releaseMockWithStatus(&release.Status{
Code: release.Status_DEPLOYED, Code: release.Status_DEPLOYED,
LastTestSuiteRun: &release.TestSuite{ LastTestSuiteRun: &release.TestSuite{
StartedAt: &date, StartedAt: date,
CompletedAt: &date, CompletedAt: date,
Results: []*release.TestRun{ Results: []*release.TestRun{
{ {
Name: "test run 1", Name: "test run 1",
Status: release.TestRun_SUCCESS, Status: release.TestRun_SUCCESS,
Info: "extra info", Info: "extra info",
StartedAt: &date, StartedAt: date,
CompletedAt: &date, CompletedAt: date,
}, },
{ {
Name: "test run 2", Name: "test run 2",
Status: release.TestRun_FAILURE, Status: release.TestRun_FAILURE,
StartedAt: &date, StartedAt: date,
CompletedAt: &date, CompletedAt: date,
}, },
}, },
}, },
@ -134,17 +130,15 @@ func TestStatusCmd(t *testing.T) {
} }
func outputWithStatus(status string) string { func outputWithStatus(status string) string {
return fmt.Sprintf("LAST DEPLOYED: %s\nNAMESPACE: \nSTATUS: %s", return fmt.Sprintf(`LAST DEPLOYED:(.*)\nNAMESPACE: \nSTATUS: %s`, status)
dateString,
status)
} }
func releaseMockWithStatus(status *release.Status) *release.Release { func releaseMockWithStatus(status *release.Status) *release.Release {
return &release.Release{ return &release.Release{
Name: "flummoxed-chickadee", Name: "flummoxed-chickadee",
Info: &release.Info{ Info: &release.Info{
FirstDeployed: &date, FirstDeployed: date,
LastDeployed: &date, LastDeployed: date,
Status: status, Status: status,
}, },
} }

@ -36,7 +36,6 @@ import (
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
util "k8s.io/helm/pkg/releaseutil" util "k8s.io/helm/pkg/releaseutil"
"k8s.io/helm/pkg/tiller" "k8s.io/helm/pkg/tiller"
"k8s.io/helm/pkg/timeconv"
tversion "k8s.io/helm/pkg/version" tversion "k8s.io/helm/pkg/version"
) )
@ -180,7 +179,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
} }
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: t.releaseName, Name: t.releaseName,
Time: timeconv.Now(), Time: time.Now(),
Namespace: t.namespace, Namespace: t.namespace,
} }
@ -252,7 +251,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
Config: config, Config: config,
Version: 1, Version: 1,
Namespace: t.namespace, Namespace: t.namespace,
Info: &release.Info{LastDeployed: timeconv.Timestamp(time.Now())}, Info: &release.Info{LastDeployed: time.Now()},
} }
printRelease(os.Stdout, rel) printRelease(os.Stdout, rel)
} }

@ -23,9 +23,9 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"strings" "strings"
"time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/golang/protobuf/ptypes/timestamp"
"k8s.io/helm/pkg/hapi/chart" "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 // for the composition of the final values struct
type ReleaseOptions struct { type ReleaseOptions struct {
Name string Name string
Time *timestamp.Timestamp Time time.Time
Namespace string Namespace string
IsUpgrade bool IsUpgrade bool
IsInstall bool IsInstall bool

@ -22,13 +22,13 @@ import (
"fmt" "fmt"
"testing" "testing"
"text/template" "text/template"
"time"
"github.com/golang/protobuf/ptypes/any" "github.com/golang/protobuf/ptypes/any"
kversion "k8s.io/apimachinery/pkg/version" kversion "k8s.io/apimachinery/pkg/version"
"k8s.io/helm/pkg/hapi/chart" "k8s.io/helm/pkg/hapi/chart"
"k8s.io/helm/pkg/timeconv"
"k8s.io/helm/pkg/version" "k8s.io/helm/pkg/version"
) )
@ -106,7 +106,7 @@ where:
o := ReleaseOptions{ o := ReleaseOptions{
Name: "Seven Voyages", Name: "Seven Voyages",
Time: timeconv.Now(), Time: time.Now(),
Namespace: "al Basrah", Namespace: "al Basrah",
IsInstall: true, IsInstall: true,
Revision: 5, Revision: 5,

@ -1,6 +1,6 @@
package release package release
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" import "time"
type Hook_Event int32 type Hook_Event int32
@ -80,7 +80,7 @@ type Hook struct {
// Events are the events that this hook fires on. // Events are the events that this hook fires on.
Events []Hook_Event `json:"events,omitempty"` Events []Hook_Event `json:"events,omitempty"`
// LastRun indicates the date/time this was last run. // 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 indicates the sort order for execution among similar Hook type
Weight int32 `json:"weight,omitempty"` Weight int32 `json:"weight,omitempty"`
// DeletePolicies are the policies that indicate when to delete the hook // DeletePolicies are the policies that indicate when to delete the hook

@ -1,14 +1,14 @@
package release package release
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" import "time"
// Info describes release information. // Info describes release information.
type Info struct { type Info struct {
Status *Status `json:"status,omitempty"` Status *Status `json:"status,omitempty"`
FirstDeployed *google_protobuf.Timestamp `json:"first_deployed,omitempty"` FirstDeployed time.Time `json:"first_deployed,omitempty"`
LastDeployed *google_protobuf.Timestamp `json:"last_deployed,omitempty"` LastDeployed time.Time `json:"last_deployed,omitempty"`
// Deleted tracks when this object was deleted. // 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 is human-friendly "log entry" about this release.
Description string `json:"Description,omitempty"` Description string `json:"Description,omitempty"`
} }

@ -1,6 +1,6 @@
package release package release
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" import "time"
type TestRun_Status int32 type TestRun_Status int32
@ -32,6 +32,6 @@ type TestRun struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Status TestRun_Status `json:"status,omitempty"` Status TestRun_Status `json:"status,omitempty"`
Info string `json:"info,omitempty"` Info string `json:"info,omitempty"`
StartedAt *google_protobuf.Timestamp `json:"started_at,omitempty"` StartedAt time.Time `json:"started_at,omitempty"`
CompletedAt *google_protobuf.Timestamp `json:"completed_at,omitempty"` CompletedAt time.Time `json:"completed_at,omitempty"`
} }

@ -1,13 +1,13 @@
package release 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 // TestSuite comprises of the last run of the pre-defined test suite of a release version
type TestSuite struct { type TestSuite struct {
// StartedAt indicates the date/time this test suite was kicked off // 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 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 are the results of each segment of the test
Results []*TestRun `json:"results,omitempty"` Results []*TestRun `json:"results,omitempty"`
} }

@ -21,8 +21,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"sync" "sync"
"time"
"github.com/golang/protobuf/ptypes/timestamp"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/chart" "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. // 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 { func ReleaseMock(opts *MockReleaseOptions) *release.Release {
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} date := time.Unix(242085845, 0)
name := opts.Name name := opts.Name
if name == "" { if name == "" {
@ -226,8 +225,8 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release {
return &release.Release{ return &release.Release{
Name: name, Name: name,
Info: &release.Info{ Info: &release.Info{
FirstDeployed: &date, FirstDeployed: date,
LastDeployed: &date, LastDeployed: date,
Status: &release.Status{Code: scode}, Status: &release.Status{Code: scode},
Description: "Release mock", Description: "Release mock",
}, },
@ -241,7 +240,7 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release {
Kind: "Job", Kind: "Job",
Path: "pre-install-hook.yaml", Path: "pre-install-hook.yaml",
Manifest: MockHookTemplate, Manifest: MockHookTemplate,
LastRun: &date, LastRun: date,
Events: []release.Hook_Event{release.Hook_PRE_INSTALL}, Events: []release.Hook_Event{release.Hook_PRE_INSTALL},
}, },
}, },

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
@ -28,7 +29,6 @@ import (
"k8s.io/helm/pkg/engine" "k8s.io/helm/pkg/engine"
cpb "k8s.io/helm/pkg/hapi/chart" cpb "k8s.io/helm/pkg/hapi/chart"
"k8s.io/helm/pkg/lint/support" "k8s.io/helm/pkg/lint/support"
"k8s.io/helm/pkg/timeconv"
tversion "k8s.io/helm/pkg/version" tversion "k8s.io/helm/pkg/version"
) )
@ -53,7 +53,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b
return return
} }
options := chartutil.ReleaseOptions{Name: "testRelease", Time: timeconv.Now(), Namespace: namespace} options := chartutil.ReleaseOptions{Name: "testRelease", Time: time.Now(), Namespace: namespace}
caps := &chartutil.Capabilities{ caps := &chartutil.Capabilities{
APIVersions: chartutil.DefaultVersionSet, APIVersions: chartutil.DefaultVersionSet,
KubeVersion: chartutil.DefaultKubeVersion, KubeVersion: chartutil.DefaultKubeVersion,

@ -19,21 +19,20 @@ package releasetesting
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/golang/protobuf/ptypes/timestamp"
"k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/hooks" "k8s.io/helm/pkg/hooks"
util "k8s.io/helm/pkg/releaseutil" util "k8s.io/helm/pkg/releaseutil"
"k8s.io/helm/pkg/timeconv"
) )
// TestSuite what tests are run, results, and metadata // TestSuite what tests are run, results, and metadata
type TestSuite struct { type TestSuite struct {
StartedAt *timestamp.Timestamp StartedAt time.Time
CompletedAt *timestamp.Timestamp CompletedAt time.Time
TestManifests []string TestManifests []string
Results []*release.TestRun 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 // Run executes tests in a test suite and stores a result within a given environment
func (ts *TestSuite) Run(env *Environment) error { func (ts *TestSuite) Run(env *Environment) error {
ts.StartedAt = timeconv.Now() ts.StartedAt = time.Now()
if len(ts.TestManifests) == 0 { if len(ts.TestManifests) == 0 {
// TODO: make this better, adding test run status on test suite is weird // 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 return err
} }
test.result.StartedAt = timeconv.Now() test.result.StartedAt = time.Now()
if err := env.streamRunning(test.result.Name); err != nil { if err := env.streamRunning(test.result.Name); err != nil {
return err 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.Results = append(ts.Results, test.result)
} }
ts.CompletedAt = timeconv.Now() ts.CompletedAt = time.Now()
return nil return nil
} }

@ -22,7 +22,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/golang/protobuf/ptypes/timestamp"
"k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
@ -89,10 +88,10 @@ func TestRun(t *testing.T) {
for range ch { // drain for range ch { // drain
} }
if ts.StartedAt == nil { if ts.StartedAt.IsZero() {
t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt) 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) t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt)
} }
if len(ts.Results) != 2 { if len(ts.Results) != 2 {
@ -100,10 +99,10 @@ func TestRun(t *testing.T) {
} }
result := ts.Results[0] 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) 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) t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt)
} }
if result.Name != "finding-nemo" { 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) t.Errorf("Expected test result to be successful, got: %v", result.Status)
} }
result2 := ts.Results[1] 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) 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) t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result2.CompletedAt)
} }
if result2.Name != "gold-rush" { if result2.Name != "gold-rush" {
@ -145,10 +144,10 @@ func TestRunEmptyTestSuite(t *testing.T) {
if msg.Msg != "No Tests Found" { if msg.Msg != "No Tests Found" {
t.Errorf("Expected message 'No Tests Found', Got: %v", msg.Msg) 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) 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) t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt)
} }
if len(ts.Results) != 0 { if len(ts.Results) != 0 {
@ -174,11 +173,11 @@ func TestRunSuccessWithTestFailureHook(t *testing.T) {
for range ch { // drain for range ch { // drain
} }
if ts.StartedAt == nil { if ts.StartedAt.IsZero() {
t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt) 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) 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] 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) 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) 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 { func releaseStub() *release.Release {
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0} date := time.Unix(242085845, 0)
return &release.Release{ return &release.Release{
Name: "lost-fish", Name: "lost-fish",
Info: &release.Info{ Info: &release.Info{
FirstDeployed: &date, FirstDeployed: date,
LastDeployed: &date, LastDeployed: date,
Status: &release.Status{Code: release.Status_DEPLOYED}, Status: &release.Status{Code: release.Status_DEPLOYED},
Description: "a release stub", Description: "a release stub",
}, },

@ -57,8 +57,8 @@ func SortByDate(list []*rspb.Release) {
s := &sorter{list: list} s := &sorter{list: list}
s.less = func(i, j int) bool { s.less = func(i, j int) bool {
ti := s.list[i].Info.LastDeployed.Seconds ti := s.list[i].Info.LastDeployed.Second()
tj := s.list[j].Info.LastDeployed.Seconds tj := s.list[j].Info.LastDeployed.Second()
return ti < tj return ti < tj
} }
sort.Sort(s) sort.Sort(s)

@ -21,7 +21,6 @@ import (
"time" "time"
rspb "k8s.io/helm/pkg/hapi/release" rspb "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/timeconv"
) )
// note: this test data is shared with filter_test.go. // 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 { 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} info := &rspb.Info{Status: &rspb.Status{Code: code}, LastDeployed: tmsp}
return &rspb.Release{ return &rspb.Release{
Name: name, Name: name,
@ -65,8 +64,8 @@ func TestSortByDate(t *testing.T) {
SortByDate(releases) SortByDate(releases)
check(t, "ByDate", func(i, j int) bool { check(t, "ByDate", func(i, j int) bool {
ti := releases[i].Info.LastDeployed.Seconds ti := releases[i].Info.LastDeployed.Second()
tj := releases[j].Info.LastDeployed.Seconds tj := releases[j].Info.LastDeployed.Second()
return ti < tj return ti < tj
}) })
} }

@ -20,13 +20,13 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"strings" "strings"
"time"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/hooks" "k8s.io/helm/pkg/hooks"
relutil "k8s.io/helm/pkg/releaseutil" relutil "k8s.io/helm/pkg/releaseutil"
"k8s.io/helm/pkg/timeconv"
) )
// InstallRelease installs a release and stores the release record. // InstallRelease installs a release and stores the release record.
@ -69,7 +69,7 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas
} }
revision := 1 revision := 1
ts := timeconv.Now() ts := time.Now()
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: name, Name: name,
Time: ts, Time: ts,

@ -270,7 +270,7 @@ func TestInstallRelease_DryRun(t *testing.T) {
t.Fatalf("Expected 1 hook, got %d", l) 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.") 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) t.Errorf("Failed install: %s", err)
} }
if hl := res.Hooks[0].LastRun; hl != nil { if !res.Hooks[0].LastRun.IsZero() {
t.Errorf("Expected that no hooks were run. Got %d", hl) t.Errorf("Expected that no hooks were run. Got %s", res.Hooks[0].LastRun)
} }
} }

@ -19,11 +19,11 @@ package tiller
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"time"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/hooks" "k8s.io/helm/pkg/hooks"
"k8s.io/helm/pkg/timeconv"
) )
// RollbackRelease rolls back to a previous version of the given release. // 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, Config: previousRelease.Config,
Info: &release.Info{ Info: &release.Info{
FirstDeployed: currentRelease.Info.FirstDeployed, FirstDeployed: currentRelease.Info.FirstDeployed,
LastDeployed: timeconv.Now(), LastDeployed: time.Now(),
Status: &release.Status{ Status: &release.Status{
Code: release.Status_PENDING_ROLLBACK, Code: release.Status_PENDING_ROLLBACK,
Notes: previousRelease.Info.Status.Notes, Notes: previousRelease.Info.Status.Notes,

@ -211,8 +211,8 @@ func TestRollbackReleaseNoHooks(t *testing.T) {
t.Fatalf("Failed rollback: %s", err) t.Fatalf("Failed rollback: %s", err)
} }
if hl := res.Hooks[0].LastRun; hl != nil { if hl := res.Hooks[0].LastRun; !hl.IsZero() {
t.Errorf("Expected that no hooks were run. Got %d", hl) t.Errorf("Expected that no hooks were run. Got %s", hl)
} }
} }

@ -24,6 +24,7 @@ import (
"path" "path"
"regexp" "regexp"
"strings" "strings"
"time"
"github.com/technosophos/moniker" "github.com/technosophos/moniker"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -38,7 +39,6 @@ import (
"k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/kube"
relutil "k8s.io/helm/pkg/releaseutil" relutil "k8s.io/helm/pkg/releaseutil"
"k8s.io/helm/pkg/tiller/environment" "k8s.io/helm/pkg/tiller/environment"
"k8s.io/helm/pkg/timeconv"
"k8s.io/helm/pkg/version" "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 { if err := s.deleteHookIfShouldBeDeletedByDeletePolicy(h, hooks.HookSucceeded, name, namespace, hook, s.env.KubeClient); err != nil {
return err return err
} }
h.LastRun = timeconv.Now() h.LastRun = time.Now()
} }
return nil return nil

@ -27,7 +27,6 @@ import (
"time" "time"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/golang/protobuf/ptypes/timestamp"
"k8s.io/client-go/kubernetes/fake" "k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/resource"
@ -223,12 +222,12 @@ func releaseStub() *release.Release {
} }
func namedReleaseStub(name string, status release.Status_Code) *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{ return &release.Release{
Name: name, Name: name,
Info: &release.Info{ Info: &release.Info{
FirstDeployed: &date, FirstDeployed: date,
LastDeployed: &date, LastDeployed: date,
Status: &release.Status{Code: status}, Status: &release.Status{Code: status},
Description: "Named Release Stub", 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 { 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 rel.Info.Status.Code = release.Status_SUPERSEDED
return &release.Release{ return &release.Release{
Name: rel.Name, Name: rel.Name,
Info: &release.Info{ Info: &release.Info{
FirstDeployed: rel.Info.FirstDeployed, FirstDeployed: rel.Info.FirstDeployed,
LastDeployed: &date, LastDeployed: date,
Status: &release.Status{Code: release.Status_DEPLOYED}, Status: &release.Status{Code: release.Status_DEPLOYED},
}, },
Chart: rel.Chart, 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{ return &release.Release{
Name: rlsName, Name: rlsName,
Info: &release.Info{ Info: &release.Info{
FirstDeployed: &date, FirstDeployed: date,
LastDeployed: &date, LastDeployed: date,
Status: &release.Status{Code: release.Status_DEPLOYED}, Status: &release.Status{Code: release.Status_DEPLOYED},
}, },
Chart: ch, Chart: ch,

@ -19,12 +19,12 @@ package tiller
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/hooks" "k8s.io/helm/pkg/hooks"
relutil "k8s.io/helm/pkg/releaseutil" 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. // 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) s.Log("uninstall: Deleting %s", req.Name)
rel.Info.Status.Code = release.Status_DELETING 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)" rel.Info.Description = "Deletion in progress (or silently failed)"
res := &hapi.UninstallReleaseResponse{Release: rel} res := &hapi.UninstallReleaseResponse{Release: rel}

@ -45,12 +45,12 @@ func TestUninstallRelease(t *testing.T) {
t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code) 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.") t.Error("Expected LastRun to be greater than zero.")
} }
if res.Release.Info.Deleted.Seconds <= 0 { if res.Release.Info.Deleted.Second() <= 0 {
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds) t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Second())
} }
if res.Release.Info.Description != "Deletion complete" { 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) t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code)
} }
if res.Release.Info.Deleted.Seconds <= 0 { if res.Release.Info.Deleted.Second() <= 0 {
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds) t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Second())
} }
rels, err := rs.GetHistory(&hapi.GetHistoryRequest{Name: "angry-panda"}) rels, err := rs.GetHistory(&hapi.GetHistoryRequest{Name: "angry-panda"})
if err != nil { if err != nil {
@ -166,7 +166,7 @@ func TestUninstallReleaseNoHooks(t *testing.T) {
} }
// The default value for a protobuf timestamp is nil. // The default value for a protobuf timestamp is nil.
if res.Release.Hooks[0].LastRun != nil { if !res.Release.Hooks[0].LastRun.IsZero() {
t.Errorf("Expected LastRun to be zero, got %d.", res.Release.Hooks[0].LastRun.Seconds) t.Errorf("Expected LastRun to be zero, got %s.", res.Release.Hooks[0].LastRun)
} }
} }

@ -19,12 +19,12 @@ package tiller
import ( import (
"fmt" "fmt"
"strings" "strings"
"time"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/hapi" "k8s.io/helm/pkg/hapi"
"k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/hapi/release"
"k8s.io/helm/pkg/hooks" "k8s.io/helm/pkg/hooks"
"k8s.io/helm/pkg/timeconv"
) )
// UpdateRelease takes an existing release and new information, and upgrades the release. // 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. // the release object.
revision := lastRelease.Version + 1 revision := lastRelease.Version + 1
ts := timeconv.Now() ts := time.Now()
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: req.Name, Name: req.Name,
Time: ts, 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 // From here on out, the release is considered to be in Status_DELETING or Status_DELETED
// state. There is no turning back. // state. There is no turning back.
oldRelease.Info.Status.Code = release.Status_DELETING 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)" oldRelease.Info.Description = "Deletion in progress (or silently failed)"
s.recordRelease(oldRelease, true) s.recordRelease(oldRelease, true)

@ -397,8 +397,8 @@ func TestUpdateReleaseNoHooks(t *testing.T) {
t.Fatalf("Failed updated: %s", err) t.Fatalf("Failed updated: %s", err)
} }
if hl := res.Hooks[0].LastRun; hl != nil { if hl := res.Hooks[0].LastRun; !hl.IsZero() {
t.Errorf("Expected that no hooks were run. Got %d", hl) t.Errorf("Expected that no hooks were run. Got %s", hl)
} }
} }

@ -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"

@ -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 &timestamp.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)
}

@ -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")
}
}
Loading…
Cancel
Save