Skip to content

Commit

Permalink
allow installation to external disks, configure multipathd and extra …
Browse files Browse the repository at this point in the history
…kernel arguments

fix typo in grub2-editenv

fixing issues for multipath config and kernel arguments

enable multipath in initrd
  • Loading branch information
ibrokethecloud committed Jul 24, 2024
1 parent 5ffebed commit e7db58f
Show file tree
Hide file tree
Showing 19 changed files with 3,895 additions and 3 deletions.
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rancher/mapper v0.0.0-20190814232720-058a8b7feb99
github.com/rancher/wharfie v0.6.5
<<<<<<< HEAD
github.com/rancher/yip v1.9.2
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
Expand All @@ -19,6 +20,16 @@ require (
golang.org/x/net v0.27.0
golang.org/x/sys v0.22.0
gopkg.in/ini.v1 v1.67.0
=======
github.com/sirupsen/logrus v1.9.2
github.com/stretchr/testify v1.9.0
github.com/tredoe/osutil v1.3.6
github.com/vishvananda/netlink v1.1.0
golang.org/x/crypto v0.14.0
golang.org/x/net v0.17.0
golang.org/x/sys v0.13.0
gopkg.in/ini.v1 v1.63.2
>>>>>>> a412288 (allow installation to external disks, configure multipathd and extra kernel arguments)
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.25.4
)
Expand Down
3 changes: 3 additions & 0 deletions package/harvester-os/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM ${BASE_OS_IMAGE}
ARG ARCH=amd64
RUN curl -sfL https://github.com/rancher/wharfie/releases/download/v0.6.5/wharfie-${ARCH} -o /usr/bin/wharfie && chmod +x /usr/bin/wharfie

