From 5648d1f43bf8997ffadaeac7e3ca9f156a0d934e Mon Sep 17 00:00:00 2001 From: Scott Cotton Date: Sun, 17 Sep 2023 22:26:39 +0200 Subject: [PATCH] fix ttl presentation for updatedAt (#86) * fix ttl presentation for updatedAt this also consumes a new go-sdk * fix-typo * use checked in updated-at go-sdk --- go.mod | 12 ++++++------ go.sum | 20 ++++++++++---------- internal/command/sandbox/printers.go | 23 +++++++++++++++++++---- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 3e99a1b..c8d2c6d 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/golang/protobuf v1.5.3 github.com/hashicorp/go-multierror v1.1.1 github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 - github.com/signadot/go-sdk v0.3.8-0.20230719152350-64caa01ff9f7 + github.com/signadot/go-sdk v0.3.8-0.20230917202415-61cf5bfada91 github.com/signadot/libconnect v0.1.1-0.20230718181052-aa93718cb097 github.com/spf13/cobra v1.6.0 github.com/spf13/viper v1.11.0 @@ -71,10 +71,10 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect - go.mongodb.org/mongo-driver v1.12.0 // indirect - go.opentelemetry.io/otel v1.16.0 // indirect - go.opentelemetry.io/otel/metric v1.16.0 // indirect - go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.mongodb.org/mongo-driver v1.12.1 // indirect + go.opentelemetry.io/otel v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/trace v1.18.0 // indirect golang.org/x/crypto v0.10.0 // indirect golang.org/x/oauth2 v0.7.0 // indirect golang.org/x/sys v0.9.0 // indirect @@ -100,4 +100,4 @@ require ( // Used for local dev //replace github.com/signadot/libconnect => ../libconnect/ -// replace github.com/signadot/go-sdk => ../go-sdk +//replace github.com/signadot/go-sdk => ../go-sdk diff --git a/go.sum b/go.sum index 124e82a..606500e 100644 --- a/go.sum +++ b/go.sum @@ -330,8 +330,8 @@ github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/signadot/go-sdk v0.3.8-0.20230719152350-64caa01ff9f7 h1:M2wFXW05iOAzCYg2mVePRPDgceXPsqkUVF4ttic5p8Q= -github.com/signadot/go-sdk v0.3.8-0.20230719152350-64caa01ff9f7/go.mod h1:DOBc8nMH/5Wu9pDO7xZK52TRhuh2LqvvNi8eli7BG9A= +github.com/signadot/go-sdk v0.3.8-0.20230917202415-61cf5bfada91 h1:DVxA0GXvgVmrlpUo48xd0SDbcXHLO+KkUHkUFbWfSwg= +github.com/signadot/go-sdk v0.3.8-0.20230917202415-61cf5bfada91/go.mod h1:X86A7rI8J//a2T8aKVCCVXxOMBjh32c2GJ50WK7iYzs= github.com/signadot/libconnect v0.1.1-0.20230718181052-aa93718cb097 h1:sY9WSgiTyDXnhb//DY+n1a6jtYnBfGEgcMTCvr1QpU0= github.com/signadot/libconnect v0.1.1-0.20230718181052-aa93718cb097/go.mod h1:E6ExZIKzVtccOHRZxc11OiDnB0/s6ecSjs8Y+STjWL8= github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -388,21 +388,21 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= -go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE= -go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0= +go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= +go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= -go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= -go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= -go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= +go.opentelemetry.io/otel v1.18.0 h1:TgVozPGZ01nHyDZxK5WGPFB9QexeTMXEH7+tIClWfzs= +go.opentelemetry.io/otel v1.18.0/go.mod h1:9lWqYO0Db579XzVuCKFNPDl4s73Voa+zEck3wHaAYQI= +go.opentelemetry.io/otel/metric v1.18.0 h1:JwVzw94UYmbx3ej++CwLUQZxEODDj/pOuTCvzhtRrSQ= +go.opentelemetry.io/otel/metric v1.18.0/go.mod h1:nNSpsVDjWGfb7chbRLUNW+PBNdcSTHD4Uu5pfFMOI0k= go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= -go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= -go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= +go.opentelemetry.io/otel/trace v1.18.0 h1:NY+czwbHbmndxojTEKiSMHkG2ClNH2PwmcHrdo0JY10= +go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5nS8Mjvzckz+0= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= diff --git a/internal/command/sandbox/printers.go b/internal/command/sandbox/printers.go index ce97903..bac9c51 100644 --- a/internal/command/sandbox/printers.go +++ b/internal/command/sandbox/printers.go @@ -44,6 +44,7 @@ func printSandboxDetails(cfg *config.Sandbox, out io.Writer, sb *models.Sandbox) fmt.Fprintf(tw, "Description:\t%s\n", sb.Spec.Description) fmt.Fprintf(tw, "Cluster:\t%s\n", *sb.Spec.Cluster) fmt.Fprintf(tw, "Created:\t%s\n", formatTimestamp(sb.CreatedAt)) + fmt.Fprintf(tw, "Updated:\t%s\n", formatTimestamp(sb.UpdatedAt)) fmt.Fprintf(tw, "TTL:\t%s\n", formatTTL(sb)) fmt.Fprintf(tw, "Dashboard page:\t%s\n", cfg.SandboxDashboardURL(sb.RoutingKey)) fmt.Fprintf(tw, "Status:\t%s (%s: %s)\n", readiness(sb.Status), sb.Status.Reason, sb.Status.Message) @@ -85,9 +86,23 @@ func formatTTL(sb *models.Sandbox) string { if ttl == nil { return "- (forever)" } - createdAt, err := time.Parse(time.RFC3339, sb.CreatedAt) - if err != nil { - return "?(e parse-created-at)" + var ( + ttlBase time.Time + err error + ) + switch ttl.OffsetFrom { + case "updatedAt": + ttlBase, err = time.Parse(time.RFC3339, sb.UpdatedAt) + if err != nil { + return fmt.Sprintf("?(e parse-updated-at %q)", sb.UpdatedAt) + } + case "createdAt": + ttlBase, err = time.Parse(time.RFC3339, sb.CreatedAt) + if err != nil { + return fmt.Sprintf("?(e parse-created-at %q)", sb.CreatedAt) + } + default: + return fmt.Sprintf("?(bad ttl offset %q)", ttl.OffsetFrom) } n := len(ttl.Duration) count, unit := ttl.Duration[0:n-1], ttl.Duration[n-1:] @@ -109,7 +124,7 @@ func formatTTL(sb *models.Sandbox) string { case "w": offset *= 24 * 7 * time.Hour } - eol := createdAt.Add(offset) + eol := ttlBase.Add(offset) local := eol.Local().Format(time.RFC1123) remaining := eol.Sub(time.Now()) return fmt.Sprintf("%s (%s)", local, units.HumanDuration(remaining))