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

Commit

Permalink
pkg/components: export component names using Name constant
Browse files Browse the repository at this point in the history
As a preparation for #992.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Dec 2, 2020
1 parent c6fe0fa commit 5446c65
Show file tree
Hide file tree
Showing 33 changed files with 214 additions and 132 deletions.
16 changes: 10 additions & 6 deletions pkg/components/aws-ebs-csi-driver/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ import (
"github.com/kinvolk/lokomotive/pkg/k8sutil"
)

const name = "aws-ebs-csi-driver"
const (
// Name represents AWS EBS CSI driver component name as it should be referenced in function calls
// and in configuration.
Name = "aws-ebs-csi-driver"

const chartValuesTmpl = `
chartValuesTmpl = `
enableDefaultStorageClass: {{ .EnableDefaultStorageClass }}
`
)

//nolint:gochecknoinits
func init() {
components.Register(name, newComponent())
components.Register(Name, newComponent())
}

type component struct {
Expand All @@ -58,7 +62,7 @@ func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContex

// RenderManifests renders the Helm chart templates with values provided.
func (c *component) RenderManifests() (map[string]string, error) {
helmChart, err := components.Chart(name)
helmChart, err := components.Chart(Name)
if err != nil {
return nil, fmt.Errorf("retrieving chart from assets: %w", err)
}
Expand All @@ -68,7 +72,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, fmt.Errorf("rendering chart values template failed: %w", err)
}

renderedFiles, err := util.RenderChart(helmChart, name, c.Metadata().Namespace.Name, values)
renderedFiles, err := util.RenderChart(helmChart, Name, c.Metadata().Namespace.Name, values)
if err != nil {
return nil, fmt.Errorf("rendering chart failed: %w", err)
}
Expand All @@ -78,7 +82,7 @@ func (c *component) RenderManifests() (map[string]string, error) {

func (c *component) Metadata() components.Metadata {
return components.Metadata{
Name: name,
Name: Name,
Namespace: k8sutil.Namespace{
Name: "kube-system",
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/components/aws-ebs-csi-driver/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestStorageClassEmptyConfig(t *testing.T) {

component := newComponent()

body, diagnostics := util.GetComponentBody(configHCL, name)
body, diagnostics := util.GetComponentBody(configHCL, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestStorageClassEnabled(t *testing.T) {

component := newComponent()

body, diagnostics := util.GetComponentBody(configHCL, name)
body, diagnostics := util.GetComponentBody(configHCL, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestStorageClassDisabled(t *testing.T) {

component := newComponent()

body, diagnostics := util.GetComponentBody(configHCL, name)
body, diagnostics := util.GetComponentBody(configHCL, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/components/cert-manager/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ import (
"github.com/kinvolk/lokomotive/pkg/k8sutil"
)

const name = "cert-manager"
const (
// Name represents cert-manager component name as it should be referenced in function calls
// and in configuration.
Name = "cert-manager"
)

func init() {
components.Register(name, newComponent())
components.Register(Name, newComponent())
}

type component struct {
Expand Down Expand Up @@ -75,7 +79,7 @@ func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContex
}

func (c *component) RenderManifests() (map[string]string, error) {
helmChart, err := components.Chart(name)
helmChart, err := components.Chart(Name)
if err != nil {
return nil, fmt.Errorf("retrieving chart from assets: %w", err)
}
Expand All @@ -85,7 +89,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, fmt.Errorf("rendering chart values template: %w", err)
}

renderedFiles, err := util.RenderChart(helmChart, name, c.Namespace, values)
renderedFiles, err := util.RenderChart(helmChart, Name, c.Namespace, values)
if err != nil {
return nil, fmt.Errorf("rendering chart: %w", err)
}
Expand All @@ -95,7 +99,7 @@ func (c *component) RenderManifests() (map[string]string, error) {

func (c *component) Metadata() components.Metadata {
return components.Metadata{
Name: name,
Name: Name,
Namespace: k8sutil.Namespace{
Name: c.Namespace,
Labels: map[string]string{
Expand Down
16 changes: 10 additions & 6 deletions pkg/components/cluster-autoscaler/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ import (
"github.com/kinvolk/lokomotive/pkg/k8sutil"
)

const name = "cluster-autoscaler"
const (
// Name represents Cluster Autoscaler component name as it should be referenced in function calls
// and in configuration.
Name = "cluster-autoscaler"

const chartValuesTmpl = `
chartValuesTmpl = `
cloudProvider: {{ .Provider }}
nodeSelector:
node.kubernetes.io/controller: "true"
Expand Down Expand Up @@ -73,9 +76,10 @@ serviceMonitor:
release: prometheus-operator
{{ end }}
`
)

