Skip to content

Commit

Permalink
Allow setting additional listen addresses (-a options). The operator …
Browse files Browse the repository at this point in the history
…still ensures that Varnish listens on port 6081 since the service expects that port. But all other -a options will be respected and appended. (#76)

Signed-off-by: Tomash Sidei <tomash.sidei@ibm.com>
  • Loading branch information
tomashibm authored Aug 17, 2022
1 parent deb1751 commit b37c3db
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
1 change: 0 additions & 1 deletion api/v1alpha1/varnishcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func SetWebhookLogger(l *logger.Logger) {
var (
varnishArgsKeyRegexp = regexp.MustCompile(`^-\w$`)
disallowedVarnishArgs = map[string]bool{
"-a": true,
"-f": true,
"-F": true,
"-n": true,
Expand Down
13 changes: 12 additions & 1 deletion api/v1alpha1/varnishcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ func TestValidatingWebhook(t *testing.T) {
},
valid: true,
},
{
name: "Additional listen addresses should be allowed",
vc: &VarnishCluster{
Spec: VarnishClusterSpec{
Varnish: &VarnishClusterVarnish{
Args: []string{"-a", ":8080,PROXY"},
},
},
},
valid: true,
},
{
name: "Invalid values",
vc: &VarnishCluster{
Expand Down Expand Up @@ -59,7 +70,7 @@ func TestValidatingWebhook(t *testing.T) {
vc: &VarnishCluster{
Spec: VarnishClusterSpec{
Varnish: &VarnishClusterVarnish{
Args: []string{"-a", "-f", "-F", "-n", "-S"},
Args: []string{"-f", "-F", "-n", "-S"},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (
func getSanitizedVarnishArgs(spec *vcapi.VarnishClusterSpec) []string {
varnishArgsOverrides := [][]string{
{"-F"},
{"-a", fmt.Sprintf("0.0.0.0:%d", vcapi.VarnishPort)},
{"-S", "/etc/varnish-secret/secret"},
{"-b", "127.0.0.1:0"}, //start a varnishd without predefined backend. It has to be overridden by settings from ConfigMap
{"-T", fmt.Sprintf("0.0.0.0:%d", vcapi.VarnishAdminPort)},
Expand Down Expand Up @@ -52,6 +51,7 @@ func getSanitizedVarnishArgs(spec *vcapi.VarnishClusterSpec) []string {
}

varnishArgs := append(parsedArgs, varnishArgsOverrides...)
varnishArgs = append(varnishArgs, []string{"-a", fmt.Sprintf("0.0.0.0:%d", vcapi.VarnishPort)})

// sort the arguments so they won't appear in different order in different reconcile loops and trigger redeployment
sort.SliceStable(varnishArgs, func(i, j int) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestGetSanitizedVarnishArgs(t *testing.T) {
spec: &v1alpha1.VarnishClusterSpec{
VCL: vclConfigMap,
Varnish: &v1alpha1.VarnishClusterVarnish{
Args: []string{"-S", "/etc/varnish/newsecret", "-T", "127.0.0.1:4235", "-a", "0.0.0.0:3425", "-b", "127.0.0.1:3456"},
Args: []string{"-S", "/etc/varnish/newsecret", "-T", "127.0.0.1:4235", "-b", "127.0.0.1:3456"},
},
},
expectedResult: []string{
Expand Down Expand Up @@ -122,6 +122,26 @@ func TestGetSanitizedVarnishArgs(t *testing.T) {
"-p", "default_ttl=3600",
},
},
{
name: "additional -a arguments can be specified",
spec: &v1alpha1.VarnishClusterSpec{
VCL: vclConfigMap,
Varnish: &v1alpha1.VarnishClusterVarnish{
Args: []string{"-a", ":8080,PROXY", "-a", ":4392", "-p", "default_grace=3600", "-p", "default_ttl=3600"},
},
},
expectedResult: []string{
"-F",
"-S", "/etc/varnish-secret/secret",
"-T", fmt.Sprintf("0.0.0.0:%d", v1alpha1.VarnishAdminPort),
"-a", fmt.Sprintf("0.0.0.0:%d", v1alpha1.VarnishPort),
"-a", ":4392",
"-a", ":8080,PROXY",
"-b", "127.0.0.1:0",
"-p", "default_grace=3600",
"-p", "default_ttl=3600",
},
},
}

for _, c := range cases {
Expand Down

0 comments on commit b37c3db

Please sign in to comment.