From 0afdf3fd6fcffb3d266c7d27466ba9aa2692ec5a Mon Sep 17 00:00:00 2001 From: Vicente Cheng Date: Mon, 4 Sep 2023 19:13:59 +0800 Subject: [PATCH] config: make sftp could be configured dynamically - add `harvester.install.enableSftp` to config `sftp` dynamically Signed-off-by: Vicente Cheng --- pkg/config/config.go | 21 +++++++++++---------- pkg/config/cos.go | 6 ++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index bdc6c3cff..2c2fdc39e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -135,16 +135,17 @@ type Install struct { VipHwAddr string `json:"vipHwAddr,omitempty"` VipMode string `json:"vipMode,omitempty"` - ForceEFI bool `json:"forceEfi,omitempty"` - Device string `json:"device,omitempty"` - ConfigURL string `json:"configUrl,omitempty"` - Silent bool `json:"silent,omitempty"` - ISOURL string `json:"isoUrl,omitempty"` - PowerOff bool `json:"powerOff,omitempty"` - NoFormat bool `json:"noFormat,omitempty"` - Debug bool `json:"debug,omitempty"` - TTY string `json:"tty,omitempty"` - ForceGPT bool `json:"forceGpt,omitempty"` + ForceEFI bool `json:"forceEfi,omitempty"` + Device string `json:"device,omitempty"` + ConfigURL string `json:"configUrl,omitempty"` + Silent bool `json:"silent,omitempty"` + ISOURL string `json:"isoUrl,omitempty"` + PowerOff bool `json:"powerOff,omitempty"` + NoFormat bool `json:"noFormat,omitempty"` + Debug bool `json:"debug,omitempty"` + TTY string `json:"tty,omitempty"` + ForceGPT bool `json:"forceGpt,omitempty"` + EnableSFTP bool `json:"enableSftp,omitempty"` // Following options are not cOS installer flag ForceMBR bool `json:"forceMbr,omitempty"` diff --git a/pkg/config/cos.go b/pkg/config/cos.go index f32b4a515..7896ed105 100644 --- a/pkg/config/cos.go +++ b/pkg/config/cos.go @@ -190,6 +190,12 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) { }, } + // Add SFTP related config to after install stage + if config.Install.EnableSFTP { + config.OS.AfterInstallChrootCommands = append(config.OS.AfterInstallChrootCommands, "mkdir -p /etc/ssh/sshd_config.d") + config.OS.AfterInstallChrootCommands = append(config.OS.AfterInstallChrootCommands, "echo 'Subsystem sftp /usr/lib/ssh/sftp-server' > /etc/ssh/sshd_config.d/sftp.conf") + } + // Add after-install-chroot stage if len(config.OS.AfterInstallChrootCommands) > 0 { afterInstallChroot := yipSchema.Stage{}