Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k8s-vcl-reloader
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
uplex-varnish
k8s-vcl-reloader
Commits
09a8dc61
Commit
09a8dc61
authored
Nov 17, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The fully qualified version of a vcl.Spec includes its creation time.
parent
64d7567b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
13 deletions
+29
-13
backends.tmpl
pkg/varnish/vcl/backends.tmpl
+0
-4
spec.go
pkg/varnish/vcl/spec.go
+10
-3
backends.golden
pkg/varnish/vcl/testdata/backends.golden
+0
-4
vcl_test.go
pkg/varnish/vcl/vcl_test.go
+19
-2
No files found.
pkg/varnish/vcl/backends.tmpl
View file @
09a8dc61
...
...
@@ -80,7 +80,3 @@ sub vcl_init {
rr_baz_backends.add_backend({{$name}});
{{- end}}
}
sub set_version {
set resp.http.X-VCL-Version = "{{fqVersion .}}";
}
pkg/varnish/vcl/spec.go
View file @
09a8dc61
...
...
@@ -34,6 +34,11 @@ import (
"hash"
"math/big"
"sort"
"time"
)
const
(
RFC3339Micro
=
"2006-01-02T15:04:05.999999Z07:00"
)
// Meta represents a k8s object's Metadata
...
...
@@ -106,6 +111,8 @@ type Spec struct {
Main
string
// Version is the version string of the VCL config.
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
...
...
@@ -141,8 +148,8 @@ func (spec Spec) DeepHash() string {
}
// FQVersion returns a fully qualified version -- the version string
// appended with the
deep hash of the Spec (since the same VCL version
// may be used with different backend configurations).
// appended with the
creation time of the Spec (since the same VCL
//
version
may be used with different backend configurations).
func
(
spec
Spec
)
FQVersion
()
string
{
return
spec
.
Version
+
"-"
+
spec
.
DeepHash
(
)
return
spec
.
Version
+
"-"
+
spec
.
Created
.
Format
(
RFC3339Micro
)
}
pkg/varnish/vcl/testdata/backends.golden
View file @
09a8dc61
...
...
@@ -80,7 +80,3 @@ sub vcl_init {
new rr_baz_backends = directors.round_robin();
rr_baz_backends.add_backend(baz-5ff49fcd4-hx7lj);
}
sub set_version {
set resp.http.X-VCL-Version = "4.7.11-aspw8srL8xsO5ObnCdofc5hQCMfOvqmySYu6YM";
}
pkg/varnish/vcl/vcl_test.go
View file @
09a8dc61
...
...
@@ -34,7 +34,9 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
func
cmpGold
(
got
[]
byte
,
goldfile
string
)
(
bool
,
error
)
{
...
...
@@ -60,8 +62,9 @@ func TestMain(m *testing.M) {
os
.
Exit
(
code
)
}
var
dfb
Spec
=
Spec
{
var
test
Spec
=
Spec
{
Version
:
"4.7.11"
,
Created
:
time
.
Unix
(
1136239445
,
123456000
),
Services
:
map
[
string
]
Service
{
"bar-service"
:
Service
{
Meta
:
Meta
{
...
...
@@ -141,7 +144,7 @@ var dfbSpec = Spec{
func
TestTemplate
(
t
*
testing
.
T
)
{
var
buf
bytes
.
Buffer
gold
:=
"backends.golden"
if
err
:=
tmpl
.
Execute
(
&
buf
,
dfb
Spec
);
err
!=
nil
{
if
err
:=
tmpl
.
Execute
(
&
buf
,
test
Spec
);
err
!=
nil
{
t
.
Fatal
(
"Execute():"
,
err
)
}
ok
,
err
:=
cmpGold
(
buf
.
Bytes
(),
gold
)
...
...
@@ -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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment