From f5fbeb149f5738a84b5b3e058186c728dd2d15f0 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Fri, 16 Feb 2024 21:22:26 +0100 Subject: [PATCH] support templated flag (#124) --- go.mod | 2 +- go.sum | 4 ++-- pkg/manifests/template/raw.go | 11 +++++++++++ pkg/manifests/template/raw_test.go | 11 ++++++++++- test/rawTemplated/pod.yaml | 10 ++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/rawTemplated/pod.yaml diff --git a/go.mod b/go.mod index e754e86e..72e83d9f 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/orcaman/concurrent-map/v2 v2.0.1 github.com/osteele/liquid v1.3.2 github.com/pkg/errors v0.9.1 - github.com/pluralsh/console-client-go v0.0.92 + github.com/pluralsh/console-client-go v0.0.95 github.com/pluralsh/controller-reconcile-helper v0.0.4 github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 github.com/pluralsh/polly v0.1.4 diff --git a/go.sum b/go.sum index 7f5c6108..bb40c97d 100644 --- a/go.sum +++ b/go.sum @@ -579,8 +579,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pluralsh/console-client-go v0.0.92 h1:PMSF05Zp5gLejeEWXbwe17CfXNLJ55dGlFPAAVucfCM= -github.com/pluralsh/console-client-go v0.0.92/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= +github.com/pluralsh/console-client-go v0.0.95 h1:JxZ4FSGDo9Mxu1947i2ipCZquDQ+iWW6FGx3s4/onpA= +github.com/pluralsh/console-client-go v0.0.95/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E= github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s= github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw= diff --git a/pkg/manifests/template/raw.go b/pkg/manifests/template/raw.go index e3f0c191..9de4ac20 100644 --- a/pkg/manifests/template/raw.go +++ b/pkg/manifests/template/raw.go @@ -44,7 +44,18 @@ func NewRaw(dir string) *raw { return &raw{dir} } +func isTemplated(svc *console.GetServiceDeploymentForAgent_ServiceDeployment) bool { + if svc.Templated != nil { + return *svc.Templated + } + // default true + return true +} + func renderLiquid(input []byte, svc *console.GetServiceDeploymentForAgent_ServiceDeployment) ([]byte, error) { + if !isTemplated(svc) { + return input, nil + } bindings := map[string]interface{}{ "configuration": configMap(svc), "cluster": svc.Cluster, diff --git a/pkg/manifests/template/raw_test.go b/pkg/manifests/template/raw_test.go index c55a4939..1c7b3e86 100644 --- a/pkg/manifests/template/raw_test.go +++ b/pkg/manifests/template/raw_test.go @@ -1,6 +1,7 @@ package template import ( + "github.com/samber/lo" "path/filepath" . "github.com/onsi/ginkgo/v2" @@ -10,7 +11,6 @@ import ( var _ = Describe("Raw template", func() { - dir := filepath.Join("..", "..", "..", "test", "raw") svc := &console.GetServiceDeploymentForAgent_ServiceDeployment{ Namespace: "default", Configuration: make([]*console.GetServiceDeploymentForAgent_ServiceDeployment_Configuration, 0), @@ -18,6 +18,7 @@ var _ = Describe("Raw template", func() { Context("Render raw template", func() { const name = "nginx" It("should successfully render the raw template", func() { + dir := filepath.Join("..", "..", "..", "test", "raw") svc.Configuration = []*console.GetServiceDeploymentForAgent_ServiceDeployment_Configuration{ { Name: "name", @@ -29,6 +30,14 @@ var _ = Describe("Raw template", func() { Expect(len(resp)).To(Equal(1)) Expect(resp[0].GetName()).To(Equal(name)) }) + It("should skip templating liquid", func() { + dir := filepath.Join("..", "..", "..", "test", "rawTemplated") + svc.Templated = lo.ToPtr(false) + resp, err := NewRaw(dir).Render(svc, utilFactory) + Expect(err).NotTo(HaveOccurred()) + Expect(len(resp)).To(Equal(1)) + Expect(resp[0].GetName()).To(Equal(name)) + }) }) }) diff --git a/test/rawTemplated/pod.yaml b/test/rawTemplated/pod.yaml new file mode 100644 index 00000000..efe5bd38 --- /dev/null +++ b/test/rawTemplated/pod.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Pod +metadata: + name: nginx +spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80