# dracut.conf.d files 50-cost-initrd.conf and 50-elemental-initrd.conf are overwritten from local copies
# this is needed to ensure that the multipath module is enabled when initrd is generated
# as this is needed to ensure we can boot off multipath disks
COPY files/ /
RUN chmod 0600 /system/oem/*

Expand Down
2 changes: 1 addition & 1 deletion package/harvester-os/files/etc/cos/bootargs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set crash_kernel_params="crashkernel=219M,high crashkernel=72M,low"
if [ "${img}" == "/cOS/recovery.img" ]; then
set kernelcmd="$console_params root=LABEL=$recovery_label cos-img/filename=$img rd.neednet=1 rd.cos.oemlabel=$oem_label rd.cos.mount=LABEL=$oem_label:/oem rd.cos.oemtimeout=120"
else
set kernelcmd="$console_params root=LABEL=$state_label cos-img/filename=$img panic=0 net.ifnames=1 rd.cos.oemlabel=$oem_label rd.cos.mount=LABEL=$oem_label:/oem rd.cos.mount=LABEL=$persistent_label:/usr/local rd.cos.oemtimeout=120 audit=1 audit_backlog_limit=8192 intel_iommu=on amd_iommu=on iommu=pt"
set kernelcmd="$console_params root=LABEL=$state_label cos-img/filename=$img panic=0 net.ifnames=1 rd.cos.oemlabel=$oem_label rd.cos.mount=LABEL=$oem_label:/oem rd.cos.mount=LABEL=$persistent_label:/usr/local rd.cos.oemtimeout=120 audit=1 audit_backlog_limit=8192 intel_iommu=on amd_iommu=on iommu=pt $third_party_kernel_args"
fi

set initramfs=/boot/initrd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hostonly_cmdline="no"
hostonly="no"
compress="xz"
add_dracutmodules+=" dmsquash-live "
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hostonly_cmdline="no"
hostonly="no"
compress="xz"
add_dracutmodules+=" livenet dmsquash-live "
8 changes: 8 additions & 0 deletions package/harvester-os/files/usr/sbin/harv-install
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ update_grub_settings()
if ! [ -f ${TARGET_FILE} ]; then
touch ${TARGET_FILE}
fi
# /etc/cos/bootargs.cfg appends a new variable $third_party_kernel_args
# if harvester config has os.externalStorageConfig.additionalKernelArguments specified
# then these will be mapped to HARVESTER_EXTERNALSTORAGECONFIG_ADDITONALKERNEL_ARGUMENTS
# and will be added to /oem/grubenv file
TARGET_FILE="${oem_dir}/grubenv"
if [ -n "${HARVESTER_ADDITIONAL_KERNEL_ARGUMENTS}" ]; then
grub2-editenv ${TARGET_FILE} set third_party_kernel_args="${HARVESTER_ADDITIONAL_KERNEL_ARGUMENTS}"
fi

add_debug_grub_entry
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,19 @@ type OS struct {
Labels map[string]string `json:"labels,omitempty"`
SSHD SSHDConfig `json:"sshd,omitempty"`

PersistentStatePaths []string `json:"persistentStatePaths,omitempty"`
PersistentStatePaths []string `json:"persistentStatePaths,omitempty"`
ExternalStorage ExternalStorageConfig `json:"externalStorageConfig,omitempty"`
AdditionalKernelArguments string `json:"additionalKernelArguments,omitempty"`
}

type ExternalStorageConfig struct {
Enabled bool `json:"enabled,omitempty"`
MultiPathConfig []DiskConfig `json:"multiPathConfig,omitempty"`
}

type DiskConfig struct {
Vendor string `json:"vendor"`
Product string `json:"product"`
}

// SSHDConfig is the SSHD configuration for the node
Expand Down
47 changes: 47 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -450,3 +451,49 @@ func TestHarvesterConfigMerge_Addons(t *testing.T) {
assert.Equal(t, "the value to overwrite original", conf.Addons["rancher-logging"].ValuesContent, "Addons ValuesContent should be merged")
assert.Equal(t, false, conf.Addons["rancher-monitoring"].Enabled, "Addons Enabled false should be merged")
}

func Test_MultipathConfig(t *testing.T) {
assert := require.New(t)
config := NewHarvesterConfig()
config.OS.ExternalStorage = ExternalStorageConfig{
Enabled: true,
MultiPathConfig: []DiskConfig{
{
Vendor: "DELL",
Product: "DISK1",
},
{
Vendor: "HPE",
Product: "DISK2",
},
},
}

content, err := render("multipath.conf.tmpl", config)
assert.NoError(err, "expected no error while rending multipath config")
t.Log("rendered multipath config:")
t.Log(content)
}

func Test_ToCosInstallEnv(t *testing.T) {
hvConfig := NewHarvesterConfig()
hvConfig.OS.ExternalStorage = ExternalStorageConfig{
Enabled: true,
MultiPathConfig: []DiskConfig{
{
Vendor: "DELL",
Product: "DISK1",
},
{
Vendor: "HPE",
Product: "DISK2",
},
},
}
hvConfig.OS.AdditionalKernelArguments = "rd.iscsi.firmware rd.iscsi.ibft"
assert := require.New(t)
env, err := hvConfig.ToCosInstallEnv()
assert.NoError(err)
t.Log(env)

}
23 changes: 23 additions & 0 deletions pkg/config/cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) {
})
}

// enable multipathd for external storage support
if err := setupExternalStorage(config, &initramfs); err != nil {
return nil, err
}

// TOP
if cfg.Mode != ModeInstall {
if err := initRancherdStage(config, &initramfs); err != nil {
Expand Down Expand Up @@ -819,3 +824,21 @@ func CreateRootPartitioningLayout(elementalConfig *ElementalConfig, hvstConfig *

return elementalConfig, nil
}

// setupExternalStorage is needed to support boot of external disks
// this involves enable multipath service and configuring it to blacklist
// all devices except the ones listed in the config.OS.ExternalStorage.MultiPathConfig

func setupExternalStorage(config *HarvesterConfig, stage *yipSchema.Stage) error {
stage.Systemctl.Enable = append(stage.Systemctl.Enable, "multipathd")
content, err := render("multipath.conf.tmpl", config)
if err != nil {
return fmt.Errorf("error rending multipath.conf template: %v", err)
}
stage.Files = append(stage.Files, yipSchema.File{
Path: "/etc/multipath.conf",
Content: content,
Permissions: 0755,
})
return nil
}
8 changes: 8 additions & 0 deletions pkg/config/templates/multipath.conf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blacklist {
{{ range $val := .ExternalStorage.MultiPathConfig }}
device {
vendor "!{{ $val.Vendor }}"
product "!{{ $val.Product }}"
}
{{ end }}
}
4 changes: 4 additions & 0 deletions pkg/console/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ func doInstall(g *gocui.Gui, hvstConfig *config.HarvesterConfig, webhooks Render
env = append(env, fmt.Sprintf("HARVESTER_DATA_DISK=%s", hvstConfig.DataDisk))
}

if hvstConfig.OS.AdditionalKernelArguments != "" {
env = append(env, fmt.Sprintf("HARVESTER_ADDITIONAL_KERNEL_ARGUMENTS=%s", hvstConfig.OS.AdditionalKernelArguments))
}

elementalConfigDir, elementalConfigFile, err := saveElementalConfig(elementalConfig)
if err != nil {
return nil
Expand Down
29 changes: 29 additions & 0 deletions vendor/github.com/stretchr/testify/require/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/github.com/stretchr/testify/require/forward_requirements.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7db58f

Please sign in to comment.