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

Commit

Permalink
pkg/components: rename newComponent() functions to NewConfig()
Browse files Browse the repository at this point in the history
To make it consistent with pkg/platform/* packages and to make it
available outside of package, so we can avoid using globals and init()
functions for collecting available components default configurations.

Refs #992

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Dec 2, 2020
1 parent 5446c65 commit 5fd4800
Show file tree
Hide file tree
Showing 32 changed files with 132 additions and 73 deletions.
7 changes: 5 additions & 2 deletions pkg/components/aws-ebs-csi-driver/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ enableDefaultStorageClass: {{ .EnableDefaultStorageClass }}

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

type component struct {
EnableDefaultStorageClass bool `hcl:"enable_default_storage_class,optional"`
}

func newComponent() *component {
// NewConfig returns new AWS EBS CSI driver component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
EnableDefaultStorageClass: true,
}
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 @@ -26,7 +26,7 @@ import (
func TestStorageClassEmptyConfig(t *testing.T) {
configHCL := `component "aws-ebs-csi-driver" {}`

component := newComponent()
component := NewConfig()

body, diagnostics := util.GetComponentBody(configHCL, Name)
if diagnostics != nil {
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestStorageClassEnabled(t *testing.T) {
enable_default_storage_class = true
}`

component := newComponent()
component := NewConfig()

body, diagnostics := util.GetComponentBody(configHCL, Name)
if diagnostics != nil {
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestStorageClassDisabled(t *testing.T) {
enable_default_storage_class = false
}`

component := newComponent()
component := NewConfig()

body, diagnostics := util.GetComponentBody(configHCL, Name)
if diagnostics != nil {
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/cert-manager/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

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

type component struct {
Expand All @@ -43,7 +43,10 @@ type component struct {
ServiceMonitor bool `hcl:"service_monitor,optional"`
}

func newComponent() *component {
// NewConfig returns new cert-manager component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
Namespace: "cert-manager",
Webhooks: true,
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/cluster-autoscaler/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ serviceMonitor:
)

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

type component struct {
Expand Down Expand Up @@ -118,7 +118,10 @@ type packetConfiguration struct {
AuthToken string
}

func newComponent() *component {
// NewConfig returns new Cluster Autoscaler component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
c := &component{
Provider: "packet",
Namespace: "kube-system",
Expand Down
6 changes: 3 additions & 3 deletions pkg/components/cluster-autoscaler/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestEmptyConfig(t *testing.T) {
c := newComponent()
c := NewConfig()

emptyConfig := hcl.EmptyBody()

Expand All @@ -36,7 +36,7 @@ func TestEmptyConfig(t *testing.T) {
}

func TestEmptyBody(t *testing.T) {
c := newComponent()
c := NewConfig()

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

Expand All @@ -51,7 +51,7 @@ func TestEmptyBody(t *testing.T) {
}

func TestRender(t *testing.T) {
c := newComponent()
c := NewConfig()

config := `
component "cluster-autoscaler" {
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/contour/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
)

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

// This annotation is added to Envoy service.
Expand All @@ -49,7 +49,10 @@ type component struct {
TolerationsRaw string
}

func newComponent() *component {
// NewConfig returns new Contour component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
ServiceType: serviceTypeLoadBalancer,
}
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 @@ -69,7 +69,7 @@ component "contour" {
t.Errorf("%s - Error getting component body: %v", tc.desc, d)
}

c := newComponent()
c := NewConfig()
d = c.LoadConfig(b, nil)

if !tc.wantErr && d.HasErrors() {
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/dex/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
)

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

type org struct {
Expand Down Expand Up @@ -81,7 +81,10 @@ type component struct {
StaticClientsRaw string
}

func newComponent() *component {
// NewConfig returns new Dex component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
CertManagerClusterIssuer: "letsencrypt-production",
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/external-dns/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ metrics:
)

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

// AwsConfig provides configuration for AWS Route53 DNS.
Expand All @@ -88,7 +88,10 @@ type component struct {
OwnerID string `hcl:"owner_id"`
}

func newComponent() *component {
// NewConfig returns new ExternalDNS component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
Namespace: "external-dns",
Sources: []string{"ingress"},
Expand Down
14 changes: 7 additions & 7 deletions pkg/components/external-dns/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestEmptyConfig(t *testing.T) {
c := newComponent()
c := NewConfig()
emptyConfig := hcl.EmptyBody()
evalContext := hcl.EvalContext{}
diagnostics := c.LoadConfig(&emptyConfig, &evalContext)
Expand All @@ -33,7 +33,7 @@ func TestEmptyConfig(t *testing.T) {
}

func TestEmptyBody(t *testing.T) {
c := newComponent()
c := NewConfig()
config := `component "external-dns" {}`
body, diagnostics := util.GetComponentBody(config, Name)
if diagnostics != nil {
Expand All @@ -44,7 +44,7 @@ func TestEmptyBody(t *testing.T) {
}
}
func TestDefaultValues(t *testing.T) {
c := newComponent()
c := NewConfig()
if c.Namespace != "external-dns" {
t.Fatal("Default namespace for installation should be external-dns.")
}
Expand All @@ -64,7 +64,7 @@ func TestDefaultValues(t *testing.T) {
}

func TestAwsConfigWithoutProvidingCredentials(t *testing.T) {
c := newComponent()
c := NewConfig()
config := `
component "external-dns" {
sources = ["ingress"]
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestAwsConfigWithoutProvidingCredentials(t *testing.T) {
}

func TestAwsConfigBySettingEnvVariables(t *testing.T) {
c := newComponent()
c := NewConfig()
config := `
component "external-dns" {
sources = ["ingress"]
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestAwsConfigBySettingEnvVariables(t *testing.T) {
}

func TestAwsConfigBySettingEmptyEnvVariables(t *testing.T) {
c := newComponent()
c := NewConfig()
config := `
component "external-dns" {
sources = ["ingress"]
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestAwsConfigBySettingEmptyEnvVariables(t *testing.T) {
}

func TestAwsConfigBySettingConfigFields(t *testing.T) {
c := newComponent()
c := NewConfig()
config := `
component "external-dns" {
sources = ["ingress"]
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/gangway/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

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

type component struct {
Expand All @@ -49,7 +49,10 @@ type component struct {
CertManagerClusterIssuer string `hcl:"certmanager_cluster_issuer,optional"`
}

func newComponent() *component {
// NewConfig returns new Gangway component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
CertManagerClusterIssuer: "letsencrypt-production",
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/httpbin/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ const (
)

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

type component struct {
IngressHost string `hcl:"ingress_host,attr"`
CertManagerClusterIssuer string `hcl:"certmanager_cluster_issuer,optional"`
}

func newComponent() *component {
// NewConfig returns new httpbin component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
CertManagerClusterIssuer: "letsencrypt-production",
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/inspektor-gadget/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ const (

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

type component struct {
Namespace string `hcl:"namespace,optional"`
EnableTraceloop bool `hcl:"enable_traceloop,optional"`
}

func newComponent() *component {
// NewConfig returns new Inspektor Gadget component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
Namespace: "kube-system",
EnableTraceloop: true,
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/istio-operator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ const (

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

type component struct {
Profile string `hcl:"profile,optional"`
EnableMonitoring bool `hcl:"enable_monitoring,optional"`
}

func newComponent() *component {
// NewConfig returns new Istio Operator component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
Profile: "minimal",
EnableMonitoring: false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/istio-operator/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestConversion(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

component := newComponent()
component := NewConfig()
m := testutil.RenderManifests(t, component, Name, tc.inputConfig)
gotConfig := testutil.ConfigFromMap(t, m, tc.expectedManifestName)

Expand All @@ -65,7 +65,7 @@ func TestVerifyServiceMonitor(t *testing.T) {
enable_monitoring = true
}`

component := newComponent()
component := NewConfig()
m := testutil.RenderManifests(t, component, Name, inputConfig)
testutil.ConfigFromMap(t, m, "istio-operator/templates/service-monitor.yaml")
}
7 changes: 5 additions & 2 deletions pkg/components/linkerd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (

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

type component struct {
Expand All @@ -58,7 +58,10 @@ type cert struct {
Expiry string
}

func newComponent() *component {
// NewConfig returns new Linkerd component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{
ControllerReplicas: 1,
EnableMonitoring: false,
Expand Down
7 changes: 5 additions & 2 deletions pkg/components/metallb/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

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

type component struct {
Expand All @@ -48,7 +48,10 @@ type component struct {
SpeakerTolerationsJSON string
}

func newComponent() *component {
// NewConfig returns new MetalLB component configuration with default values set.
//
//nolint:golint
func NewConfig() *component {
return &component{}
}

Expand Down
Loading

0 comments on commit 5fd4800

Please sign in to comment.