Skip to content

Commit 6df1c03

Browse files
committed
PRODENG-3100 EL native MCR install
- drop install.sh for all linux configurers TODO: - drop script download phase, and move windows script download to windows installMCR function - drop mkex handler so that we don't need to refactor it Signed-off-by: James Nesbitt <[email protected]>
1 parent 1f14803 commit 6df1c03

File tree

12 files changed

+173
-270
lines changed

12 files changed

+173
-270
lines changed

pkg/configurer/centos/centos.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
package centos
22

33
import (
4-
"fmt"
5-
6-
"github.com/Mirantis/launchpad/pkg/configurer/enterpriselinux"
74
"github.com/k0sproject/rig"
8-
"github.com/k0sproject/rig/os"
95
"github.com/k0sproject/rig/os/registry"
6+
7+
"github.com/Mirantis/launchpad/pkg/configurer/enterpriselinux"
108
)
119

1210
// Configurer is the CentOS specific implementation of a host configurer.
1311
type Configurer struct {
1412
enterpriselinux.Configurer
1513
}
1614

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-
2515
func init() {
2616
registry.RegisterOSModule(
2717
func(os rig.OSVersion) bool {
2818
return os.ID == "centos"
2919
},
30-
func() interface{} {
20+
func() any {
3121
return Configurer{}
3222
},
3323
)

pkg/configurer/enterpriselinux/el.go

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/Mirantis/launchpad/pkg/configurer"
8-
common "github.com/Mirantis/launchpad/pkg/product/common/api"
7+
log "github.com/sirupsen/logrus"
8+
99
"github.com/k0sproject/rig/exec"
1010
"github.com/k0sproject/rig/os"
1111
"github.com/k0sproject/rig/os/linux"
12-
log "github.com/sirupsen/logrus"
12+
13+
"github.com/Mirantis/launchpad/pkg/configurer"
14+
common "github.com/Mirantis/launchpad/pkg/product/common/api"
1315
)
1416

1517
// Configurer is the EL family specific implementation of a host configurer.
@@ -26,6 +28,45 @@ func (c Configurer) InstallMKEBasePackages(h os.Host) error {
2628
return nil
2729
}
2830

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

56-
// InstallMCR install Docker EE engine on Linux.
57-
func (c Configurer) InstallMCR(h os.Host, scriptPath string, engineConfig common.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-
7097
// function to check if the host is an AWS instance - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
7198
func (c Configurer) isAWSInstance(h os.Host) bool {
7299
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: 28 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
common "github.com/Mirantis/launchpad/pkg/product/common/api"
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 common.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,26 @@ 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+
func ResolveLinux(h os.Host) (rig.OSVersion, error) {
366+
if err := h.Exec("uname | grep -q Linux"); err != nil {
367+
return rig.OSVersion{}, fmt.Errorf("not a linux host (%w)", err)
368+
}
369+
370+
output, err := h.ExecOutput("cat /etc/os-release || cat /usr/lib/os-release")
371+
if err != nil {
372+
// 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
373+
return rig.OSVersion{}, fmt.Errorf("%w: unable to read os-release file: %w", errAbort, err)
374+
}
375+
376+
var version rig.OSVersion
377+
if err := rig.ParseOSReleaseFile(output, &version); err != nil {
378+
return rig.OSVersion{}, errors.Join(errAbort, err)
379+
}
380+
return version, nil
381+
}

pkg/configurer/mkex/README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

pkg/configurer/mkex/mkex.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)