Skip to content

Commit

Permalink
Support passing control node mgmt link annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Oct 9, 2024
1 parent 7c4b58b commit 95f3849
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 33 deletions.
20 changes: 14 additions & 6 deletions cmd/hhfab/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
FlagNameTLSSAN = "tls-san"
FlagNameDev = "dev"
FlagIncludeONIE = "include-onie"
FlagControlNodeMgmtLink = "control-node-mgmt-link"
FlagNameFabricMode = "fabric-mode"
FlagNameCount = "count"
FlagNameKillStale = "kill-stale"
Expand Down Expand Up @@ -370,6 +371,12 @@ func Run(ctx context.Context) error {
Usage: "import host repo/prefix and creds from docker config as an upstream registry mode and config (creds will be stored plain text)",
EnvVars: []string{"HHFAB_IMPORT_HOST_UPSTREAM"},
},
&cli.StringFlag{
Name: FlagControlNodeMgmtLink,
Hidden: true,
Usage: "control node management link (for pci passthrough for VLAB-only)",
EnvVars: []string{"HHFAB_CONTROL_NODE_MGMT_LINK"},
},
),
Before: before(false),
Action: func(c *cli.Context) error {
Expand All @@ -382,12 +389,13 @@ func Run(ctx context.Context) error {
Wiring: c.StringSlice(FlagNameWiring),
ImportHostUpstream: c.Bool(FlagNameImportHostUpstream),
InitConfigInput: fab.InitConfigInput{
FabricMode: meta.FabricMode(c.String(FlagNameFabricMode)),
TLSSAN: c.StringSlice(FlagNameTLSSAN),
DefaultPasswordHash: c.String(FlagNameDefaultPasswordHash),
DefaultAuthorizedKeys: c.StringSlice(FlagNameDefaultAuthorizedKeys),
Dev: c.Bool(FlagNameDev),
IncludeONIE: c.Bool(FlagIncludeONIE),
FabricMode: meta.FabricMode(c.String(FlagNameFabricMode)),
TLSSAN: c.StringSlice(FlagNameTLSSAN),
DefaultPasswordHash: c.String(FlagNameDefaultPasswordHash),
DefaultAuthorizedKeys: c.StringSlice(FlagNameDefaultAuthorizedKeys),
Dev: c.Bool(FlagNameDev),
IncludeONIE: c.Bool(FlagIncludeONIE),
ControlNodeManagementLink: c.String(FlagControlNodeMgmtLink),
},
}); err != nil {
return fmt.Errorf("initializing: %w", err)
Expand Down
15 changes: 8 additions & 7 deletions pkg/fab/initconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const (
)

type InitConfigInput struct {
FabricMode meta.FabricMode
TLSSAN []string
DefaultPasswordHash string
DefaultAuthorizedKeys []string
Dev bool
IncludeONIE bool
RegUpstream *fabapi.ControlConfigRegistryUpstream
FabricMode meta.FabricMode
TLSSAN []string
DefaultPasswordHash string
DefaultAuthorizedKeys []string
Dev bool
IncludeONIE bool
RegUpstream *fabapi.ControlConfigRegistryUpstream
ControlNodeManagementLink string
}

func InitConfig(ctx context.Context, in InitConfigInput) ([]byte, error) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/fab/initconfig.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ kind: ControlNode
metadata:
name: control-1
namespace: fab
{{- if .ControlNodeManagementLink }}
annotations:
link.hhfab.githedgehog.com/enp2s1: {{ .ControlNodeManagementLink}}
{{- end }}
spec:
bootstrap:
disk: "/dev/sda" # disk to install OS on, e.g. "sda" or "nvme0n1"
Expand Down
72 changes: 52 additions & 20 deletions pkg/fab/initconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@ import (

func TestInitConfig(t *testing.T) {
ctx := context.Background()
expectedControls := []fabapi.ControlNode{
{
ObjectMeta: metav1.ObjectMeta{
Name: "control-1",
Namespace: comp.FabNamespace,
},
Spec: fabapi.ControlNodeSpec{
Bootstrap: fabapi.ControlNodeBootstrap{
Disk: "/dev/sda",
},
Management: fabapi.ControlNodeManagement{
Interface: "enp2s1",
},
External: fabapi.ControlNodeExternal{
Interface: "enp2s0",
IP: meta.PrefixDHCP,
},
},
},
}

for _, test := range []struct {
name string
Expand Down Expand Up @@ -236,8 +216,60 @@ func TestInitConfig(t *testing.T) {
},
},
},
{
name: "control-node-management-link",
in: fab.InitConfigInput{
ControlNodeManagementLink: "pci@0000:00:00.0",
},
expectedFab: fabapi.Fabricator{
ObjectMeta: metav1.ObjectMeta{
Name: comp.FabName,
Namespace: comp.FabNamespace,
},
Spec: fabapi.FabricatorSpec{
Config: fabapi.FabConfig{
Fabric: fabapi.FabricConfig{
DefaultSwitchUsers: map[string]fabapi.SwitchUser{
"admin": {
Role: "admin",
},
"op": {
Role: "operator",
},
},
},
},
},
},
},
} {
t.Run(test.name, func(t *testing.T) {
expectedControls := []fabapi.ControlNode{
{
ObjectMeta: metav1.ObjectMeta{
Name: "control-1",
Namespace: comp.FabNamespace,
},
Spec: fabapi.ControlNodeSpec{
Bootstrap: fabapi.ControlNodeBootstrap{
Disk: "/dev/sda",
},
Management: fabapi.ControlNodeManagement{
Interface: "enp2s1",
},
External: fabapi.ControlNodeExternal{
Interface: "enp2s0",
IP: meta.PrefixDHCP,
},
},
},
}
if test.in.ControlNodeManagementLink != "" {
expectedControls[0].Annotations = map[string]string{
"link.hhfab.githedgehog.com/enp2s1": test.in.ControlNodeManagementLink,
}
}

data, err := fab.InitConfig(ctx, test.in)
if test.err {
require.Error(t, err)
Expand Down

0 comments on commit 95f3849

Please sign in to comment.