Skip to content

Commit 5823430

Browse files
authored
Fix loading configuration from YAML (#78)
1 parent 7c09177 commit 5823430

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

chart/templates/_config.tpl

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{{ define "config" }}
22
{{- $cfg := .Values.config -}}
3-
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
4-
kind: ControllerManagerConfig
53
health:
64
healthProbeBindAddress: :8081
75
leaderElection:

cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() {
4040
if err != nil {
4141
logger.Fatal("failed to open config file", zap.Error(err))
4242
}
43-
if err := yaml.NewDecoder(file).Decode(config); err != nil {
43+
if err := yaml.NewDecoder(file).Decode(&config); err != nil {
4444
logger.Fatal("failed to parse config file", zap.Error(err))
4545
}
4646
}

dev/config.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
2-
kind: ControllerManagerConfig
31
health:
42
healthProbeBindAddress: :8081
53
leaderElection:

internal/config/v1/config.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,70 @@ import (
66

77
// Config is the Schema for the configs API
88
type Config struct {
9-
ControllerConfig `json:",inline"`
10-
Selector IngressSelector `json:"selector"`
11-
Integrations IntegrationConfigs `json:"integrations"`
9+
ControllerConfig `yaml:",inline"`
10+
Selector IngressSelector `yaml:"selector"`
11+
Integrations IntegrationConfigs `yaml:"integrations"`
1212
}
1313

1414
//-------------------------------------------------------------------------------------------------
1515

1616
// ControllerConfig provides configuration for the controller.
1717
type ControllerConfig struct {
18-
Health HealthConfig `json:"health,omitempty"`
19-
LeaderElection LeaderElectionConfig `json:"leaderElection,omitempty"`
20-
Metrics MetricsConfig `json:"metrics,omitempty"`
18+
Health HealthConfig `yaml:"health,omitempty"`
19+
LeaderElection LeaderElectionConfig `yaml:"leaderElection,omitempty"`
20+
Metrics MetricsConfig `yaml:"metrics,omitempty"`
2121
}
2222

2323
// HealthConfig provides configuration for the controller health checks.
2424
type HealthConfig struct {
25-
HealthProbeBindAddress string `json:"healthProbeBindAddress,omitempty"`
25+
HealthProbeBindAddress string `yaml:"healthProbeBindAddress,omitempty"`
2626
}
2727

2828
// LeaderElectionConfig provides configuration for the leader election.
2929
type LeaderElectionConfig struct {
30-
LeaderElect bool `json:"leaderElect,omitempty"`
31-
ResourceName string `json:"resourceName,omitempty"`
32-
ResourceNamespace string `json:"resourceNamespace,omitempty"`
30+
LeaderElect bool `yaml:"leaderElect,omitempty"`
31+
ResourceName string `yaml:"resourceName,omitempty"`
32+
ResourceNamespace string `yaml:"resourceNamespace,omitempty"`
3333
}
3434

3535
// MetricsConfig provides configuration for the controller metrics.
3636
type MetricsConfig struct {
37-
BindAddress string `json:"bindAddress,omitempty"`
37+
BindAddress string `yaml:"bindAddress,omitempty"`
3838
}
3939

4040
//-------------------------------------------------------------------------------------------------
4141

4242
// IngressSelector can be used to limit operations to ingresses with a specific class.
4343
type IngressSelector struct {
44-
IngressClass *string `json:"ingressClass,omitempty"`
44+
IngressClass *string `yaml:"ingressClass,omitempty"`
4545
}
4646

4747
// IntegrationConfigs describes the configurations for all integrations.
4848
type IntegrationConfigs struct {
49-
ExternalDNS *ExternalDNSIntegrationConfig `json:"externalDNS"`
50-
CertManager *CertManagerIntegrationConfig `json:"certManager"`
49+
ExternalDNS *ExternalDNSIntegrationConfig `yaml:"externalDNS"`
50+
CertManager *CertManagerIntegrationConfig `yaml:"certManager"`
5151
}
5252

5353
// ExternalDNSIntegrationConfig describes the configuration for the external-dns integration.
5454
// Exactly one of target and target IPs should be set.
5555
type ExternalDNSIntegrationConfig struct {
56-
TargetService *ServiceRef `json:"targetService,omitempty"`
57-
TargetIPs []string `json:"targetIPs,omitempty"`
56+
TargetService *ServiceRef `yaml:"targetService,omitempty"`
57+
TargetIPs []string `yaml:"targetIPs,omitempty"`
5858
}
5959

6060
// CertManagerIntegrationConfig describes the configuration for the cert-manager integration.
6161
type CertManagerIntegrationConfig struct {
62-
Template v1.Certificate `json:"certificateTemplate"`
62+
Template v1.Certificate `yaml:"certificateTemplate"`
6363
}
6464

6565
// ServiceRef uniquely describes a Kubernetes service.
6666
type ServiceRef struct {
67-
Name string `json:"name"`
68-
Namespace string `json:"namespace"`
67+
Name string `yaml:"name"`
68+
Namespace string `yaml:"namespace"`
6969
}
7070

7171
// IssuerRef uniquely references a cert-manager issuer.
7272
type IssuerRef struct {
73-
Kind string `json:"kind"`
74-
Name string `json:"name"`
73+
Kind string `yaml:"kind"`
74+
Name string `yaml:"name"`
7575
}

0 commit comments

Comments
 (0)