Skip to content

Commit 34d6562

Browse files
Frostmanedipascale
authored andcommitted
chore: cleanup server/external ignition gen
Signed-off-by: Sergei Lukianov <me@slukjanov.name>
1 parent 643b631 commit 34d6562

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

pkg/hhfab/vlabrunner.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ import (
3939
coreapi "k8s.io/api/core/v1"
4040
)
4141

42-
//go:embed vlab_butane.tmpl.yaml
42+
//go:embed vlab_server_butane.tmpl.yaml
4343
var serverButaneTmpl string
4444

45-
//go:embed vlab_frr_butane.tmpl.yaml
46-
var frrButaneTmpl string
45+
//go:embed vlab_external_butane.tmpl.yaml
46+
var externalButaneTmpl string
4747

4848
//go:embed hhnet.sh
4949
var hhnet []byte
@@ -68,6 +68,7 @@ const (
6868
VLABCmdLess = "less"
6969
VLABCmdExpect = "expect"
7070

71+
VLABButane = "butane.yaml"
7172
VLABIgnition = "ignition.json"
7273

7374
VLABKubeConfig = "kubeconfig"
@@ -311,21 +312,30 @@ func (c *Config) VLABRun(ctx context.Context, vlab *VLAB, opts VLABRunOpts) erro
311312
}
312313

313314
if vm.Type == VMTypeServer {
314-
ign, err := serverIgnition(c.Fab, vm)
315+
but, ign, err := serverIgnition(c.Fab, vm)
315316
if err != nil {
316-
return fmt.Errorf("generating ignition: %w", err)
317+
return fmt.Errorf("generating server ignition: %w", err)
318+
}
319+
320+
if but != "" {
321+
if err := os.WriteFile(filepath.Join(vmDir, VLABButane), ign, 0o600); err != nil {
322+
return fmt.Errorf("writing server butane: %w", err)
323+
}
317324
}
318325

319326
if err := os.WriteFile(filepath.Join(vmDir, VLABIgnition), ign, 0o600); err != nil {
320-
return fmt.Errorf("writing ignition: %w", err)
327+
return fmt.Errorf("writing server ignition: %w", err)
321328
}
322329
} else if vm.Type == VMTypeExternal {
323330
but, ign, err := externalIgnition(c.Fab, vm, vlab.Externals)
324331
if err != nil {
325332
return fmt.Errorf("generating external ignition: %w", err)
326333
}
327-
if err := os.WriteFile(filepath.Join(vmDir, "butane.yaml"), []byte(but), 0o600); err != nil {
328-
return fmt.Errorf("writing external butane: %w", err)
334+
335+
if but != "" {
336+
if err := os.WriteFile(filepath.Join(vmDir, VLABButane), ign, 0o600); err != nil {
337+
return fmt.Errorf("writing external butane: %w", err)
338+
}
329339
}
330340

331341
if err := os.WriteFile(filepath.Join(vmDir, VLABIgnition), ign, 0o600); err != nil {
@@ -771,15 +781,15 @@ func execHelper(ctx context.Context, baseDir string, args []string) error {
771781
}
772782

773783
func externalIgnition(fab fabapi.Fabricator, vm VM, ext ExternalsCfg) (string, []byte, error) {
774-
but, err := tmplutil.FromTemplate("butane", frrButaneTmpl, map[string]any{
784+
but, err := tmplutil.FromTemplate("butane-external", externalButaneTmpl, map[string]any{
775785
"Hostname": vm.Name,
776786
"PasswordHash": fab.Spec.Config.Control.DefaultUser.PasswordHash,
777787
"AuthorizedKeys": fab.Spec.Config.Control.DefaultUser.AuthorizedKeys,
778788
"ExternalVRFs": ext.VRFs,
779789
"ExternalNICs": ext.NICs,
780790
})
781791
if err != nil {
782-
return "", nil, fmt.Errorf("butane: %w", err)
792+
return but, nil, fmt.Errorf("butane: %w", err)
783793
}
784794

785795
ign, err := butaneutil.Translate(but)
@@ -790,22 +800,22 @@ func externalIgnition(fab fabapi.Fabricator, vm VM, ext ExternalsCfg) (string, [
790800
return but, ign, nil
791801
}
792802

793-
func serverIgnition(fab fabapi.Fabricator, vm VM) ([]byte, error) {
794-
but, err := tmplutil.FromTemplate("butane", serverButaneTmpl, map[string]any{
803+
func serverIgnition(fab fabapi.Fabricator, vm VM) (string, []byte, error) {
804+
but, err := tmplutil.FromTemplate("butane-server", serverButaneTmpl, map[string]any{
795805
"Hostname": vm.Name,
796806
"PasswordHash": fab.Spec.Config.Control.DefaultUser.PasswordHash,
797807
"AuthorizedKeys": fab.Spec.Config.Control.DefaultUser.AuthorizedKeys,
798808
})
799809
if err != nil {
800-
return nil, fmt.Errorf("butane: %w", err)
810+
return but, nil, fmt.Errorf("butane: %w", err)
801811
}
802812

803813
ign, err := butaneutil.Translate(but)
804814
if err != nil {
805-
return nil, fmt.Errorf("translating butane: %w", err)
815+
return but, nil, fmt.Errorf("translating butane: %w", err)
806816
}
807817

808-
return ign, nil
818+
return but, ign, nil
809819
}
810820

811821
func (c *Config) vmPostProcess(ctx context.Context, vlab *VLAB, d *artificer.Downloader, vm VM, opts VLABRunOpts) error {

0 commit comments

Comments
 (0)