Skip to content

Commit d2e2a69

Browse files
committed
PRODENG-3100 Linux native MCR install
- drop install.sh for all linux configurers Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
1 parent 48df1b5 commit d2e2a69

File tree

18 files changed

+238
-169
lines changed

18 files changed

+238
-169
lines changed

examples/terraform/aws-simple/terraform.tfvars.template

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ aws = {
88
launchpad = {
99
drain = false
1010

11-
mcr_version = "25.0.13"
11+
mcr_version = "25.0.14.2"
1212
mke_version = "3.8.8"
1313
msr_version = "2.9.28"
1414

@@ -32,7 +32,7 @@ subnets = {
3232
"main" = {
3333
"cidr" = "172.31.0.0/17",
3434
"private" = false,
35-
"nodegroups" = ["MngrA", "WrkA", "MsrA"]
35+
"nodegroups" = ["MngrA", "Wrkubuntu", "Wrkrhel", "Wrksles"]
3636
}
3737
}
3838

@@ -46,22 +46,30 @@ nodegroups = {
4646
"role" = "manager",
4747
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
4848
},
49-
"WrkA" = {
50-
"platform" = "ubuntu_22.04",
49+
"Wrkrhel" = {
50+
"platform" = "rhel-9",
5151
"count" = 1,
5252
"type" = "c6a.xlarge",
5353
"volume_size" = "100",
5454
"role" = "worker",
5555
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
56-
}
57-
"MsrA" = {
56+
},
57+
"Wrkubuntu" = {
5858
"platform" = "ubuntu_22.04",
5959
"count" = 1,
6060
"type" = "c6a.xlarge",
6161
"volume_size" = "100",
62-
"role" = "msr",
62+
"role" = "worker",
6363
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
64-
}
64+
},
65+
"Wrksles" = {
66+
"platform" = "sles-15",
67+
"count" = 1,
68+
"type" = "c6a.xlarge",
69+
"volume_size" = "100",
70+
"role" = "worker",
71+
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
72+
},
6573
}
6674

6775
// set a windows password, if you have windows nodes

jn-todo.org

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
* JNesbitt informal todo list
2+
3+
** TODO Move product/mke/api/host.go:Host.MCRConfigure to /pkg/configurer interfaces
4+
5+
The MCRConfigure() method likely exists on the host as a convenience, but as we have common
6+
configurer functionality and the other MCR methods are on the configurer it doesn't belong
7+
on the host.
8+
Another option would be to move functionality to the /pkg/mcr package.
9+
10+
On top of this, the configurer.MCRConfigPath should perhaps be an accessor pair of content,
11+
instead of a filepath.
12+
13+
** TODO Move MCR install script from a pkg/product/phase/download_installer to the windows configurer
14+
15+
The phase is in a weird place, and also is no longer needed for linux installations (we dropped
16+
the linux script usage.)
17+
It should get moved to the Windows configurer and integrated into the Windows configurer MCRInstall().

pkg/analytics/analytics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"testing"
55

66
"github.com/Mirantis/launchpad/pkg/config/user"
7-
"github.com/stretchr/testify/require"
87
"github.com/segmentio/analytics-go/v3"
8+
"github.com/stretchr/testify/require"
99
)
1010

