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

Commit e55661c

Browse files
author
Imran Pochi
committed
baremetal: add CLC snippets in configuration
This commit adds functionality to add CLC snippets to the Baremetal Lokomotive configuration. Updates the existing CLC snippet test to also cover baremetal platform. Updates the Baremetal configuration reference documentation to include the new variable `clc_snippets`. Signed-off-by: Imran Pochi <imran@kinvolk.io>
1 parent 33a1227 commit e55661c

File tree

6 files changed

+113
-32
lines changed

6 files changed

+113
-32
lines changed

ci/baremetal/baremetal-cluster.lokocfg.envsubst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ cluster "bare-metal" {
4444
conntrack_max_per_core = 65000
4545

4646
install_to_smallest_disk = true
47+
48+
clc_snippets = {
49+
"node1" = [
50+
file("./clc-snippet.yaml"),
51+
]
52+
"node2" = [
53+
file("./clc-snippet.yaml"),
54+
]
55+
"node3" = [
56+
file("./clc-snippet.yaml"),
57+
]
58+
}
4759
}
4860

4961
component "inspektor-gadget" {}

docs/configuration-reference/platforms/baremetal.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ cluster "bare-metal" {
5555
5656
cached_install = "true"
5757
58+
clc_snippets = {
59+
"<name_of_controller_or_worker>" = [
60+
file("./clc-snippet-1.yaml"),
61+
]
62+
"<name_of_controller_or_worker>" = [
63+
file("./clc-snippet-2.yaml"),
64+
]
65+
"<name_of_controller_or_worker>" = [
66+
file("./clc-snippet-3.yaml"),
67+
]
68+
5869
matchbox_ca_path = var.matchbox_ca_path
5970
6071
matchbox_client_cert_path = var.matchbox_client_cert_path

pkg/platform/baremetal/baremetal.go

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,38 @@ import (
3131
)
3232

3333
type config struct {
34-
AssetDir string `hcl:"asset_dir"`
35-
CachedInstall string `hcl:"cached_install,optional"`
36-
ClusterName string `hcl:"cluster_name"`
37-
ControllerDomains []string `hcl:"controller_domains"`
38-
ControllerMacs []string `hcl:"controller_macs"`
39-
ControllerNames []string `hcl:"controller_names"`
40-
DisableSelfHostedKubelet bool `hcl:"disable_self_hosted_kubelet,optional"`
41-
K8sDomainName string `hcl:"k8s_domain_name"`
42-
MatchboxCAPath string `hcl:"matchbox_ca_path"`
43-
MatchboxClientCertPath string `hcl:"matchbox_client_cert_path"`
44-
MatchboxClientKeyPath string `hcl:"matchbox_client_key_path"`
45-
MatchboxEndpoint string `hcl:"matchbox_endpoint"`
46-
MatchboxHTTPEndpoint string `hcl:"matchbox_http_endpoint"`
47-
NetworkMTU int `hcl:"network_mtu,optional"`
48-
OSChannel string `hcl:"os_channel,optional"`
49-
OSVersion string `hcl:"os_version,optional"`
50-
SSHPubKeys []string `hcl:"ssh_pubkeys"`
51-
WorkerNames []string `hcl:"worker_names"`
52-
WorkerMacs []string `hcl:"worker_macs"`
53-
WorkerDomains []string `hcl:"worker_domains"`
54-
Labels map[string]string `hcl:"labels,optional"`
55-
OIDC *oidc.Config `hcl:"oidc,block"`
56-
EnableTLSBootstrap bool `hcl:"enable_tls_bootstrap,optional"`
57-
EncryptPodTraffic bool `hcl:"encrypt_pod_traffic,optional"`
58-
IgnoreX509CNCheck bool `hcl:"ignore_x509_cn_check,optional"`
59-
ConntrackMaxPerCore int `hcl:"conntrack_max_per_core,optional"`
60-
InstallToSmallestDisk bool `hcl:"install_to_smallest_disk,optional"`
61-
InstallDisk string `hcl:"install_disk,optional"`
62-
KernelArgs []string `hcl:"kernel_args,optional"`
63-
DownloadProtocol string `hcl:"download_protocol,optional"`
64-
NetworkIPAutodetectionMethod string `hcl:"network_ip_autodetection_method,optional"`
34+
AssetDir string `hcl:"asset_dir"`
35+
CachedInstall string `hcl:"cached_install,optional"`
36+
ClusterName string `hcl:"cluster_name"`
37+
ControllerDomains []string `hcl:"controller_domains"`
38+
ControllerMacs []string `hcl:"controller_macs"`
39+
ControllerNames []string `hcl:"controller_names"`
40+
DisableSelfHostedKubelet bool `hcl:"disable_self_hosted_kubelet,optional"`
41+
K8sDomainName string `hcl:"k8s_domain_name"`
42+
MatchboxCAPath string `hcl:"matchbox_ca_path"`
43+
MatchboxClientCertPath string `hcl:"matchbox_client_cert_path"`
44+
MatchboxClientKeyPath string `hcl:"matchbox_client_key_path"`
45+
MatchboxEndpoint string `hcl:"matchbox_endpoint"`
46+
MatchboxHTTPEndpoint string `hcl:"matchbox_http_endpoint"`
47+
NetworkMTU int `hcl:"network_mtu,optional"`
48+
OSChannel string `hcl:"os_channel,optional"`
49+
OSVersion string `hcl:"os_version,optional"`
50+
SSHPubKeys []string `hcl:"ssh_pubkeys"`
51+
WorkerNames []string `hcl:"worker_names"`
52+
WorkerMacs []string `hcl:"worker_macs"`
53+
WorkerDomains []string `hcl:"worker_domains"`
54+
Labels map[string]string `hcl:"labels,optional"`
55+
OIDC *oidc.Config `hcl:"oidc,block"`
56+
EnableTLSBootstrap bool `hcl:"enable_tls_bootstrap,optional"`
57+
EncryptPodTraffic bool `hcl:"encrypt_pod_traffic,optional"`
58+
IgnoreX509CNCheck bool `hcl:"ignore_x509_cn_check,optional"`
59+
ConntrackMaxPerCore int `hcl:"conntrack_max_per_core,optional"`
60+
InstallToSmallestDisk bool `hcl:"install_to_smallest_disk,optional"`
61+
InstallDisk string `hcl:"install_disk,optional"`
62+
KernelArgs []string `hcl:"kernel_args,optional"`
63+
DownloadProtocol string `hcl:"download_protocol,optional"`
64+
NetworkIPAutodetectionMethod string `hcl:"network_ip_autodetection_method,optional"`
65+
CLCSnippets map[string][]string `hcl:"clc_snippets,optional"`
6566
KubeAPIServerExtraFlags []string
6667
}
6768

@@ -231,6 +232,7 @@ func createTerraformConfigFile(cfg *config, terraformPath string) error {
231232
KernelArgs []string
232233
DownloadProtocol string
233234
NetworkIPAutodetectionMethod string
235+
CLCSnippets map[string][]string
234236
}{
235237
CachedInstall: cfg.CachedInstall,
236238
ClusterName: cfg.ClusterName,
@@ -262,6 +264,7 @@ func createTerraformConfigFile(cfg *config, terraformPath string) error {
262264
KernelArgs: cfg.KernelArgs,
263265
DownloadProtocol: cfg.DownloadProtocol,
264266
NetworkIPAutodetectionMethod: cfg.NetworkIPAutodetectionMethod,
267+
CLCSnippets: cfg.CLCSnippets,
265268
}
266269

267270
if err := t.Execute(f, terraformCfg); err != nil {
@@ -304,5 +307,25 @@ func (c *config) checkValidConfig() hcl.Diagnostics {
304307
diagnostics = append(diagnostics, diags...)
305308
}
306309

310+
for key, list := range c.CLCSnippets {
311+
if key == "" || len(list) == 0 {
312+
diagnostics = append(diagnostics, &hcl.Diagnostic{
313+
Severity: hcl.DiagError,
314+
Summary: "key/value for clc_snippets map can't be empty",
315+
Detail: fmt.Sprintf("either key or value for clc_snippets is empty: %q : %v", key, list),
316+
})
317+
}
318+
319+
for _, data := range list {
320+
if data == "" {
321+
diagnostics = append(diagnostics, &hcl.Diagnostic{
322+
Severity: hcl.DiagError,
323+
Summary: "Values list for clc_snippets cannot contain an empty element",
324+
Detail: fmt.Sprintf("found empty element in the key value pair: %q : %v", key, list),
325+
})
326+
}
327+
}
328+
}
329+
307330
return diagnostics
308331
}

pkg/platform/baremetal/baremetal_internal_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ func TestConfigurationIsInvalidWhen(t *testing.T) {
5656
"conntrack_max_per_core_is_negative": func(c *config) {
5757
c.ConntrackMaxPerCore = -1
5858
},
59+
"clc_snippets_key_is_empty": func(c *config) {
60+
c.CLCSnippets = map[string][]string{
61+
"": {"clc_snippet_1", "clc_snippet_2"},
62+
}
63+
},
64+
"clc_snippets_value_is_empty": func(c *config) {
65+
c.CLCSnippets = map[string][]string{
66+
"node1": {""},
67+
}
68+
},
69+
"at_least_one_clc_snippets_value_is_empty": func(c *config) {
70+
c.CLCSnippets = map[string][]string{
71+
"node1": {"clc_snippet_1", "", "clc_snippet_3"},
72+
}
73+
},
5974
}
6075

6176
for n, c := range cases {
@@ -95,6 +110,11 @@ func TestConfigurationIsValidWhen(t *testing.T) {
95110
"download_protocol_used_is_https": func(c *config) {
96111
c.DownloadProtocol = "https"
97112
},
113+
"clc_snippets_has_both_key_and_value_populated": func(c *config) {
114+
c.CLCSnippets = map[string][]string{
115+
"node1": {"clc_snippet_1", "clc_snippet_2"},
116+
}
117+
},
98118
}
99119

100120
for n, c := range cases {

pkg/platform/baremetal/template.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ module "bare-metal-{{.ClusterName}}" {
8888
download_protocol = "{{ .DownloadProtocol }}"
8989
9090
network_ip_autodetection_method = "{{ .NetworkIPAutodetectionMethod }}"
91+
92+
{{- if .CLCSnippets}}
93+
clc_snippets = {
94+
{{- range $nodeName, $clcSnippetList := .CLCSnippets }}
95+
"{{ $nodeName }}" = [
96+
{{- range $clcSnippet := $clcSnippetList }}
97+
<<EOF
98+
{{ $clcSnippet }}
99+
EOF
100+
,
101+
{{- end }}
102+
]
103+
{{- end }}
104+
}
105+
{{- end }}
91106
}
92107
93108
terraform {

test/system/clc_snippets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// +build aws aws_edge packet
15+
// +build aws aws_edge packet baremetal
1616
// +build e2e
1717

1818
//nolint:dupl

0 commit comments

Comments
 (0)