Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
refactor: remove template.go from components/util package.
Browse files Browse the repository at this point in the history
Since RenderTemplate function is now part of the `internal` package,
this caused duplication. Hence the file `template.go` is removed from
the codebase.

Also we update the references to `util.RenderTemplate` to now refer to
the correct package and function.

Signed-off-by: Imran Pochi <imran@kinvolk.io>
  • Loading branch information
ipochi committed Jun 9, 2020
1 parent 78e487b commit 2fbb1a2
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 59 deletions.
4 changes: 2 additions & 2 deletions pkg/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/backend"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

type local struct {
Expand All @@ -45,7 +45,7 @@ func NewLocalBackend() *local {

// Render renders the Go template with local backend configuration.
func (l *local) Render() (string, error) {
return util.RenderTemplate(backendConfigTmpl, l)
return template.Render(backendConfigTmpl, l)
}

// Validate validates the local backend configuration.
Expand Down
4 changes: 2 additions & 2 deletions pkg/backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/backend"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

type s3 struct {
Expand Down Expand Up @@ -52,7 +52,7 @@ func NewS3Backend() *s3 {

// Render renders the Go template with s3 backend configuration.
func (s *s3) Render() (string, error) {
return util.RenderTemplate(backendConfigTmpl, s)
return template.Render(backendConfigTmpl, s)
}

// Validate validates the s3 backend configuration.
Expand Down
3 changes: 2 additions & 1 deletion pkg/components/cert-manager/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, errors.Wrap(err, "load chart from assets")
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "render chart values template")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/components/cluster-autoscaler/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/packethost/packngo"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)
Expand Down Expand Up @@ -323,7 +324,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
c.Packet.AuthToken = base64.StdEncoding.EncodeToString([]byte(os.Getenv("PACKET_AUTH_TOKEN")))
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "render chart values template")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/contour/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/kinvolk/lokomotive/pkg/components/util"

internaltemplate "github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

const (
Expand Down Expand Up @@ -101,7 +102,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, fmt.Errorf("failed to marshal node affinity: %w", err)
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := internaltemplate.Render(chartValuesTmpl, c)
if err != nil {
return nil, fmt.Errorf("rendering values template failed: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/components/dex/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

internaltemplate "github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

const name = "dex"
Expand Down Expand Up @@ -310,17 +310,17 @@ func (c *component) RenderManifests() (map[string]string, error) {
}
c.StaticClientsRaw = staticClients

configMap, err := util.RenderTemplate(configMapTmpl, c)
configMap, err := internaltemplate.Render(configMapTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "execute template failed")
}

ingressBuf, err := util.RenderTemplate(ingressTmpl, c)
ingressBuf, err := internaltemplate.Render(ingressTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "execute template failed")
}

deployment, err := util.RenderTemplate(deploymentTmpl, c)
deployment, err := internaltemplate.Render(deploymentTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "execute template failed")
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/components/external-dns/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
"github.com/pkg/errors"
)

const name = "external-dns"
Expand Down Expand Up @@ -128,7 +130,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
c.AwsConfig.SecretAccessKey = secretAccessKey
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "render chart values template")
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/components/metallb/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package metallb
import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
"github.com/pkg/errors"
)

const name = "metallb"
Expand Down Expand Up @@ -85,17 +87,17 @@ func (c *component) RenderManifests() (map[string]string, error) {
}
c.ControllerTolerationsJSON = t

controllerStr, err := util.RenderTemplate(deploymentController, c)
controllerStr, err := template.Render(deploymentController, c)
if err != nil {
return nil, errors.Wrap(err, "render template failed")
}

speakerStr, err := util.RenderTemplate(daemonsetSpeaker, c)
speakerStr, err := template.Render(daemonsetSpeaker, c)
if err != nil {
return nil, errors.Wrap(err, "render template failed")
}

configMapStr, err := util.RenderTemplate(configMap, c)
configMapStr, err := template.Render(configMap, c)
if err != nil {
return nil, errors.Wrap(err, "rendering ConfigMap template failed")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/components/metrics-server/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)
Expand Down Expand Up @@ -75,7 +76,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, errors.Wrap(err, "load chart from assets")
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "render chart values template")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/components/openebs-operator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)
Expand Down Expand Up @@ -101,7 +102,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, fmt.Errorf("load chart from assets: %w", err)
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, fmt.Errorf("render chart values template: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/components/prometheus-operator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/types"
"github.com/kinvolk/lokomotive/pkg/components/util"
Expand Down Expand Up @@ -149,7 +150,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, errors.Wrap(err, "load chart from assets")
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "render chart values template")
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/components/rook-ceph/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

internaltemplate "github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
"github.com/pkg/errors"
)

const name = "rook-ceph"
Expand Down Expand Up @@ -74,7 +76,7 @@ func (c *component) RenderManifests() (map[string]string, error) {

// Parse template with values
for k, v := range template {
rendered, err := util.RenderTemplate(v, c)
rendered, err := internaltemplate.Render(v, c)
if err != nil {
return nil, fmt.Errorf("template rendering failed for %q: %w", k, err)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/components/rook/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)
Expand Down Expand Up @@ -75,7 +77,7 @@ func (c *component) RenderManifests() (map[string]string, error) {

c.RookNodeAffinity = convertNodeSelector(c.NodeSelector)

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, fmt.Errorf("rendering values template failed: %w", err)
}
Expand Down
34 changes: 0 additions & 34 deletions pkg/components/util/template.go

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/components/velero/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/pkg/errors"

"github.com/kinvolk/lokomotive/internal/template"
"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
"github.com/kinvolk/lokomotive/pkg/components/velero/azure"
Expand Down Expand Up @@ -152,7 +153,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, errors.Wrap(err, "load chart from assets")
}

values, err := util.RenderTemplate(chartValuesTmpl, c)
values, err := template.Render(chartValuesTmpl, c)
if err != nil {
return nil, errors.Wrap(err, "render chart values template")
}
Expand Down

0 comments on commit 2fbb1a2

Please sign in to comment.