Skip to content
Merged
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
25 changes: 21 additions & 4 deletions pkg/maas/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,23 @@ const (
clusterNamespacePrefix = "cluster-"
clusterNamespacePrefixLen = len(clusterNamespacePrefix)
hashIDLength = 8 // Length of hash-based cluster ID

// customOSSystem is the MAAS osystem for legacy non-prefixed custom images.
customOSSystem = "custom"
)

// splitImage derives the MAAS osystem and distro_series from a boot-resource
// image name. A prefixed name ("<osystem>/<series>", e.g. "rhel/rocky-92-0-k-1285-0")
// deploys under that osystem so MAAS handles the OS correctly; a legacy
// non-prefixed name keeps osystem "custom" (no behavior change for existing
// Ubuntu images).
func splitImage(image string) (osystem, distroSeries string) {
if os, series, found := strings.Cut(image, "/"); found {
return os, series
}
return customOSSystem, image
}

type Service struct {
scope *scope.MachineScope
maasClient maasclient.ClientSetInterface
Expand Down Expand Up @@ -264,10 +279,11 @@ func (s *Service) DeployMachine(userDataB64 string) (_ *infrav1beta1.Machine, re
}

s.scope.Info("Starting deployment", "system-id", m.SystemID())
osystem, distroSeries := splitImage(mm.Spec.Image)
deployingM, err := m.Deployer().
SetUserData(userDataB64).
SetOSSystem("custom").
SetDistroSeries(mm.Spec.Image).Deploy(ctx)
SetOSSystem(osystem).
SetDistroSeries(distroSeries).Deploy(ctx)
if err != nil {
return nil, errors.Wrapf(err, "Unable to deploy machine")
}
Expand Down Expand Up @@ -306,10 +322,11 @@ func (s *Service) createVMViaMAAS(ctx context.Context, userDataB64 string) (*inf
}
}
}
osystem, distroSeries := splitImage(mm.Spec.Image)
deployingM, err := m.Deployer().
SetUserData(userDataB64).
SetOSSystem("custom").
SetDistroSeries(mm.Spec.Image).Deploy(ctx)
SetOSSystem(osystem).
SetDistroSeries(distroSeries).Deploy(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to deploy existing VM")
}
Expand Down
56 changes: 56 additions & 0 deletions pkg/maas/machine/splitimage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package machine

import (
"testing"

. "github.com/onsi/gomega"
)

func TestSplitImage(t *testing.T) {
tests := []struct {
name string
image string
wantOSSystem string
wantDistro string
}{
{
name: "prefixed rhel image",
image: "rhel/rocky-92-0-k-1285-0",
wantOSSystem: "rhel",
wantDistro: "rocky-92-0-k-1285-0",
},
{
name: "prefixed suse image",
image: "suse/sles-15-0-k-1304-0",
wantOSSystem: "suse",
wantDistro: "sles-15-0-k-1304-0",
},
{
name: "prefixed ubuntu image",
image: "ubuntu/u-2204-0-k-1329-0",
wantOSSystem: "ubuntu",
wantDistro: "u-2204-0-k-1329-0",
},
{
name: "legacy non-prefixed image stays custom",
image: "u-2204-0-k-1329-0",
wantOSSystem: "custom",
wantDistro: "u-2204-0-k-1329-0",
},
{
name: "empty image stays custom",
image: "",
wantOSSystem: "custom",
wantDistro: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewGomegaWithT(t)
osystem, distro := splitImage(tt.image)
g.Expect(osystem).To(Equal(tt.wantOSSystem))
g.Expect(distro).To(Equal(tt.wantDistro))
})
}
}
Loading