func init() {
components.Register(name, newComponent())
components.Register(Name, newComponent())
}

type component struct {
Expand Down Expand Up @@ -346,7 +350,7 @@ func (c *component) validatePacket(diagnostics hcl.Diagnostics) hcl.Diagnostics
}

func (c *component) RenderManifests() (map[string]string, error) {
helmChart, err := components.Chart(name)
helmChart, err := components.Chart(Name)
if err != nil {
return nil, fmt.Errorf("retrieving chart from assets: %w", err)
}
Expand Down Expand Up @@ -376,12 +380,12 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, fmt.Errorf("rendering chart values template: %w", err)
}

return util.RenderChart(helmChart, name, c.Namespace, values)
return util.RenderChart(helmChart, Name, c.Namespace, values)
}

func (c *component) Metadata() components.Metadata {
return components.Metadata{
Name: name,
Name: Name,
Namespace: k8sutil.Namespace{
Name: c.Namespace,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/cluster-autoscaler/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestEmptyBody(t *testing.T) {

config := `component "cluster-autoscaler" {}`

body, diagnostics := util.GetComponentBody(config, name)
body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand All @@ -66,7 +66,7 @@ func TestRender(t *testing.T) {
}
`

body, diagnostics := util.GetComponentBody(config, name)
body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/components/contour/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ import (
)

const (
name = "contour"
// Name represents Contour component name as it should be referenced in function calls
// and in configuration.
Name = "contour"

serviceTypeNodePort = "NodePort"
serviceTypeLoadBalancer = "LoadBalancer"
)

func init() {
components.Register(name, newComponent())
components.Register(Name, newComponent())
}

// This annotation is added to Envoy service.
Expand Down Expand Up @@ -79,7 +82,7 @@ func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContex
}

func (c *component) RenderManifests() (map[string]string, error) {
helmChart, err := components.Chart(name)
helmChart, err := components.Chart(Name)
if err != nil {
return nil, fmt.Errorf("retrieving chart from assets: %w", err)
}
Expand All @@ -100,7 +103,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
}

// Generate YAML for the Contour deployment.
renderedFiles, err := util.RenderChart(helmChart, name, c.Metadata().Namespace.Name, values)
renderedFiles, err := util.RenderChart(helmChart, Name, c.Metadata().Namespace.Name, values)
if err != nil {
return nil, fmt.Errorf("rendering chart failed: %w", err)
}
Expand All @@ -110,7 +113,7 @@ func (c *component) RenderManifests() (map[string]string, error) {

func (c *component) Metadata() components.Metadata {
return components.Metadata{
Name: name,
Name: Name,
Namespace: k8sutil.Namespace{
Name: "projectcontour",
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/contour/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ component "contour" {
}

for _, tc := range tests {
b, d := util.GetComponentBody(tc.hcl, name)
b, d := util.GetComponentBody(tc.hcl, Name)
if d != nil {
t.Errorf("%s - Error getting component body: %v", tc.desc, d)
}
Expand Down
16 changes: 10 additions & 6 deletions pkg/components/dex/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ import (
"github.com/kinvolk/lokomotive/pkg/k8sutil"
)

const name = "dex"
const (
// Name represents Dex component name as it should be referenced in function calls
// and in configuration.
Name = "dex"
)

func init() { //nolint:gochecknoinits
components.Register(name, newComponent())
components.Register(Name, newComponent())
}

type org struct {
Expand Down Expand Up @@ -105,7 +109,7 @@ func marshalToStr(obj interface{}) (string, error) {
}

func (c *component) RenderManifests() (map[string]string, error) {
helmChart, err := components.Chart(name)
helmChart, err := components.Chart(Name)
if err != nil {
return nil, fmt.Errorf("retrieving chart from assets: %w", err)
}
Expand Down Expand Up @@ -141,7 +145,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
}

// Generate YAML for the dex deployment.
renderedFiles, err := util.RenderChart(helmChart, name, c.Metadata().Namespace.Name, values)
renderedFiles, err := util.RenderChart(helmChart, Name, c.Metadata().Namespace.Name, values)
if err != nil {
return nil, fmt.Errorf("rendering chart failed: %w", err)
}
Expand All @@ -151,9 +155,9 @@ func (c *component) RenderManifests() (map[string]string, error) {

func (c *component) Metadata() components.Metadata {
return components.Metadata{
Name: name,
Name: Name,
Namespace: k8sutil.Namespace{
Name: name,
Name: Name,
},
}
}
22 changes: 13 additions & 9 deletions pkg/components/external-dns/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import (
"github.com/kinvolk/lokomotive/pkg/k8sutil"
)

const name = "external-dns"

// TODO Currently supporting only AWS Route53. Provide better conditional templates
// when multiple provider support is added.
const chartValuesTmpl = `
const (
// Name represents ExternalDNS component name as it should be referenced in function calls
// and in configuration.
Name = "external-dns"

// TODO Currently supporting only AWS Route53. Provide better conditional templates
// when multiple provider support is added.
chartValuesTmpl = `
provider: aws
{{- if .Sources }}
sources:
Expand Down Expand Up @@ -60,9 +63,10 @@ metrics:
release: prometheus-operator
{{ end }}
`
)

func init() {
components.Register(name, newComponent())
components.Register(Name, newComponent())
}

// AwsConfig provides configuration for AWS Route53 DNS.
Expand Down Expand Up @@ -108,7 +112,7 @@ func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContex

// RenderManifests renders the helm chart templates with values provided.
func (c *component) RenderManifests() (map[string]string, error) {
helmChart, err := components.Chart(name)
helmChart, err := components.Chart(Name)
if err != nil {
return nil, fmt.Errorf("retrieving chart from assets: %w", err)
}
Expand All @@ -135,7 +139,7 @@ func (c *component) RenderManifests() (map[string]string, error) {
return nil, fmt.Errorf("rendering chart values template: %w", err)
}

renderedFiles, err := util.RenderChart(helmChart, name, c.Namespace, values)
renderedFiles, err := util.RenderChart(helmChart, Name, c.Namespace, values)
if err != nil {
return nil, fmt.Errorf("rendering chart: %w", err)
}
Expand All @@ -145,7 +149,7 @@ func (c *component) RenderManifests() (map[string]string, error) {

func (c *component) Metadata() components.Metadata {
return components.Metadata{
Name: name,
Name: Name,
Namespace: k8sutil.Namespace{
Name: c.Namespace,
},
Expand Down
12 changes: 7 additions & 5 deletions pkg/components/external-dns/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestEmptyConfig(t *testing.T) {
func TestEmptyBody(t *testing.T) {
c := newComponent()
config := `component "external-dns" {}`
body, diagnostics := util.GetComponentBody(config, name)
body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestAwsConfigWithoutProvidingCredentials(t *testing.T) {
os.Unsetenv("AWS_ACCESS_KEY_ID")
os.Unsetenv("AWS_SECRET_ACCESS_KEY")

body, diagnostics := util.GetComponentBody(config, name)
body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down Expand Up @@ -114,7 +114,8 @@ func TestAwsConfigBySettingEnvVariables(t *testing.T) {
if err := os.Setenv("AWS_SECRET_ACCESS_KEY", "TESTSECRETACCESSKEY"); err != nil {
t.Fatalf("Error setting env variable: %s", err)
}
body, diagnostics := util.GetComponentBody(config, name)

body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down Expand Up @@ -153,7 +154,8 @@ func TestAwsConfigBySettingEmptyEnvVariables(t *testing.T) {
if err != nil {
t.Fatalf("Error setting env variable: %s", err)
}
body, diagnostics := util.GetComponentBody(config, name)

body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down Expand Up @@ -182,7 +184,7 @@ func TestAwsConfigBySettingConfigFields(t *testing.T) {
}
}
`
body, diagnostics := util.GetComponentBody(config, name)
body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
t.Fatalf("Error getting component body: %v", diagnostics)
}
Expand Down
Loading

0 comments on commit 5446c65

Please sign in to comment.