Skip to content

Commit d69b957

Browse files
committed
PRODENG-3100 schema bump to 1.6
- migrate 1.5 -> 1.6, which is actually kind of painful - update aws example Terraform that generates launchpad yaml - update smoke test to use new terraform, and also to test on RHEL9, Ubuntu22 and Sles15 - some fixes for the native configurers Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
1 parent 86d37cc commit d69b957

15 files changed

Lines changed: 203 additions & 213 deletions

File tree

examples/terraform/aws-simple/launchpad.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ variable "launchpad" {
1414
type = object({
1515
drain = bool
1616

17-
mcr_version = string
17+
mcr_channel = string
1818
mke_version = string
1919
msr_version = string // unused if you have no MSR hosts
2020

@@ -137,8 +137,8 @@ locals {
137137
// ------- Ye old launchpad yaml (just for debugging)
138138

139139
locals {
140-
launchpad_yaml_15 = <<-EOT
141-
apiVersion: launchpad.mirantis.com/mke/v1.5
140+
launchpad_yaml = <<-EOT
141+
apiVersion: launchpad.mirantis.com/mke/v1.6
142142
kind: mke%{if local.has_msr}+msr%{endif}
143143
metadata:
144144
name: ${var.name}
@@ -165,11 +165,9 @@ spec:
165165
insecure: ${h.winrm_insecure}
166166
%{~endfor}
167167
mcr:
168-
version: ${var.launchpad.mcr_version}
168+
channel: ${var.launchpad.mcr_channel}
169169
repoURL: https://repos.mirantis.com
170-
installURLLinux: https://get.mirantis.com/
171170
installURLWindows: https://get.mirantis.com/install.ps1
172-
channel: stable-25.0
173171
prune: true
174172
mke:
175173
version: ${var.launchpad.mke_version}
@@ -199,7 +197,7 @@ EOT
199197
output "launchpad_yaml" {
200198
description = "launchpad config file yaml (for debugging)"
201199
sensitive = true
202-
value = local.launchpad_yaml_15
200+
value = local.launchpad_yaml
203201
}
204202

205203
output "mke_connect" {

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

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

11-
mcr_version = "25.0.14.2"
11+
mcr_channel = "stable-25.0.14"
1212
mke_version = "3.8.8"
1313
msr_version = "2.9.28"
1414

1515
mke_connect = {
1616
username = "admin"
17-
password = "" // an MKE passwords must be provided
17+
password = "" // an MKE password must be provided
1818
insecure = true
1919
}
2020

@@ -47,7 +47,7 @@ nodegroups = {
4747
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
4848
},
4949
"Wrkrhel" = {
50-
"platform" = "rhel-9",
50+
"platform" = "rhel_9",
5151
"count" = 1,
5252
"type" = "c6a.xlarge",
5353
"volume_size" = "100",
@@ -63,7 +63,7 @@ nodegroups = {
6363
"user_data" = "sudo ufw allow 7946/tcp ; sudo ufw allow 10250/tcp "
6464
},
6565
"Wrksles" = {
66-
"platform" = "sles-15",
66+
"platform" = "sles_15",
6767
"count" = 1,
6868
"type" = "c6a.xlarge",
6969
"volume_size" = "100",

pkg/config/migration/v15/v15.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package v15
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/Mirantis/launchpad/pkg/config/migration"
8+
log "github.com/sirupsen/logrus"
9+
)
10+
11+
// Migrate migrates a v1.5 format configuration into the v1.6 api format and replaces the contents of the supplied data byte slice.
12+
//
13+
// v1.6 uses only an MCR channel, dropping the MCR Version value. A migrated channel can be made from the combined v1.5 channel-version
14+
func Migrate(plain map[string]any) error {
15+
plain["apiVersion"] = "launchpad.mirantis.com/mke/v1.6"
16+
if spec, ok := plain["spec"].(map[any]any); ok {
17+
if mcr, ok := spec["mcr"].(map[any]any); ok {
18+
version := mcr["version"] // if "version: 25.0" it could be parsed as a float64 instead of a string
19+
channel := mcr["channel"]
20+
21+
channels, ok := channel.(string)
22+
if !ok {
23+
return fmt.Errorf("could not migrate non-string channel, expected something like 'test' or 'stable-25.0`, but got '%s'", channel) // this is not likely
24+
}
25+
26+
versions, ok := version.(string)
27+
if !ok { // handle some frustrating yaml parsing issues for version v`alues
28+
if versionf, ok := version.(float64); ok { // version: 25.0 : produces`` a float64
29+
versions = fmt.Sprintf("%.1f", versionf)
30+
} else if versioni, ok := version.(int); ok { // version: 25 : produces an integer
31+
versions = fmt.Sprintf("%d.0", versioni)
32+
} else {
33+
log.Warnf("unclear version for migration: %+v (%T)", version, version)
34+
}
35+
}
36+
37+
// channel might already be `stable-25.0` but a version was passed, so we overrid it with a version passed
38+
if channelsParts := strings.Split(channels, "-"); len(channelsParts) > 1 {
39+
log.Warnf("when migrating to v1.6, a version (%s) and a channel (%s) were passed, but we combined them to use: %s-%s", version, channel, channels, versions)
40+
channels = channelsParts[0]
41+
}
42+
43+
mcr["channel"] = fmt.Sprintf("%s-%s", channels, versions)
44+
delete(mcr, "version")
45+
}
46+
}
47+
48+
log.Debugf("migrated configuration from launchpad.mirantis.com/v1.4 to launchpad.mirantis.com/mke/v1.5")
49+
log.Infof("Note: The configuration has been migrated from a previous version")
50+
log.Infof(" to see the migrated configuration use: launchpad describe config")
51+
return nil
52+
}
53+
54+
func init() {
55+
migration.Register("launchpad.mirantis.com/mke/v1.5", Migrate)
56+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package v15
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
"gopkg.in/yaml.v2"
8+
)
9+
10+
func TestVersionMigrationSimple(t *testing.T) {
11+
v15 := []byte(`---
12+
apiVersion: launchpad.mirantis.com/mke/v1.5
13+
kind: mke
14+
spec:
15+
mcr:
16+
channel: stable
17+
repoURL: https://repos.mirantis.com
18+
version: 25.0.14
19+
mke:
20+
adminUsername: admin
21+
imageRepo: docker.io/mirantis
22+
version: 3.8.6
23+
`)
24+
25+
v16 := []byte(`apiVersion: launchpad.mirantis.com/mke/v1.6
26+
kind: mke
27+
spec:
28+
mcr:
29+
channel: stable-25.0.14
30+
repoURL: https://repos.mirantis.com
31+
mke:
32+
adminUsername: admin
33+
imageRepo: docker.io/mirantis
34+
version: 3.8.6
35+
`)
36+
in := make(map[string]any)
37+
require.NoError(t, yaml.Unmarshal(v15, in))
38+
require.NoError(t, Migrate(in))
39+
out, err := yaml.Marshal(in)
40+
require.NoError(t, err)
41+
require.Equal(t, string(v16), string(out))
42+
}
43+
44+
func TestVersionMigrationDefault(t *testing.T) {
45+
v15 := []byte(`---
46+
apiVersion: launchpad.mirantis.com/mke/v1.5
47+
kind: mke
48+
spec:
49+
mcr:
50+
channel: stable
51+
repoURL: https://repos.mirantis.com
52+
version: 25.0
53+
mke:
54+
adminUsername: admin
55+
imageRepo: docker.io/mirantis
56+
version: 3.8.6
57+
`)
58+
59+
v16 := []byte(`apiVersion: launchpad.mirantis.com/mke/v1.6
60+
kind: mke
61+
spec:
62+
mcr:
63+
channel: stable-25.0
64+
repoURL: https://repos.mirantis.com
65+
mke:
66+
adminUsername: admin
67+
imageRepo: docker.io/mirantis
68+
version: 3.8.6
69+
`)
70+
in := make(map[string]any)
71+
require.NoError(t, yaml.Unmarshal(v15, in))
72+
require.NoError(t, Migrate(in))
73+
out, err := yaml.Marshal(in)
74+
require.NoError(t, err)
75+
require.Equal(t, string(v16), string(out))
76+
}
77+
78+
func TestVersionMigrationSlim(t *testing.T) {
79+
v15 := []byte(`---
80+
apiVersion: launchpad.mirantis.com/mke/v1.5
81+
kind: mke
82+
spec:
83+
mcr:
84+
channel: stable
85+
repoURL: https://repos.mirantis.com
86+
version: 25
87+
mke:
88+
adminUsername: admin
89+
imageRepo: docker.io/mirantis
90+
version: 3.8.6
91+
`)
92+
93+
v16 := []byte(`apiVersion: launchpad.mirantis.com/mke/v1.6
94+
kind: mke
95+
spec:
96+
mcr:
97+
channel: stable-25.0
98+
repoURL: https://repos.mirantis.com
99+
mke:
100+
adminUsername: admin
101+
imageRepo: docker.io/mirantis
102+
version: 3.8.6
103+
`)
104+
in := make(map[string]any)
105+
require.NoError(t, yaml.Unmarshal(v15, in))
106+
require.NoError(t, Migrate(in))
107+
out, err := yaml.Marshal(in)
108+
require.NoError(t, err)
109+
require.Equal(t, string(v16), string(out))
110+
}

pkg/configurer/enterpriselinux/el.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ gpgkey=%s
5757
return fmt.Errorf("could not write Yum repo file for MCR")
5858
}
5959

60-
if err := c.InstallPackage(h, "docker.ee"); err != nil {
60+
if err := c.InstallPackage(h, "docker-ee"); err != nil {
6161
return fmt.Errorf("package manager could not install docker-ee")
6262
}
6363
return nil

pkg/configurer/sles/sles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c Configurer) InstallMCR(h os.Host, engineConfig commonconfig.MCRConfig) e
8181
}
8282

8383
// UninstallMCR uninstalls docker-ee engine.
84-
func (c Configurer) UninstallMCR(h os.Host, _ string, engineConfig commonconfig.MCRConfig) error {
84+
func (c Configurer) UninstallMCR(h os.Host, engineConfig commonconfig.MCRConfig) error {
8585
info, getDockerError := c.GetDockerInfo(h)
8686
if engineConfig.Prune {
8787
defer c.CleanupLingeringMCR(h, info)

pkg/configurer/windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (c WindowsConfigurer) InstallMCRLicense(h os.Host, lic string) error {
6464

6565
// InstallMCR install MCR on Windows.
6666
func (c WindowsConfigurer) InstallMCR(h os.Host, engineConfig commonconfig.MCRConfig) error {
67-
var version = "latest"
67+
version := "latest"
6868

6969
installerPath, getInstallerErr := GetInstaller(engineConfig.InstallURLWindows)
7070
if getInstallerErr != nil {

pkg/mcr/mcr.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
log "github.com/sirupsen/logrus"
1111
)
1212

13-
var ErrInvalidMCRConfig = errors.New("MCR configuration is invalid")
14-
var ErrMCRNotRunning = errors.New("MCR is not running")
13+
var (
14+
ErrInvalidMCRConfig = errors.New("MCR configuration is invalid")
15+
ErrMCRNotRunning = errors.New("MCR is not running")
16+
)
1517

1618
// DrainNode drains a node from the workload via docker drain command.
1719
func DrainNode(lead *mkeconfig.Host, h *mkeconfig.Host) error {

pkg/product/common/config/mcr_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type MCRConfig struct {
2525
License string `yaml:"license"`
2626
InstallScriptRemoteDirLinux string `yaml:"installScriptRemoteDirLinux,omitempty"`
2727
InstallURLWindows string `yaml:"installURLWindows,omitempty"`
28-
Channel string `yaml:"channel,omitempty,validate=regexp=test|stable"`
28+
Channel string `yaml:"channel,omitempty"`
2929
Prune bool `yaml:"prune,omitempty"`
3030
ForceUpgrade bool `yaml:"forceUpgrade,omitempty"`
3131
SwarmInstallFlags Flags `yaml:"swarmInstallFlags,omitempty,flow"`

0 commit comments

Comments
 (0)