[WIP] start machine now accepts a base datastructure#100
Open
jack-w-shaw wants to merge 1 commit into
Open
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
SimonRichardson
requested changes
Jul 6, 2023
Comment on lines
+13
to
+81
| 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", | ||
| } |
Member
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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