Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions examples/terraform/aws-simple/terraform.tfvars.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aws = {
launchpad = {
drain = false

mcr_version = "25.0.13"
mcr_version = "25.0.14.2"
mke_version = "3.8.8"
msr_version = "2.9.28"

Expand All @@ -32,7 +32,7 @@ subnets = {
"main" = {
"cidr" = "172.31.0.0/17",
"private" = false,
"nodegroups" = ["MngrA", "WrkA", "MsrA"]
"nodegroups" = ["MngrA", "Wrkubuntu", "Wrkrhel", "Wrksles"]
}
}

Expand All @@ -46,22 +46,30 @@ nodegroups = {
"role" = "manager",
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
},
"WrkA" = {
"platform" = "ubuntu_22.04",
"Wrkrhel" = {
"platform" = "rhel-9",
"count" = 1,
"type" = "c6a.xlarge",
"volume_size" = "100",
"role" = "worker",
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
}
"MsrA" = {
},
"Wrkubuntu" = {
"platform" = "ubuntu_22.04",
"count" = 1,
"type" = "c6a.xlarge",
"volume_size" = "100",
"role" = "msr",
"role" = "worker",
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
}
},
"Wrksles" = {
"platform" = "sles-15",
"count" = 1,
"type" = "c6a.xlarge",
"volume_size" = "100",
"role" = "worker",
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
},
}

// set a windows password, if you have windows nodes
Expand Down
17 changes: 17 additions & 0 deletions jn-todo.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* JNesbitt informal todo list

** TODO Move product/mke/api/host.go:Host.MCRConfigure to /pkg/configurer interfaces

The MCRConfigure() method likely exists on the host as a convenience, but as we have common
configurer functionality and the other MCR methods are on the configurer it doesn't belong
on the host.
Another option would be to move functionality to the /pkg/mcr package.

On top of this, the configurer.MCRConfigPath should perhaps be an accessor pair of content,
instead of a filepath.

** TODO Move MCR install script from a pkg/product/phase/download_installer to the windows configurer

The phase is in a weird place, and also is no longer needed for linux installations (we dropped
the linux script usage.)
It should get moved to the Windows configurer and integrated into the Windows configurer MCRInstall().
16 changes: 3 additions & 13 deletions pkg/configurer/centos/centos.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
package centos

import (
"fmt"

"github.com/Mirantis/launchpad/pkg/configurer/enterpriselinux"
"github.com/k0sproject/rig"
"github.com/k0sproject/rig/os"
"github.com/k0sproject/rig/os/registry"

"github.com/Mirantis/launchpad/pkg/configurer/enterpriselinux"
)

// Configurer is the CentOS specific implementation of a host configurer.
type Configurer struct {
enterpriselinux.Configurer
}

// InstallMKEBasePackages install all the needed base packages on the host.
func (c Configurer) InstallMKEBasePackages(h os.Host) error {
if err := c.InstallPackage(h, "curl", "socat", "iptables", "iputils", "gzip"); err != nil {
return fmt.Errorf("failed to install base packages: %w", err)
}
return nil
}

func init() {
registry.RegisterOSModule(
func(os rig.OSVersion) bool {
return os.ID == "centos"
},
func() interface{} {
func() any {
return Configurer{}
},
)
Expand Down
59 changes: 42 additions & 17 deletions pkg/configurer/enterpriselinux/el.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"fmt"
"strings"

"github.com/Mirantis/launchpad/pkg/configurer"
common "github.com/Mirantis/launchpad/pkg/product/common/api"
log "github.com/sirupsen/logrus"

"github.com/k0sproject/rig/exec"
"github.com/k0sproject/rig/os"
"github.com/k0sproject/rig/os/linux"
log "github.com/sirupsen/logrus"

"github.com/Mirantis/launchpad/pkg/configurer"
common "github.com/Mirantis/launchpad/pkg/product/common/api"
)

// Configurer is the EL family specific implementation of a host configurer.
Expand All @@ -26,6 +28,43 @@
return nil
}

// InstallMCR install Docker EE engine on Linux.
func (c Configurer) InstallMCR(h os.Host, scriptPath string, engineConfig common.MCRConfig) error {
ver, verErr := configurer.ResolveLinux(h)
if verErr != nil {
return fmt.Errorf("could not discover Linux version information")

Check failure on line 35 in pkg/configurer/enterpriselinux/el.go

View workflow job for this annotation

GitHub Actions / Lint

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"could not discover Linux version information\")" (err113)
}

if isEC2 := c.isAWSInstance(h); !isEC2 {
log.Debugf("%s: confirmed that this is not an AWS instance", h)
} else if c.InstallPackage(h, "rh-amazon-rhui-client") == nil {
log.Infof("%s: appears to be an AWS EC2 instance, installed rh-amazon-rhui-client", h)
}

// e.g. https://repos.mirantis.com/rhel/$releasever/$basearch/<update-channel>
baseUrl := fmt.Sprintf("%s/%s/%s/%s/%s", engineConfig.RepoURL, ver.ID, "$releasever", "$basearch", engineConfig.Channel)
// e.g. https://repos.mirantis.com/oraclelinux/gpg
gpgUrl := fmt.Sprintf("%s/%s/gpg", engineConfig.RepoURL, ver.ID)
elRepoFilePath := "/etc/yum.repos.d/docker-ee.repo"
elRepoTemplate := `[mirantis]
name=Mirantis Container Runtime
baseurl=%s
enabled=1
gpgcheck=1
gpgkey=%s
`
elRepo := fmt.Sprintf(elRepoTemplate, baseUrl, gpgUrl)

if err := c.WriteFile(h, elRepoFilePath, elRepo, "0600"); err != nil {
return fmt.Errorf("Could not write Yum repo file for MCR")

Check failure on line 59 in pkg/configurer/enterpriselinux/el.go

View workflow job for this annotation

GitHub Actions / Lint

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"Could not write Yum repo file for MCR\")" (err113)
}

if err := c.InstallPackage(h, "docker.ee"); err != nil {
return fmt.Errorf("Package manager could not install docker-ee")

Check failure on line 63 in pkg/configurer/enterpriselinux/el.go

View workflow job for this annotation

GitHub Actions / Lint

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"Package manager could not install docker-ee\")" (err113)
}
return nil
}

// UninstallMCR uninstalls docker-ee engine.
func (c Configurer) UninstallMCR(h os.Host, _ string, engineConfig common.MCRConfig) error {
info, getDockerError := c.GetDockerInfo(h)
Expand Down Expand Up @@ -53,20 +92,6 @@
return nil
}

// InstallMCR install Docker EE engine on Linux.
func (c Configurer) InstallMCR(h os.Host, scriptPath string, engineConfig common.MCRConfig) error {
if isEC2 := c.isAWSInstance(h); !isEC2 {
log.Debugf("%s: confirmed that this is not an AWS instance", h)
} else if c.InstallPackage(h, "rh-amazon-rhui-client") == nil {
log.Infof("%s: appears to be an AWS EC2 instance, installed rh-amazon-rhui-client", h)
}

if err := c.LinuxConfigurer.InstallMCR(h, scriptPath, engineConfig); err != nil {
return fmt.Errorf("failed to install MCR: %w", err)
}
return nil
}

// function to check if the host is an AWS instance - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
func (c Configurer) isAWSInstance(h os.Host) bool {
found, err := h.ExecOutput("curl -s -m 5 http://169.254.169.254/latest/dynamic/instance-identity/document | grep region")
Expand Down
2 changes: 1 addition & 1 deletion pkg/configurer/enterpriselinux/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "rhel"
},
func() interface{} {
func() any {
return Rhel{}
},
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/configurer/enterpriselinux/rockylinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
func(os rig.OSVersion) bool {
return os.ID == "rocky"
},
func() interface{} {
func() any {
return RockyLinux{}
},
)
Expand Down
83 changes: 28 additions & 55 deletions pkg/configurer/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package configurer
import (
"errors"
"fmt"
"io/fs"
"path"
"path/filepath"
"regexp"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/Mirantis/launchpad/pkg/constant"
common "github.com/Mirantis/launchpad/pkg/product/common/api"
"github.com/Mirantis/launchpad/pkg/util/iputil"
"github.com/k0sproject/rig"
"github.com/k0sproject/rig/exec"
"github.com/k0sproject/rig/os"
log "github.com/sirupsen/logrus"
Expand All @@ -26,6 +26,10 @@ const (
SbinPath = `PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH`
)

var (
LinuxMCRInstallError = errors.New("failed to install MCR on linux")
)

// LinuxConfigurer is a generic linux host configurer.
type LinuxConfigurer struct {
riglinux os.Linux
Expand Down Expand Up @@ -54,60 +58,6 @@ func (c LinuxConfigurer) InstallMCRLicense(h os.Host, lic string) error {
return nil
}

// InstallMCR install MCR on Linux.
func (c LinuxConfigurer) InstallMCR(h os.Host, scriptPath string, engineConfig common.MCRConfig) error {
base := path.Base(scriptPath)

installScriptDir := engineConfig.InstallScriptRemoteDirLinux
if installScriptDir == "" {
installScriptDir = c.riglinux.Pwd(h)
}

_, err := h.ExecOutput(fmt.Sprintf("mkdir -p %s", installScriptDir))
if err != nil {
return fmt.Errorf("failed to create directory %s: %w", installScriptDir, err)
}

installer := path.Join(installScriptDir, base)

err = h.Upload(scriptPath, installer, fs.FileMode(0o640))
if err != nil {
log.Errorf("failed: %s", err.Error())
return fmt.Errorf("upload %s to %s: %w", scriptPath, installer, err)
}
defer func() {
if err := c.riglinux.DeleteFile(h, installer); err != nil {
log.Warnf("failed to delete installer script: %s", err.Error())
}
}()

envs := fmt.Sprintf("DOCKER_URL=%s CHANNEL=%s VERSION=%s ", engineConfig.RepoURL, engineConfig.Channel, engineConfig.Version)
if engineConfig.AdditionalRuntimes != "" {
envs += fmt.Sprintf("ADDITIONAL_RUNTIMES=%s ", engineConfig.AdditionalRuntimes)
}
if engineConfig.DefaultRuntime != "" {
envs += fmt.Sprintf("DEFAULT_RUNTIME=%s ", engineConfig.DefaultRuntime)
}
cmd := envs + fmt.Sprintf("bash %s", escape.Quote(installer))

log.Infof("%s: running installer", h)
log.Debugf("%s: installer command: %s", h, cmd)

if err := h.Exec(cmd); err != nil {
return fmt.Errorf("run MCR installer: %w", err)
}

if err := c.riglinux.EnableService(h, "docker"); err != nil {
return fmt.Errorf("enable docker service: %w", err)
}

if err := c.riglinux.StartService(h, "docker"); err != nil {
return fmt.Errorf("start docker service: %w", err)
}

return nil
}

// RestartMCR restarts Docker EE engine.
func (c LinuxConfigurer) RestartMCR(h os.Host) error {
if err := c.riglinux.RestartService(h, "docker"); err != nil {
Expand Down Expand Up @@ -406,3 +356,26 @@ func (c LinuxConfigurer) attemptPathSudoDelete(h os.Host, path string) {
}
log.Infof("%s: removed %s successfully", h, path)
}

var (
errAbort = errors.New("base os detected but version resolving failed")
)

// ResolveLinux stolen from k0sproject/rig
func ResolveLinux(h os.Host) (rig.OSVersion, error) {
if err := h.Exec("uname | grep -q Linux"); err != nil {
return rig.OSVersion{}, fmt.Errorf("not a linux host (%w)", err)
}

output, err := h.ExecOutput("cat /etc/os-release || cat /usr/lib/os-release")
if err != nil {
// at this point it is known that this is a linux host, so any error from here on should signal the resolver to not try the next
return rig.OSVersion{}, fmt.Errorf("%w: unable to read os-release file: %w", errAbort, err)
}

var version rig.OSVersion
if err := rig.ParseOSReleaseFile(output, &version); err != nil {
return rig.OSVersion{}, errors.Join(errAbort, err)
}
return version, nil
}
25 changes: 0 additions & 25 deletions pkg/configurer/mkex/README.md

This file was deleted.

Loading
Loading