From 0988eb5d663c4d396d145d8911cb0e229d2bd4e6 Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Mon, 2 Nov 2020 17:11:53 +0100 Subject: [PATCH] pkg/components: rename newComponent() functions to NewConfig() 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 --- pkg/components/aws-ebs-csi-driver/component.go | 7 +++++-- .../aws-ebs-csi-driver/component_test.go | 6 +++--- pkg/components/cert-manager/component.go | 7 +++++-- pkg/components/cluster-autoscaler/component.go | 7 +++++-- .../cluster-autoscaler/component_test.go | 6 +++--- pkg/components/contour/component.go | 7 +++++-- pkg/components/contour/component_test.go | 2 +- pkg/components/dex/component.go | 7 +++++-- pkg/components/external-dns/component.go | 7 +++++-- pkg/components/external-dns/component_test.go | 14 +++++++------- pkg/components/gangway/component.go | 7 +++++-- pkg/components/httpbin/component.go | 7 +++++-- pkg/components/inspektor-gadget/component.go | 7 +++++-- pkg/components/istio-operator/component.go | 7 +++++-- pkg/components/istio-operator/component_test.go | 4 ++-- pkg/components/linkerd/component.go | 7 +++++-- pkg/components/metallb/component.go | 7 +++++-- pkg/components/metallb/component_test.go | 4 ++-- pkg/components/metrics-server/component.go | 7 +++++-- pkg/components/metrics-server/component_test.go | 2 +- pkg/components/openebs-operator/component.go | 7 +++++-- pkg/components/openebs-storage-class/component.go | 7 +++++-- .../openebs-storage-class/component_test.go | 4 ++-- pkg/components/prometheus-operator/component.go | 7 +++++-- .../prometheus-operator/component_test.go | 4 ++-- pkg/components/rook-ceph/component.go | 7 +++++-- pkg/components/rook-ceph/component_test.go | 4 ++-- pkg/components/rook/component.go | 7 +++++-- pkg/components/velero/azure/azure.go | 2 +- pkg/components/velero/component.go | 8 +++++--- pkg/components/velero/component_test.go | 12 ++++++------ pkg/components/web-ui/component.go | 7 +++++-- 32 files changed, 132 insertions(+), 73 deletions(-) diff --git a/pkg/components/aws-ebs-csi-driver/component.go b/pkg/components/aws-ebs-csi-driver/component.go index d9b4ddf0a..76380d2a2 100644 --- a/pkg/components/aws-ebs-csi-driver/component.go +++ b/pkg/components/aws-ebs-csi-driver/component.go @@ -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, } diff --git a/pkg/components/aws-ebs-csi-driver/component_test.go b/pkg/components/aws-ebs-csi-driver/component_test.go index 7c1362260..f090dce37 100644 --- a/pkg/components/aws-ebs-csi-driver/component_test.go +++ b/pkg/components/aws-ebs-csi-driver/component_test.go @@ -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 { @@ -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 { @@ -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 { diff --git a/pkg/components/cert-manager/component.go b/pkg/components/cert-manager/component.go index 5adb6bcdb..cca8d4237 100644 --- a/pkg/components/cert-manager/component.go +++ b/pkg/components/cert-manager/component.go @@ -33,7 +33,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -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, diff --git a/pkg/components/cluster-autoscaler/component.go b/pkg/components/cluster-autoscaler/component.go index debc75f00..c0c35ae30 100644 --- a/pkg/components/cluster-autoscaler/component.go +++ b/pkg/components/cluster-autoscaler/component.go @@ -79,7 +79,7 @@ serviceMonitor: ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -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", diff --git a/pkg/components/cluster-autoscaler/component_test.go b/pkg/components/cluster-autoscaler/component_test.go index caa7a05cc..779297421 100644 --- a/pkg/components/cluster-autoscaler/component_test.go +++ b/pkg/components/cluster-autoscaler/component_test.go @@ -23,7 +23,7 @@ import ( ) func TestEmptyConfig(t *testing.T) { - c := newComponent() + c := NewConfig() emptyConfig := hcl.EmptyBody() @@ -36,7 +36,7 @@ func TestEmptyConfig(t *testing.T) { } func TestEmptyBody(t *testing.T) { - c := newComponent() + c := NewConfig() config := `component "cluster-autoscaler" {}` @@ -51,7 +51,7 @@ func TestEmptyBody(t *testing.T) { } func TestRender(t *testing.T) { - c := newComponent() + c := NewConfig() config := ` component "cluster-autoscaler" { diff --git a/pkg/components/contour/component.go b/pkg/components/contour/component.go index d2365b3da..652cf3a32 100644 --- a/pkg/components/contour/component.go +++ b/pkg/components/contour/component.go @@ -36,7 +36,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } // This annotation is added to Envoy service. @@ -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, } diff --git a/pkg/components/contour/component_test.go b/pkg/components/contour/component_test.go index 3bfd85450..a1ce8ecae 100644 --- a/pkg/components/contour/component_test.go +++ b/pkg/components/contour/component_test.go @@ -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() { diff --git a/pkg/components/dex/component.go b/pkg/components/dex/component.go index 9bddbf7c7..9d91e9a8e 100644 --- a/pkg/components/dex/component.go +++ b/pkg/components/dex/component.go @@ -34,7 +34,7 @@ const ( ) func init() { //nolint:gochecknoinits - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type org struct { @@ -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", } diff --git a/pkg/components/external-dns/component.go b/pkg/components/external-dns/component.go index 7213dbb74..60e279e76 100644 --- a/pkg/components/external-dns/component.go +++ b/pkg/components/external-dns/component.go @@ -66,7 +66,7 @@ metrics: ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } // AwsConfig provides configuration for AWS Route53 DNS. @@ -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"}, diff --git a/pkg/components/external-dns/component_test.go b/pkg/components/external-dns/component_test.go index 433705b40..66e299c4d 100644 --- a/pkg/components/external-dns/component_test.go +++ b/pkg/components/external-dns/component_test.go @@ -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) @@ -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 { @@ -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.") } @@ -64,7 +64,7 @@ func TestDefaultValues(t *testing.T) { } func TestAwsConfigWithoutProvidingCredentials(t *testing.T) { - c := newComponent() + c := NewConfig() config := ` component "external-dns" { sources = ["ingress"] @@ -94,7 +94,7 @@ func TestAwsConfigWithoutProvidingCredentials(t *testing.T) { } func TestAwsConfigBySettingEnvVariables(t *testing.T) { - c := newComponent() + c := NewConfig() config := ` component "external-dns" { sources = ["ingress"] @@ -132,7 +132,7 @@ func TestAwsConfigBySettingEnvVariables(t *testing.T) { } func TestAwsConfigBySettingEmptyEnvVariables(t *testing.T) { - c := newComponent() + c := NewConfig() config := ` component "external-dns" { sources = ["ingress"] @@ -169,7 +169,7 @@ func TestAwsConfigBySettingEmptyEnvVariables(t *testing.T) { } func TestAwsConfigBySettingConfigFields(t *testing.T) { - c := newComponent() + c := NewConfig() config := ` component "external-dns" { sources = ["ingress"] diff --git a/pkg/components/gangway/component.go b/pkg/components/gangway/component.go index a576577cf..d16c67c9f 100644 --- a/pkg/components/gangway/component.go +++ b/pkg/components/gangway/component.go @@ -33,7 +33,7 @@ const ( ) func init() { //nolint:gochecknoinits - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -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", } diff --git a/pkg/components/httpbin/component.go b/pkg/components/httpbin/component.go index 97b41d803..d17762fca 100644 --- a/pkg/components/httpbin/component.go +++ b/pkg/components/httpbin/component.go @@ -33,7 +33,7 @@ const ( ) func init() { //nolint:gochecknoinits - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -41,7 +41,10 @@ type component struct { 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", } diff --git a/pkg/components/inspektor-gadget/component.go b/pkg/components/inspektor-gadget/component.go index a064c7bcf..c0916ef75 100644 --- a/pkg/components/inspektor-gadget/component.go +++ b/pkg/components/inspektor-gadget/component.go @@ -34,7 +34,7 @@ const ( //nolint:gochecknoinits func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -42,7 +42,10 @@ type component struct { 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, diff --git a/pkg/components/istio-operator/component.go b/pkg/components/istio-operator/component.go index 13c772488..39aba507e 100644 --- a/pkg/components/istio-operator/component.go +++ b/pkg/components/istio-operator/component.go @@ -36,7 +36,7 @@ const ( //nolint:gochecknoinits func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -44,7 +44,10 @@ type component struct { 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, diff --git a/pkg/components/istio-operator/component_test.go b/pkg/components/istio-operator/component_test.go index f22265ef3..1b5db9d64 100644 --- a/pkg/components/istio-operator/component_test.go +++ b/pkg/components/istio-operator/component_test.go @@ -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) @@ -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") } diff --git a/pkg/components/linkerd/component.go b/pkg/components/linkerd/component.go index bb77e60ff..12b6a0631 100644 --- a/pkg/components/linkerd/component.go +++ b/pkg/components/linkerd/component.go @@ -40,7 +40,7 @@ const ( //nolint:gochecknoinits func init() { - components.Register(name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -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, diff --git a/pkg/components/metallb/component.go b/pkg/components/metallb/component.go index b7d80e7de..57f0ad4c1 100644 --- a/pkg/components/metallb/component.go +++ b/pkg/components/metallb/component.go @@ -33,7 +33,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -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{} } diff --git a/pkg/components/metallb/component_test.go b/pkg/components/metallb/component_test.go index 165c93c00..1d0386b23 100644 --- a/pkg/components/metallb/component_test.go +++ b/pkg/components/metallb/component_test.go @@ -27,7 +27,7 @@ import ( ) func TestEmptyConfig(t *testing.T) { - c := newComponent() + c := NewConfig() emptyConfig := hcl.EmptyBody() evalContext := hcl.EvalContext{} diagnostics := c.LoadConfig(&emptyConfig, &evalContext) @@ -37,7 +37,7 @@ func TestEmptyConfig(t *testing.T) { } func renderManifest(t *testing.T, configHCL string) map[string]string { - component := newComponent() + component := NewConfig() body, diagnostics := util.GetComponentBody(configHCL, Name) if diagnostics != nil { diff --git a/pkg/components/metrics-server/component.go b/pkg/components/metrics-server/component.go index e6632e6bb..12af42514 100644 --- a/pkg/components/metrics-server/component.go +++ b/pkg/components/metrics-server/component.go @@ -53,14 +53,17 @@ args: ` func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { Namespace string `hcl:"namespace,optional"` } -func newComponent() *component { +// NewConfig returns new metrics-server component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{ Namespace: "kube-system", } diff --git a/pkg/components/metrics-server/component_test.go b/pkg/components/metrics-server/component_test.go index 79774cdda..f8f95fa90 100644 --- a/pkg/components/metrics-server/component_test.go +++ b/pkg/components/metrics-server/component_test.go @@ -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) diff --git a/pkg/components/openebs-operator/component.go b/pkg/components/openebs-operator/component.go index 421d16e3e..b37db8822 100644 --- a/pkg/components/openebs-operator/component.go +++ b/pkg/components/openebs-operator/component.go @@ -33,7 +33,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -92,7 +92,10 @@ webhook: {{- end }} ` -func newComponent() *component { +// NewConfig returns new OpenEBS Operator component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{} } diff --git a/pkg/components/openebs-storage-class/component.go b/pkg/components/openebs-storage-class/component.go index 0bab6d9a8..8afe6b88c 100644 --- a/pkg/components/openebs-storage-class/component.go +++ b/pkg/components/openebs-storage-class/component.go @@ -35,7 +35,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type Storageclass struct { @@ -61,7 +61,10 @@ func defaultStorageClass() *Storageclass { } } -func newComponent() *component { +// NewConfig returns new OpenEBS Storage Class component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{ Storageclasses: []*Storageclass{}, } diff --git a/pkg/components/openebs-storage-class/component_test.go b/pkg/components/openebs-storage-class/component_test.go index 406ad3951..cb65a2041 100644 --- a/pkg/components/openebs-storage-class/component_test.go +++ b/pkg/components/openebs-storage-class/component_test.go @@ -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) @@ -68,7 +68,7 @@ func TestUserInputValues(t *testing.T) { } func testRenderManifest(t *testing.T, configHCL string) { - component := newComponent() + component := NewConfig() body, diagnostics := util.GetComponentBody(configHCL, Name) if diagnostics != nil { diff --git a/pkg/components/prometheus-operator/component.go b/pkg/components/prometheus-operator/component.go index 3c9fc1128..9166cfa63 100644 --- a/pkg/components/prometheus-operator/component.go +++ b/pkg/components/prometheus-operator/component.go @@ -35,7 +35,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } // Monitor holds information about which Kubernetes components should be monitored with the default Prometheus instance. @@ -94,7 +94,10 @@ type component struct { CoreDNS *CoreDNS `hcl:"coredns,block"` } -func newComponent() *component { +// NewConfig returns new Prometheus Operator component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { defaultAlertManagerConfig := ` config: global: diff --git a/pkg/components/prometheus-operator/component_test.go b/pkg/components/prometheus-operator/component_test.go index 53f7b51ea..edc918f7f 100644 --- a/pkg/components/prometheus-operator/component_test.go +++ b/pkg/components/prometheus-operator/component_test.go @@ -101,7 +101,7 @@ component "prometheus-operator" { t.Fatalf("error getting component body: %v", d) } - c := newComponent() + c := NewConfig() d = c.LoadConfig(b, nil) if !tc.wantErr && d.HasErrors() { @@ -208,7 +208,7 @@ providers: 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) diff --git a/pkg/components/rook-ceph/component.go b/pkg/components/rook-ceph/component.go index 7b1b5c884..5b046e4a4 100644 --- a/pkg/components/rook-ceph/component.go +++ b/pkg/components/rook-ceph/component.go @@ -33,7 +33,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -53,7 +53,10 @@ type StorageClass struct { Default bool `hcl:"default,optional"` } -func newComponent() *component { +// NewConfig returns new Rook Ceph component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{ Namespace: "rook", MonitorCount: 1, diff --git a/pkg/components/rook-ceph/component_test.go b/pkg/components/rook-ceph/component_test.go index cb46b44a9..4d7104cc7 100644 --- a/pkg/components/rook-ceph/component_test.go +++ b/pkg/components/rook-ceph/component_test.go @@ -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) @@ -62,7 +62,7 @@ component "rook-ceph" { } ` - component := newComponent() + component := NewConfig() body, diagnostics := util.GetComponentBody(configHCL, Name) if diagnostics != nil { diff --git a/pkg/components/rook/component.go b/pkg/components/rook/component.go index adc7c1f7d..a4b5409c0 100644 --- a/pkg/components/rook/component.go +++ b/pkg/components/rook/component.go @@ -34,7 +34,7 @@ const ( ) func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type component struct { @@ -55,7 +55,10 @@ type component struct { CSIPluginTolerationsRaw string } -func newComponent() *component { +// NewConfig returns new Rook component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{ Namespace: "rook", } diff --git a/pkg/components/velero/azure/azure.go b/pkg/components/velero/azure/azure.go index b5f8e836f..912f063fa 100644 --- a/pkg/components/velero/azure/azure.go +++ b/pkg/components/velero/azure/azure.go @@ -149,7 +149,7 @@ func (c *Configuration) Validate() hcl.Diagnostics { // Since nested blocks in hcl2 does not support default values during DecodeBody, // we need to set the default value here, rather than adding diagnostics. // Once PR https://github.com/hashicorp/hcl2/pull/120 is released, this value can be set in - // newComponent() and diagnostic can be added. + // NewConfig() and diagnostic can be added. defaultAPITimeout := "10m" if c.VolumeSnapshotLocation == nil { c.VolumeSnapshotLocation = &VolumeSnapshotLocation{ diff --git a/pkg/components/velero/component.go b/pkg/components/velero/component.go index e198539a1..18e2be9ac 100644 --- a/pkg/components/velero/component.go +++ b/pkg/components/velero/component.go @@ -38,7 +38,7 @@ const ( // init registers velero component to components list, so it shows up as available to install func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } // component represents component configuration data @@ -69,8 +69,10 @@ type provider interface { Validate() hcl.Diagnostics } -// newComponent creates new velero component struct with default values initialized -func newComponent() *component { +// NewConfig returns new Velero component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{ Namespace: "velero", Metrics: &Metrics{ diff --git a/pkg/components/velero/component_test.go b/pkg/components/velero/component_test.go index 5d695e11c..fee1fa586 100644 --- a/pkg/components/velero/component_test.go +++ b/pkg/components/velero/component_test.go @@ -23,7 +23,7 @@ import ( ) func TestEmptyConfig(t *testing.T) { - c := newComponent() + c := NewConfig() emptyConfig := hcl.EmptyBody() evalContext := hcl.EvalContext{} @@ -54,7 +54,7 @@ component "velero" { } ` - component := newComponent() + component := NewConfig() body, diagnostics := util.GetComponentBody(configHCL, Name) if diagnostics != nil { @@ -99,7 +99,7 @@ component "velero" { } ` - component := newComponent() + component := NewConfig() body, diagnostics := util.GetComponentBody(configHCL, Name) if diagnostics != nil { @@ -130,7 +130,7 @@ component "velero" { } ` - component := newComponent() + component := NewConfig() body, d := util.GetComponentBody(configHCL, Name) if d != nil { @@ -147,7 +147,7 @@ func TestRenderManifestNoProviderConfigured(t *testing.T) { component "velero" {} ` - component := newComponent() + component := NewConfig() body, d := util.GetComponentBody(configHCL, Name) if d != nil { @@ -174,7 +174,7 @@ component "velero" { } ` - component := newComponent() + component := NewConfig() body, d := util.GetComponentBody(configHCL, Name) if d != nil { diff --git a/pkg/components/web-ui/component.go b/pkg/components/web-ui/component.go index 9faeedfb7..422ba2209 100644 --- a/pkg/components/web-ui/component.go +++ b/pkg/components/web-ui/component.go @@ -35,7 +35,7 @@ const ( //nolint:gochecknoinits func init() { - components.Register(Name, newComponent()) + components.Register(Name, NewConfig()) } type oidc struct { @@ -50,7 +50,10 @@ type component struct { OIDC *oidc `hcl:"oidc,block"` } -func newComponent() *component { +// NewConfig returns new Web UI component configuration with default values set. +// +//nolint:golint +func NewConfig() *component { return &component{ Namespace: "lokomotive-system", }