Commit 09a8dc61 authored by Geoff Simmons's avatar Geoff Simmons

The fully qualified version of a vcl.Spec includes its creation time.

parent 64d7567b
...@@ -80,7 +80,3 @@ sub vcl_init { ...@@ -80,7 +80,3 @@ sub vcl_init {
rr_baz_backends.add_backend({{$name}}); rr_baz_backends.add_backend({{$name}});
{{- end}} {{- end}}
} }
sub set_version {
set resp.http.X-VCL-Version = "{{fqVersion .}}";
}
...@@ -34,6 +34,11 @@ import ( ...@@ -34,6 +34,11 @@ import (
"hash" "hash"
"math/big" "math/big"
"sort" "sort"
"time"
)
const (
RFC3339Micro = "2006-01-02T15:04:05.999999Z07:00"
) )
// Meta represents a k8s object's Metadata // Meta represents a k8s object's Metadata
...@@ -106,6 +111,8 @@ type Spec struct { ...@@ -106,6 +111,8 @@ type Spec struct {
Main string Main string
// Version is the version string of the VCL config. // Version is the version string of the VCL config.
Version string Version string
// Created is the time at which this Spec was created.
Created time.Time
} }
// DeepHash computes a alphanumerically encoded hash value from a Spec // DeepHash computes a alphanumerically encoded hash value from a Spec
...@@ -141,8 +148,8 @@ func (spec Spec) DeepHash() string { ...@@ -141,8 +148,8 @@ func (spec Spec) DeepHash() string {
} }
// FQVersion returns a fully qualified version -- the version string // FQVersion returns a fully qualified version -- the version string
// appended with the deep hash of the Spec (since the same VCL version // appended with the creation time of the Spec (since the same VCL
// may be used with different backend configurations). // version may be used with different backend configurations).
func (spec Spec) FQVersion() string { func (spec Spec) FQVersion() string {
return spec.Version + "-" + spec.DeepHash() return spec.Version + "-" + spec.Created.Format(RFC3339Micro)
} }
...@@ -80,7 +80,3 @@ sub vcl_init { ...@@ -80,7 +80,3 @@ sub vcl_init {
new rr_baz_backends = directors.round_robin(); new rr_baz_backends = directors.round_robin();
rr_baz_backends.add_backend(baz-5ff49fcd4-hx7lj); rr_baz_backends.add_backend(baz-5ff49fcd4-hx7lj);
} }
sub set_version {
set resp.http.X-VCL-Version = "4.7.11-aspw8srL8xsO5ObnCdofc5hQCMfOvqmySYu6YM";
}
...@@ -34,7 +34,9 @@ import ( ...@@ -34,7 +34,9 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"time"
) )
func cmpGold(got []byte, goldfile string) (bool, error) { func cmpGold(got []byte, goldfile string) (bool, error) {
...@@ -60,8 +62,9 @@ func TestMain(m *testing.M) { ...@@ -60,8 +62,9 @@ func TestMain(m *testing.M) {
os.Exit(code) os.Exit(code)
} }
var dfbSpec = Spec{ var testSpec = Spec{
Version: "4.7.11", Version: "4.7.11",
Created: time.Unix(1136239445, 123456000),
Services: map[string]Service{ Services: map[string]Service{
"bar-service": Service{ "bar-service": Service{
Meta: Meta{ Meta: Meta{
...@@ -141,7 +144,7 @@ var dfbSpec = Spec{ ...@@ -141,7 +144,7 @@ var dfbSpec = Spec{
func TestTemplate(t *testing.T) { func TestTemplate(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
gold := "backends.golden" gold := "backends.golden"
if err := tmpl.Execute(&buf, dfbSpec); err != nil { if err := tmpl.Execute(&buf, testSpec); err != nil {
t.Fatal("Execute():", err) t.Fatal("Execute():", err)
} }
ok, err := cmpGold(buf.Bytes(), gold) ok, err := cmpGold(buf.Bytes(), gold)
...@@ -155,3 +158,17 @@ func TestTemplate(t *testing.T) { ...@@ -155,3 +158,17 @@ func TestTemplate(t *testing.T) {
} }
} }
} }
func TestFQVersion(t *testing.T) {
fqVersion := testSpec.FQVersion()
if !strings.HasPrefix(fqVersion, testSpec.Version + "-") {
t.Fatal("FQVersion(): does not begin with spec.Version + "+
"\"-\":", fqVersion)
}
versionSlice := strings.SplitN(fqVersion, "-", 2)
if created, err := time.Parse(RFC3339Micro, versionSlice[1]); err != nil {
t.Fatal("FQVersion: cannot parse timestamp", err)
} else if testSpec.Created != created {
t.Fatal("FQVersion(): timestamp != Spec.Created", fqVersion)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment