Skip to content

Commit 81df387

Browse files
committed
docs: generate load balancer env reference
1 parent c07966f commit 81df387

File tree

7 files changed

+120
-31
lines changed

7 files changed

+120
-31
lines changed

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ linters:
8787
- linters:
8888
- godot
8989
path: internal/annotation/load_balancer.go
90+
- linters:
91+
- godot
92+
path: internal/config/load_balancer_envs.go
9093
- linters:
9194
- errcheck
9295
- gosec

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ repos:
6464
require_serial: false
6565
additional_dependencies: [prettier@3.7.4]
6666
files: \.(md|ya?ml)$
67-
exclude: ^(CHANGELOG.md|chart/templates/.*|chart/.snapshots/.*|docs/reference/load_balancer_annotations\.md)$
67+
exclude: ^(CHANGELOG.md|chart/templates/.*|chart/.snapshots/.*|docs/reference/load_balancer_.*\.md|)$
6868

6969
- repo: local
7070
hooks:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Load Balancer Environment Variables
2+
3+
This page contains all environment variables, which can be specified to configure the Load Balancer controller of HCCM. Most of them are used to set global defaults.
4+
5+
- Enums are depicted in the `Type` column and possible options are separated via the pipe symbol `|`.
6+
7+
| Annotation | Type | Default | Description |
8+
| --- | --- | --- | --- |
9+
| `HCLOUD_LOAD_BALANCERS_DISABLE_IPV6` | `bool` | `false` | Disables the use of IPv6 for the Load Balancer by default. |
10+
| `HCLOUD_LOAD_BALANCERS_DISABLE_PRIVATE_INGRESS` | `bool` | `false` | Disables the use of the private network for ingress by default. |
11+
| `HCLOUD_LOAD_BALANCERS_ENABLED` | `bool` | `true` | Controls whether the load balancer controller of HCCM should run. |
12+
| `HCLOUD_LOAD_BALANCERS_LOCATION` | `string` | `-` | Specifies the default location where the Load Balancer will be created in. Mutually exclusive with hcloudLoadBalancersNetworkZone. |
13+
| `HCLOUD_LOAD_BALANCERS_NETWORK_ZONE` | `string` | `-` | Specifies the default network zone where the Load Balancer will be created in. Mutually exclusive with hcloudLoadBalancersLocation. |
14+
| `HCLOUD_LOAD_BALANCERS_USE_PRIVATE_IP` | `bool` | `false` | Configures the Load Balancer to use the private IP for Load Balancer server targets by default. |

internal/config/config.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,14 @@ const (
3434
hcloudNetworkDisableAttachedCheck = "HCLOUD_NETWORK_DISABLE_ATTACHED_CHECK"
3535
hcloudNetworkRoutesEnabled = "HCLOUD_NETWORK_ROUTES_ENABLED"
3636

37-
hcloudLoadBalancersAlgorithmType = "HCLOUD_LOAD_BALANCERS_ALGORITHM_TYPE"
38-
hcloudLoadBalancersDisableIPv6 = "HCLOUD_LOAD_BALANCERS_DISABLE_IPV6"
39-
hcloudLoadBalancersDisablePrivateIngress = "HCLOUD_LOAD_BALANCERS_DISABLE_PRIVATE_INGRESS"
40-
hcloudLoadBalancersDisablePublicNetwork = "HCLOUD_LOAD_BALANCERS_DISABLE_PUBLIC_NETWORK"
41-
hcloudLoadBalancersEnabled = "HCLOUD_LOAD_BALANCERS_ENABLED"
42-
hcloudLoadBalancersHealthCheckInterval = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_INTERVAL"
43-
hcloudLoadBalancersHealthCheckRetries = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_RETRIES"
44-
hcloudLoadBalancersHealthCheckTimeout = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_TIMEOUT"
45-
hcloudLoadBalancersLocation = "HCLOUD_LOAD_BALANCERS_LOCATION"
46-
hcloudLoadBalancersNetworkZone = "HCLOUD_LOAD_BALANCERS_NETWORK_ZONE"
47-
hcloudLoadBalancersPrivateSubnetIPRange = "HCLOUD_LOAD_BALANCERS_PRIVATE_SUBNET_IP_RANGE"
48-
hcloudLoadBalancersType = "HCLOUD_LOAD_BALANCERS_TYPE"
49-
hcloudLoadBalancersUsePrivateIP = "HCLOUD_LOAD_BALANCERS_USE_PRIVATE_IP"
50-
hcloudLoadBalancersUsesProxyProtocol = "HCLOUD_LOAD_BALANCERS_USES_PROXYPROTOCOL"
37+
hcloudLoadBalancersAlgorithmType = "HCLOUD_LOAD_BALANCERS_ALGORITHM_TYPE"
38+
hcloudLoadBalancersDisablePublicNetwork = "HCLOUD_LOAD_BALANCERS_DISABLE_PUBLIC_NETWORK"
39+
hcloudLoadBalancersHealthCheckInterval = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_INTERVAL"
40+
hcloudLoadBalancersHealthCheckRetries = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_RETRIES"
41+
hcloudLoadBalancersHealthCheckTimeout = "HCLOUD_LOAD_BALANCERS_HEALTH_CHECK_TIMEOUT"
42+
hcloudLoadBalancersPrivateSubnetIPRange = "HCLOUD_LOAD_BALANCERS_PRIVATE_SUBNET_IP_RANGE"
43+
hcloudLoadBalancersType = "HCLOUD_LOAD_BALANCERS_TYPE"
44+
hcloudLoadBalancersUsesProxyProtocol = "HCLOUD_LOAD_BALANCERS_USES_PROXYPROTOCOL"
5145

5246
hcloudMetricsEnabled = "HCLOUD_METRICS_ENABLED"
5347
hcloudMetricsAddress = "HCLOUD_METRICS_ADDRESS"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package config
2+
3+
const (
4+
// hcloudLoadBalancersEnabled controls whether the load balancer controller of HCCM should run.
5+
//
6+
// Type: bool
7+
// Default: true
8+
hcloudLoadBalancersEnabled = "HCLOUD_LOAD_BALANCERS_ENABLED"
9+
10+
// hcloudLoadBalancersLocation specifies the default location where the Load Balancer will be
11+
// created in.
12+
//
13+
// Mutually exclusive with hcloudLoadBalancersNetworkZone.
14+
//
15+
// Type: string
16+
hcloudLoadBalancersLocation = "HCLOUD_LOAD_BALANCERS_LOCATION"
17+
18+
// hcloudLoadBalancersNetworkZone specifies the default network zone where the Load Balancer will be
19+
// created in.
20+
//
21+
// Mutually exclusive with hcloudLoadBalancersLocation.
22+
//
23+
// Type: string
24+
hcloudLoadBalancersNetworkZone = "HCLOUD_LOAD_BALANCERS_NETWORK_ZONE"
25+
26+
// hcloudLoadBalancersDisablePrivateIngress disables the use of the private network for ingress by default.
27+
//
28+
// Type: bool
29+
// Default: false
30+
hcloudLoadBalancersDisablePrivateIngress = "HCLOUD_LOAD_BALANCERS_DISABLE_PRIVATE_INGRESS"
31+
32+
// hcloudLoadBalancersUsePrivateIP configures the Load Balancer to use the private IP for
33+
// Load Balancer server targets by default.
34+
//
35+
// Type: bool
36+
// Default: false
37+
hcloudLoadBalancersUsePrivateIP = "HCLOUD_LOAD_BALANCERS_USE_PRIVATE_IP"
38+
39+
// hcloudLoadBalancersDisableIPv6 disables the use of IPv6 for the Load Balancer by default.
40+
//
41+
// Type: bool
42+
// Default: false
43+
hcloudLoadBalancersDisableIPv6 = "HCLOUD_LOAD_BALANCERS_DISABLE_IPV6"
44+
)

tools/doc_generation.go

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,16 @@ func (t *Table) FromAST(node ast.Node) (*Table, error) {
115115
return t, nil
116116
}
117117

118-
func (t *Table) String() string {
118+
func (t *Table) String(hasReadOnlyColumn bool) string {
119119
tableStr := strings.Builder{}
120120

121-
tableStr.WriteString("| Annotation | Type | Default | Read-only | Description |\n")
122-
tableStr.WriteString("| --- | --- | --- | --- | --- |\n")
121+
if hasReadOnlyColumn {
122+
tableStr.WriteString("| Annotation | Type | Default | Read-only | Description |\n")
123+
tableStr.WriteString("| --- | --- | --- | --- | --- |\n")
124+
} else {
125+
tableStr.WriteString("| Annotation | Type | Default | Description |\n")
126+
tableStr.WriteString("| --- | --- | --- | --- |\n")
127+
}
123128

124129
annotations := slices.Sorted(maps.Keys(t.table))
125130

@@ -142,16 +147,28 @@ func (t *Table) String() string {
142147
readOnlyVal = "Yes"
143148
}
144149

145-
tableStr.WriteString(
146-
fmt.Sprintf(
147-
"| `%s` | `%s` | `%s` | `%s` | %s |\n",
148-
annotation,
149-
typeVal,
150-
defaultVal,
151-
readOnlyVal,
152-
t.table[annotation].Description,
153-
),
154-
)
150+
if hasReadOnlyColumn {
151+
tableStr.WriteString(
152+
fmt.Sprintf(
153+
"| `%s` | `%s` | `%s` | `%s` | %s |\n",
154+
annotation,
155+
typeVal,
156+
defaultVal,
157+
readOnlyVal,
158+
t.table[annotation].Description,
159+
),
160+
)
161+
} else {
162+
tableStr.WriteString(
163+
fmt.Sprintf(
164+
"| `%s` | `%s` | `%s` | %s |\n",
165+
annotation,
166+
typeVal,
167+
defaultVal,
168+
t.table[annotation].Description,
169+
),
170+
)
171+
}
155172
}
156173

157174
return tableStr.String()
@@ -211,7 +228,7 @@ func getValueFromLine(line, key string) string {
211228
return ""
212229
}
213230

214-
func run(templatePath string, annotationsPath string, outputPath string) error {
231+
func run(templatePath string, annotationsPath string, outputPath string, hasReadOnlyColumn bool) error {
215232
// Read template file
216233
tmplStr, err := os.ReadFile(templatePath)
217234
if err != nil {
@@ -236,7 +253,7 @@ func run(templatePath string, annotationsPath string, outputPath string) error {
236253
return fmt.Errorf("error parsing template: %w", err)
237254
}
238255

239-
tmplData := Template{AnnotationsTable: table.String()}
256+
tmplData := Template{AnnotationsTable: table.String(hasReadOnlyColumn)}
240257
var buf bytes.Buffer
241258
if err := tmpl.Execute(&buf, tmplData); err != nil {
242259
return fmt.Errorf("error executing template: %w", err)
@@ -265,7 +282,17 @@ func main() {
265282
lbAnnotationsPath := "../internal/annotation/load_balancer.go"
266283
lbOutputPath := "../docs/reference/load_balancer_annotations.md"
267284

268-
if err := run(lbTemplatePath, lbAnnotationsPath, lbOutputPath); err != nil {
285+
// Generate Load Balancer env documentation
286+
lbEnvTemplatePath := "./load_balancer_envs.md.tmpl"
287+
lbEnvPath := "../internal/config/load_balancer_envs.go"
288+
lbEnvOutputPath := "../docs/reference/load_balancer_envs.md"
289+
290+
if err := run(lbTemplatePath, lbAnnotationsPath, lbOutputPath, true); err != nil {
291+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
292+
os.Exit(1)
293+
}
294+
295+
if err := run(lbEnvTemplatePath, lbEnvPath, lbEnvOutputPath, false); err != nil {
269296
fmt.Fprintf(os.Stderr, "error: %v\n", err)
270297
os.Exit(1)
271298
}

tools/load_balancer_envs.md.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Load Balancer Environment Variables
2+
3+
This page contains all environment variables, which can be specified to configure the Load Balancer controller of HCCM. Most of them are used to set global defaults.
4+
5+
- Enums are depicted in the `Type` column and possible options are separated via the pipe symbol `|`.
6+
7+
{{.AnnotationsTable}}

0 commit comments

Comments
 (0)