Skip to content

Commit

Permalink
Merge branch 'kloeckner-i-add_additional_varnisch_parameter'
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Jun 17, 2020
2 parents 26256cf + f384c55 commit 7338893
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 31 deletions.
10 changes: 6 additions & 4 deletions cmd/kube-httpcache/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ type KubeHTTPProxyFlags struct {
Port int
}
Varnish struct {
SecretFile string
Storage string
VCLTemplate string
VCLTemplatePoll bool
SecretFile string
Storage string
AdditionalParameters string
VCLTemplate string
VCLTemplatePoll bool
}
}

Expand Down Expand Up @@ -82,6 +83,7 @@ func (f *KubeHTTPProxyFlags) Parse() error {
flag.StringVar(&f.Varnish.SecretFile, "varnish-secret-file", "/etc/varnish/secret", "Varnish secret file")
flag.StringVar(&f.Varnish.Storage, "varnish-storage", "file,/tmp/varnish-data,1G", "varnish storage config")
flag.StringVar(&f.Varnish.VCLTemplate, "varnish-vcl-template", "/etc/varnish/default.vcl.tmpl", "VCL template file")
flag.StringVar(&f.Varnish.AdditionalParameters, "varnish-additional-parameters", "", "Additional Varnish start parameters (-p, seperated by comma), like 'ban_dups=on,cli_timeout=30'")
flag.BoolVar(&f.Varnish.VCLTemplatePoll, "varnish-vcl-template-poll", false, "poll for file changes instead of using inotify (useful on some network filesystems)")

flag.Parse()
Expand Down
1 change: 1 addition & 0 deletions cmd/kube-httpcache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
varnishController, err := controller.NewVarnishController(
opts.Varnish.SecretFile,
opts.Varnish.Storage,
opts.Varnish.AdditionalParameters,
opts.Frontend.Address,
opts.Frontend.Port,
opts.Admin.Address,
Expand Down
27 changes: 21 additions & 6 deletions pkg/controller/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/golang/glog"
"github.com/mittwald/kube-httpcache/pkg/watcher"
Expand Down Expand Up @@ -61,12 +62,7 @@ func (v *VarnishController) startVarnish(ctx context.Context) (*exec.Cmd, <-chan
c := exec.CommandContext(
ctx,
"varnishd",
"-F",
"-f", v.configFile,
"-S", v.SecretFile,
"-s", v.Storage,
"-a", fmt.Sprintf("%s:%d", v.FrontendAddr, v.FrontendPort),
"-T", fmt.Sprintf("%s:%d", v.AdminAddr, v.AdminPort),
v.generateArgs()...,
)

c.Dir = "/"
Expand All @@ -82,3 +78,22 @@ func (v *VarnishController) startVarnish(ctx context.Context) (*exec.Cmd, <-chan

return c, r
}

func (v *VarnishController) generateArgs() []string {
args := []string{
"-F",
"-f", v.configFile,
"-S", v.SecretFile,
"-s", v.Storage,
"-a", fmt.Sprintf("%s:%d", v.FrontendAddr, v.FrontendPort),
"-T", fmt.Sprintf("%s:%d", v.AdminAddr, v.AdminPort),
}

if v.AdditionalParameters != "" {
for _, val := range strings.Split(v.AdditionalParameters, ",") {
args = append(args, "-p")
args = append(args, val)
}
}
return args
}
41 changes: 22 additions & 19 deletions pkg/controller/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ type TemplateData struct {
}

type VarnishController struct {
SecretFile string
Storage string
FrontendAddr string
FrontendPort int
AdminAddr string
AdminPort int
SecretFile string
Storage string
AdditionalParameters string
FrontendAddr string
FrontendPort int
AdminAddr string
AdminPort int

vclTemplate *template.Template
vclTemplateUpdates chan []byte
Expand All @@ -40,6 +41,7 @@ type VarnishController struct {
func NewVarnishController(
secretFile string,
storage string,
additionalParameter string,
frontendAddr string,
frontendPort int,
adminAddr string,
Expand All @@ -66,19 +68,20 @@ func NewVarnishController(
}

return &VarnishController{
SecretFile: secretFile,
Storage: storage,
FrontendAddr: frontendAddr,
FrontendPort: frontendPort,
AdminAddr: adminAddr,
AdminPort: adminPort,
vclTemplate: tmpl,
vclTemplateUpdates: templateUpdates,
frontendUpdates: frontendUpdates,
backendUpdates: backendUpdates,
varnishSignaller: varnishSignaller,
configFile: "/tmp/vcl",
secret: secret,
SecretFile: secretFile,
Storage: storage,
AdditionalParameters: additionalParameter,
FrontendAddr: frontendAddr,
FrontendPort: frontendPort,
AdminAddr: adminAddr,
AdminPort: adminPort,
vclTemplate: tmpl,
vclTemplateUpdates: templateUpdates,
frontendUpdates: frontendUpdates,
backendUpdates: backendUpdates,
varnishSignaller: varnishSignaller,
configFile: "/tmp/vcl",
secret: secret,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/watcher/template_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ func (t *fsnotifyTemplateWatcher) watch(updates chan []byte, errors chan error)

updates <- content
}
}
}
2 changes: 1 addition & 1 deletion pkg/watcher/template_watch_poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ func (t *pollingTemplateWatcher) watch(updates chan []byte, errors chan error) {
updates <- content
}
}
}
}

0 comments on commit 7338893

Please sign in to comment.