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
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ linters:
- contextcheck
- dupword
- durationcheck
- err113
# - err113
- errchkjson
- errname
- errorlint
Expand All @@ -38,6 +38,7 @@ linters:
- unparam
- usestdlibvars
- usetesting
- varnamelen
- wastedassign
- whitespace
- wrapcheck
Expand All @@ -54,7 +55,8 @@ linters:
- wg sync.WaitGroup
- h Host
- h os.Host
- h *api.Host
- h mkeconfig.Host
- h *mkeconfig.Host
- ok bool
- s string
exclusions:
Expand Down
12 changes: 5 additions & 7 deletions examples/terraform/aws-simple/launchpad.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ variable "launchpad" {
type = object({
drain = bool

mcr_version = string
mcr_channel = string
mke_version = string
msr_version = string // unused if you have no MSR hosts

Expand Down Expand Up @@ -137,8 +137,8 @@ locals {
// ------- Ye old launchpad yaml (just for debugging)

locals {
launchpad_yaml_15 = <<-EOT
apiVersion: launchpad.mirantis.com/mke/v1.5
launchpad_yaml = <<-EOT
apiVersion: launchpad.mirantis.com/mke/v1.6
kind: mke%{if local.has_msr}+msr%{endif}
metadata:
name: ${var.name}
Expand All @@ -165,11 +165,9 @@ spec:
insecure: ${h.winrm_insecure}
%{~endfor}
mcr:
version: ${var.launchpad.mcr_version}
channel: ${var.launchpad.mcr_channel}
repoURL: https://repos.mirantis.com
installURLLinux: https://get.mirantis.com/
installURLWindows: https://get.mirantis.com/install.ps1
channel: stable-25.0
prune: true
mke:
version: ${var.launchpad.mke_version}
Expand Down Expand Up @@ -199,7 +197,7 @@ EOT
output "launchpad_yaml" {
description = "launchpad config file yaml (for debugging)"
sensitive = true
value = local.launchpad_yaml_15
value = local.launchpad_yaml
}

output "mke_connect" {
Expand Down
26 changes: 17 additions & 9 deletions examples/terraform/aws-simple/terraform.tfvars.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ aws = {
launchpad = {
drain = false

mcr_version = "25.0.13"
mcr_channel = "stable-25.0.14"
mke_version = "3.8.8"
msr_version = "2.9.28"

mke_connect = {
username = "admin"
password = "" // an MKE passwords must be provided
password = "" // an MKE password must be provided
insecure = true
}

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
20 changes: 20 additions & 0 deletions jn-todo.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
* JNesbitt informal todo list

** code-quality

*** 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. Maybe the configurer should have methods to write/read the MCR configuration.

** linting

*** general interface{} -> any replace

There are a lot of `interface{}` types declared in the code base that should be changed to `any`
2 changes: 1 addition & 1 deletion pkg/analytics/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/Mirantis/launchpad/pkg/config/user"
"github.com/stretchr/testify/require"
"github.com/segmentio/analytics-go/v3"
"github.com/stretchr/testify/require"
)

type mockClient struct {
Expand Down
56 changes: 56 additions & 0 deletions pkg/config/migration/v15/v15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package v15

import (
"fmt"
"strings"

"github.com/Mirantis/launchpad/pkg/config/migration"
log "github.com/sirupsen/logrus"
)

// Migrate migrates a v1.5 format configuration into the v1.6 api format and replaces the contents of the supplied data byte slice.
//
// 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
func Migrate(plain map[string]any) error {
plain["apiVersion"] = "launchpad.mirantis.com/mke/v1.6"
if spec, ok := plain["spec"].(map[any]any); ok {
if mcr, ok := spec["mcr"].(map[any]any); ok {
version := mcr["version"] // if "version: 25.0" it could be parsed as a float64 instead of a string
channel := mcr["channel"]

channels, ok := channel.(string)
if !ok {
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
}

versions, ok := version.(string)
if !ok { // handle some frustrating yaml parsing issues for version v`alues
if versionf, ok := version.(float64); ok { // version: 25.0 : produces`` a float64
versions = fmt.Sprintf("%.1f", versionf)
} else if versioni, ok := version.(int); ok { // version: 25 : produces an integer
versions = fmt.Sprintf("%d.0", versioni)
} else {
log.Warnf("unclear version for migration: %+v (%T)", version, version)
}
}

// channel might already be `stable-25.0` but a version was passed, so we overrid it with a version passed
if channelsParts := strings.Split(channels, "-"); len(channelsParts) > 1 {
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)
channels = channelsParts[0]
}

mcr["channel"] = fmt.Sprintf("%s-%s", channels, versions)
delete(mcr, "version")
}
}

log.Debugf("migrated configuration from launchpad.mirantis.com/v1.4 to launchpad.mirantis.com/mke/v1.5")
log.Infof("Note: The configuration has been migrated from a previous version")
log.Infof(" to see the migrated configuration use: launchpad describe config")
return nil
}

func init() {
migration.Register("launchpad.mirantis.com/mke/v1.5", Migrate)
}
110 changes: 110 additions & 0 deletions pkg/config/migration/v15/v15_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package v15

import (
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)

func TestVersionMigrationSimple(t *testing.T) {
v15 := []byte(`---
apiVersion: launchpad.mirantis.com/mke/v1.5
kind: mke
spec:
mcr:
channel: stable
repoURL: https://repos.mirantis.com
version: 25.0.14
mke:
adminUsername: admin
imageRepo: docker.io/mirantis
version: 3.8.6
`)

v16 := []byte(`apiVersion: launchpad.mirantis.com/mke/v1.6
kind: mke
spec:
mcr:
channel: stable-25.0.14
repoURL: https://repos.mirantis.com
mke:
adminUsername: admin
imageRepo: docker.io/mirantis
version: 3.8.6
`)
in := make(map[string]any)
require.NoError(t, yaml.Unmarshal(v15, in))
require.NoError(t, Migrate(in))
out, err := yaml.Marshal(in)
require.NoError(t, err)
require.Equal(t, string(v16), string(out))
}

func TestVersionMigrationDefault(t *testing.T) {
v15 := []byte(`---
apiVersion: launchpad.mirantis.com/mke/v1.5
kind: mke
spec:
mcr:
channel: stable
repoURL: https://repos.mirantis.com
version: 25.0
mke:
adminUsername: admin
imageRepo: docker.io/mirantis
version: 3.8.6
`)

v16 := []byte(`apiVersion: launchpad.mirantis.com/mke/v1.6
kind: mke
spec:
mcr:
channel: stable-25.0
repoURL: https://repos.mirantis.com
mke:
adminUsername: admin
imageRepo: docker.io/mirantis
version: 3.8.6
`)
in := make(map[string]any)
require.NoError(t, yaml.Unmarshal(v15, in))
require.NoError(t, Migrate(in))
out, err := yaml.Marshal(in)
require.NoError(t, err)
require.Equal(t, string(v16), string(out))
}

func TestVersionMigrationSlim(t *testing.T) {
v15 := []byte(`---
apiVersion: launchpad.mirantis.com/mke/v1.5
kind: mke
spec:
mcr:
channel: stable
repoURL: https://repos.mirantis.com
version: 25
mke:
adminUsername: admin
imageRepo: docker.io/mirantis
version: 3.8.6
`)

v16 := []byte(`apiVersion: launchpad.mirantis.com/mke/v1.6
kind: mke
spec:
mcr:
channel: stable-25.0
repoURL: https://repos.mirantis.com
mke:
adminUsername: admin
imageRepo: docker.io/mirantis
version: 3.8.6
`)
in := make(map[string]any)
require.NoError(t, yaml.Unmarshal(v15, in))
require.NoError(t, Migrate(in))
out, err := yaml.Marshal(in)
require.NoError(t, err)
require.Equal(t, string(v16), string(out))
}
13 changes: 1 addition & 12 deletions pkg/configurer/centos/centos.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
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"
)

Expand All @@ -14,20 +11,12 @@ 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
Loading
Loading