-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] start machine now accepts a base datastructure #100
base: v2
Are you sure you want to change the base?
Conversation
This is converted to a series if deploying with base isn't supported As a flyby, tidy go.mod and replace github.com/juju/version with github.com/juju/version/v2
var VersionDeploySupportsBases = version.Number{Major: 3, Minor: 3, Patch: 5} | ||
|
||
type OSType string | ||
|
||
var ( | ||
Custom OSType = "custom" | ||
Ubuntu OSType = "ubuntu" | ||
Centos OSType = "centos" | ||
) | ||
|
||
type Base struct { | ||
OS OSType | ||
Version string | ||
} | ||
|
||
func (b Base) String() string { | ||
if b.OS != "" && b.Version != "" { | ||
return fmt.Sprintf("%s/%s", b.OS, b.Version) | ||
} | ||
if b.Version != "" { | ||
return b.Version | ||
} | ||
return "" | ||
} | ||
|
||
func (b Base) toSeries() (string, error) { | ||
if b.OS == "" { | ||
return b.Version, nil | ||
} | ||
switch b.OS { | ||
case Custom: | ||
return b.String(), nil | ||
case Ubuntu: | ||
if series, ok := ubuntuMap[b.Version]; ok { | ||
return series, nil | ||
} | ||
return "", errors.NotValidf("base %s cannot be converted into a series", b) | ||
case Centos: | ||
if series, ok := centosMap[b.Version]; ok { | ||
return series, nil | ||
} | ||
return "", errors.NotValidf("base %s cannot be converted into a series", b) | ||
default: | ||
return "", errors.NotValidf("base %s OS", b) | ||
} | ||
|
||
} | ||
|
||
const ( | ||
centos7 = "centos7" | ||
centos8 = "centos8" | ||
centos9 = "centos9" | ||
) | ||
|
||
var ubuntuMap = map[string]string{ | ||
"20.04": "ubuntu/focal", | ||
"20.10": "ubuntu/groovy", | ||
"21.04": "ubuntu/hirsute", | ||
"21.10": "ubuntu/impish", | ||
"22.04": "ubuntu/jammy", | ||
"22.10": "ubuntu/kinetic", | ||
"23.04": "ubuntu/lunar", | ||
} | ||
|
||
var centosMap = map[string]string{ | ||
"7": "centos/centos7", | ||
"8": "centos/centos8", | ||
"9": "centos/centos9", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite the right approach.
So we don't want to hardcode the versions here. That's for juju to request and for MAAS to say are valid or not. What I was looking for is just a Base
type that you can validate up front. Either from a string ParseBase
which will return a valid Base
or NewBase
which takes the concrete types. Both of which should validate the consistency of a base.
For example, you can't set OS without a Version.
What we don't want is to have that lazily. If toSeries
was called Validate
(minus the concrete version checking), then that would be ideal.
This is converted to a series if deploying with base isn't supported
As a flyby, tidy go.mod and replace github.com/juju/version with github.com/juju/version/v2