1111
type mockClient struct {

pkg/configurer/centos/centos.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package centos
22

33
import (
4-
"fmt"
5-
64
"github.com/Mirantis/launchpad/pkg/configurer/enterpriselinux"
75
"github.com/k0sproject/rig"
8-
"github.com/k0sproject/rig/os"
96
"github.com/k0sproject/rig/os/registry"
107
)
118

@@ -14,20 +11,12 @@ type Configurer struct {
1411
enterpriselinux.Configurer
1512
}
1613

17-
// InstallMKEBasePackages install all the needed base packages on the host.
18-
func (c Configurer) InstallMKEBasePackages(h os.Host) error {
19-
if err := c.InstallPackage(h, "curl", "socat", "iptables", "iputils", "gzip"); err != nil {
20-
return fmt.Errorf("failed to install base packages: %w", err)
21-
}
22-
return nil
23-
}
24-
2514
func init() {
2615
registry.RegisterOSModule(
2716
func(os rig.OSVersion) bool {
2817
return os.ID == "centos"
2918
},
30-
func() interface{} {
19+
func() any {
3120
return Configurer{}
3221
},
3322
)

pkg/configurer/enterpriselinux/el.go

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,43 @@ func (c Configurer) InstallMKEBasePackages(h os.Host) error {
2626
return nil
2727
}
2828

29+
// InstallMCR install Docker EE engine on Linux.
30+
func (c Configurer) InstallMCR(h os.Host, _ string, engineConfig commonconfig.MCRConfig) error {
31+
ver, verErr := configurer.ResolveLinux(h)
32+
if verErr != nil {
33+
return fmt.Errorf("could not discover Linux version information")
34+
}
35+
36+
if isEC2 := c.isAWSInstance(h); !isEC2 {
37+
log.Debugf("%s: confirmed that this is not an AWS instance", h)
38+
} else if c.InstallPackage(h, "rh-amazon-rhui-client") == nil {
39+
log.Infof("%s: appears to be an AWS EC2 instance, installed rh-amazon-rhui-client", h)
40+
}
41+
42+
// e.g. https://repos.mirantis.com/rhel/$releasever/$basearch/<update-channel>
43+
baseURL := fmt.Sprintf("%s/%s/%s/%s/%s", engineConfig.RepoURL, ver.ID, "$releasever", "$basearch", engineConfig.Channel)
44+
// e.g. https://repos.mirantis.com/oraclelinux/gpg
45+
gpgURL := fmt.Sprintf("%s/%s/gpg", engineConfig.RepoURL, ver.ID)
46+
elRepoFilePath := "/etc/yum.repos.d/docker-ee.repo"
47+
elRepoTemplate := `[mirantis]
48+
name=Mirantis Container Runtime
49+
baseurl=%s
50+
enabled=1
51+
gpgcheck=1
52+
gpgkey=%s
53+
`
54+
elRepo := fmt.Sprintf(elRepoTemplate, baseURL, gpgURL)
55+
56+
if err := c.WriteFile(h, elRepoFilePath, elRepo, "0600"); err != nil {
57+
return fmt.Errorf("could not write Yum repo file for MCR")
58+
}
59+
60+
if err := c.InstallPackage(h, "docker.ee"); err != nil {
61+
return fmt.Errorf("package manager could not install docker-ee")
62+
}
63+
return nil
64+
}
65+
2966
// UninstallMCR uninstalls docker-ee engine.
3067
func (c Configurer) UninstallMCR(h os.Host, _ string, engineConfig commonconfig.MCRConfig) error {
3168
info, getDockerError := c.GetDockerInfo(h)
@@ -53,20 +90,6 @@ func (c Configurer) UninstallMCR(h os.Host, _ string, engineConfig commonconfig.
5390
return nil
5491
}
5592

56-
// InstallMCR install Docker EE engine on Linux.
57-
func (c Configurer) InstallMCR(h os.Host, scriptPath string, engineConfig commonconfig.MCRConfig) error {
58-
if isEC2 := c.isAWSInstance(h); !isEC2 {
59-
log.Debugf("%s: confirmed that this is not an AWS instance", h)
60-
} else if c.InstallPackage(h, "rh-amazon-rhui-client") == nil {
61-
log.Infof("%s: appears to be an AWS EC2 instance, installed rh-amazon-rhui-client", h)
62-
}
63-
64-
if err := c.LinuxConfigurer.InstallMCR(h, scriptPath, engineConfig); err != nil {
65-
return fmt.Errorf("failed to install MCR: %w", err)
66-
}
67-
return nil
68-
}
69-
7093
// function to check if the host is an AWS instance - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
7194
func (c Configurer) isAWSInstance(h os.Host) bool {
7295
found, err := h.ExecOutput("curl -s -m 5 http://169.254.169.254/latest/dynamic/instance-identity/document | grep region")

pkg/configurer/enterpriselinux/rhel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func init() {
1515
func(os rig.OSVersion) bool {
1616
return os.ID == "rhel"
1717
},
18-
func() interface{} {
18+
func() any {
1919
return Rhel{}
2020
},
2121
)

pkg/configurer/enterpriselinux/rockylinux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func init() {
1515
func(os rig.OSVersion) bool {
1616
return os.ID == "rocky"
1717
},
18-
func() interface{} {
18+
func() any {
1919
return RockyLinux{}
2020
},
2121
)

pkg/configurer/linux.go

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package configurer
33
import (
44
"errors"
55
"fmt"
6-
"io/fs"
76
"path"
87
"path/filepath"
98
"regexp"
@@ -14,6 +13,7 @@ import (
1413
"github.com/Mirantis/launchpad/pkg/constant"
1514
commonconfig "github.com/Mirantis/launchpad/pkg/product/common/config"
1615
"github.com/Mirantis/launchpad/pkg/util/iputil"
16+
"github.com/k0sproject/rig"
1717
"github.com/k0sproject/rig/exec"
1818
"github.com/k0sproject/rig/os"
1919
log "github.com/sirupsen/logrus"
@@ -26,6 +26,10 @@ const (
2626
SbinPath = `PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH`
2727
)
2828

29+
var (
30+
LinuxMCRInstallError = errors.New("failed to install MCR on linux")
31+
)
32+
2933
// LinuxConfigurer is a generic linux host configurer.
3034
type LinuxConfigurer struct {
3135
riglinux os.Linux
@@ -54,60 +58,6 @@ func (c LinuxConfigurer) InstallMCRLicense(h os.Host, lic string) error {
5458
return nil
5559
}
5660

57-
// InstallMCR install MCR on Linux.
58-
func (c LinuxConfigurer) InstallMCR(h os.Host, scriptPath string, engineConfig commonconfig.MCRConfig) error {
59-
base := path.Base(scriptPath)
60-
61-
installScriptDir := engineConfig.InstallScriptRemoteDirLinux
62-
if installScriptDir == "" {
63-
installScriptDir = c.riglinux.Pwd(h)
64-
}
65-
66-
_, err := h.ExecOutput(fmt.Sprintf("mkdir -p %s", installScriptDir))
67-
if err != nil {
68-
return fmt.Errorf("failed to create directory %s: %w", installScriptDir, err)
69-
}
70-
71-
installer := path.Join(installScriptDir, base)
72-
73-
err = h.Upload(scriptPath, installer, fs.FileMode(0o640))
74-
if err != nil {
75-
log.Errorf("failed: %s", err.Error())
76-
return fmt.Errorf("upload %s to %s: %w", scriptPath, installer, err)
77-
}
78-
defer func() {
79-
if err := c.riglinux.DeleteFile(h, installer); err != nil {
80-
log.Warnf("failed to delete installer script: %s", err.Error())
81-
}
82-
}()
83-
84-
envs := fmt.Sprintf("DOCKER_URL=%s CHANNEL=%s VERSION=%s ", engineConfig.RepoURL, engineConfig.Channel, engineConfig.Version)
85-
if engineConfig.AdditionalRuntimes != "" {
86-
envs += fmt.Sprintf("ADDITIONAL_RUNTIMES=%s ", engineConfig.AdditionalRuntimes)
87-
}
88-
if engineConfig.DefaultRuntime != "" {
89-
envs += fmt.Sprintf("DEFAULT_RUNTIME=%s ", engineConfig.DefaultRuntime)
90-
}
91-
cmd := envs + fmt.Sprintf("bash %s", escape.Quote(installer))
92-
93-
log.Infof("%s: running installer", h)
94-
log.Debugf("%s: installer command: %s", h, cmd)
95-
96-
if err := h.Exec(cmd); err != nil {
97-
return fmt.Errorf("run MCR installer: %w", err)
98-
}
99-
100-
if err := c.riglinux.EnableService(h, "docker"); err != nil {
101-
return fmt.Errorf("enable docker service: %w", err)
102-
}
103-
104-
if err := c.riglinux.StartService(h, "docker"); err != nil {
105-
return fmt.Errorf("start docker service: %w", err)
106-
}
107-
108-
return nil
109-
}
110-
11161
// RestartMCR restarts Docker EE engine.
11262
func (c LinuxConfigurer) RestartMCR(h os.Host) error {
11363
if err := c.riglinux.RestartService(h, "docker"); err != nil {
@@ -406,3 +356,28 @@ func (c LinuxConfigurer) attemptPathSudoDelete(h os.Host, path string) {
406356
}
407357
log.Infof("%s: removed %s successfully", h, path)
408358
}
359+
360+
var (
361+
errAbort = errors.New("base os detected but version resolving failed")
362+
)
363+
364+
// ResolveLinux stolen from k0sproject/rig.
365+
//
366+
// We need os-release info in various scenarios, but rig doesn't really expose it.
367+
func ResolveLinux(h os.Host) (rig.OSVersion, error) {
368+
if err := h.Exec("uname | grep -q Linux"); err != nil {
369+
return rig.OSVersion{}, fmt.Errorf("not a linux host (%w)", err)
370+
}
371+
372+
output, err := h.ExecOutput("cat /etc/os-release || cat /usr/lib/os-release")
373+
if err != nil {
374+
// 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
375+
return rig.OSVersion{}, fmt.Errorf("%w: unable to read os-release file: %w", errAbort, err)
376+
}
377+
378+
var version rig.OSVersion
379+
if err := rig.ParseOSReleaseFile(output, &version); err != nil {
380+
return rig.OSVersion{}, errors.Join(errAbort, err)
381+
}
382+
return version, nil
383+
}

pkg/configurer/oracle/oracle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func init() {
1616
func(os rig.OSVersion) bool {
1717
return os.ID == "ol"
1818
},
19-
func() interface{} {
19+
func() any {
2020
return Configurer{}
2121
},
2222
)

0 commit comments

Comments
 (0)