-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upstream/3.6' into 3.6-into-main
- Loading branch information
Showing
26 changed files
with
269 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,6 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check if CLA signed | ||
uses: canonical/[email protected].2 | ||
uses: canonical/[email protected].3 | ||
with: | ||
accept-existing-contributors: true |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,3 +80,41 @@ func (s *BaseSuite) TestParseManifestBases(c *gc.C) { | |
} | ||
c.Assert(obtained, jc.DeepEquals, expected) | ||
} | ||
|
||
var ubuntuLTS = []Base{ | ||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]/stable"), | ||
MustParseBaseFromString("[email protected]/edge"), | ||
} | ||
|
||
func (s *BaseSuite) TestIsUbuntuLTSForLTSes(c *gc.C) { | ||
for i, lts := range ubuntuLTS { | ||
c.Logf("Checking index %d base %v", i, lts) | ||
c.Check(lts.IsUbuntuLTS(), jc.IsTrue) | ||
} | ||
} | ||
|
||
var nonUbuntuLTS = []Base{ | ||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
|
||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
|
||
MustParseBaseFromString("[email protected]"), | ||
MustParseBaseFromString("[email protected]"), | ||
|
||
MustParseBaseFromString("centos@7"), | ||
MustParseBaseFromString("[email protected]"), | ||
} | ||
|
||
func (s *BaseSuite) TestIsUbuntuLTSForNonLTSes(c *gc.C) { | ||
for i, lts := range nonUbuntuLTS { | ||
c.Logf("Checking index %d base %v", i, lts) | ||
c.Check(lts.IsUbuntuLTS(), jc.IsFalse) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,17 @@ const ( | |
ubuntuPublisher = "Canonical" | ||
|
||
dailyStream = "daily" | ||
|
||
plan = "server-gen1" | ||
) | ||
|
||
// SeriesImage gets an instances.Image for the specified series, image stream | ||
// BaseImage gets an instances.Image for the specified base, image stream | ||
// and location. The resulting Image's ID is in the URN format expected by | ||
// Azure Resource Manager. | ||
// | ||
// For Ubuntu, we query the SKUs to determine the most recent point release | ||
// for a series. | ||
func SeriesImage( | ||
func BaseImage( | ||
ctx envcontext.ProviderCallContext, | ||
base jujubase.Base, stream, location string, | ||
client *armcompute.VirtualMachineImagesClient, | ||
|
@@ -77,19 +79,91 @@ func SeriesImage( | |
}, nil | ||
} | ||
|
||
func offerForUbuntuSeries(series string) string { | ||
return fmt.Sprintf("0001-com-ubuntu-server-%s", series) | ||
// legacyUbuntuBases is a slice of bases which use the old-style offer | ||
// id formatted like "0001-com-ubuntu-server-${series}". | ||
// | ||
// Recently Canonical changed the format for images offer ids | ||
// and SKUs in Azure. The threshold for this change was noble, so if | ||
// we want to deploy bases before noble, we must branch and use the | ||
// old format. | ||
// | ||
// The old format offer ids have format `0001-com-ubuntu-server-${series}` | ||
// or `001-com-ubuntu-server-${series}-daily` and have SKUs formatted | ||
// `${version_number}-lts`, `${version_number}-gen2`, etc. | ||
// | ||
// The new format offer ids have format `ubuntu-${version_number}`, | ||
// `ubuntu-${version_number}-lts`, `ubuntu-${version_number}-lts-daily`, | ||
// etc. and have SKUs `server`, `server-gen1`m, `server-arm64`, etc. | ||
// | ||
// Since there are only a finte number of Ubuntu versions we support | ||
// before Noble, we hardcode this list. So when new versions of Ubuntu | ||
// are | ||
// | ||
// All Ubuntu images we support outside of this list have offer | ||
// id like "ubuntu-${version}-lts" or "ubuntu-${version}" | ||
var legacyUbuntuBases = []jujubase.Base{ | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
jujubase.MustParseBaseFromString("[email protected]"), | ||
} | ||
|
||
func ubuntuBaseIslegacy(base jujubase.Base) bool { | ||
for _, oldBase := range legacyUbuntuBases { | ||
if base.IsCompatible(oldBase) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// ubuntuSKU returns the best SKU for the Canonical:UbuntuServer offering, | ||
// matching the given series. | ||
// | ||
// TODO(jack-w-shaw): Selecting the 'daily' stream is currently broken for legacy | ||
// Ubuntu SKU selection. See the following lp bug: | ||
// https://bugs.launchpad.net/juju/+bug/2067717 | ||
func ubuntuSKU(ctx envcontext.ProviderCallContext, base jujubase.Base, stream, location string, client *armcompute.VirtualMachineImagesClient) (string, string, error) { | ||
if ubuntuBaseIslegacy(base) { | ||
return legacyUbuntuSKU(ctx, base, stream, location, client) | ||
} | ||
|
||
offer := fmt.Sprintf("ubuntu-%s", strings.ReplaceAll(base.Channel.Track, ".", "_")) | ||
if base.IsUbuntuLTS() { | ||
offer = fmt.Sprintf("%s-lts", offer) | ||
} | ||
if stream == dailyStream { | ||
offer = fmt.Sprintf("%s-daily", offer) | ||
} | ||
|
||
logger.Debugf("listing SKUs: Location=%s, Publisher=%s, Offer=%s", location, ubuntuPublisher, offer) | ||
result, err := client.ListSKUs(ctx, location, ubuntuPublisher, offer, nil) | ||
if err != nil { | ||
return "", "", errorutils.HandleCredentialError(errors.Annotate(err, "listing Ubuntu SKUs"), ctx) | ||
} | ||
for _, img := range result.VirtualMachineImageResourceArray { | ||
skuName := *img.Name | ||
if skuName == plan { | ||
logger.Debugf("found Azure SKU Name: %v", skuName) | ||
return skuName, offer, nil | ||
} | ||
logger.Debugf("ignoring Azure SKU Name: %v", skuName) | ||
} | ||
return "", "", errors.NotFoundf("ubuntu %q SKUs for %v stream", base, stream) | ||
} | ||
|
||
func legacyUbuntuSKU(ctx envcontext.ProviderCallContext, base jujubase.Base, stream, location string, client *armcompute.VirtualMachineImagesClient) (string, string, error) { | ||
series, err := jujubase.GetSeriesFromBase(base) | ||
if err != nil { | ||
return "", "", errors.Trace(err) | ||
} | ||
offer := offerForUbuntuSeries(series) | ||
version := strings.ReplaceAll(base.Channel.Track, ".", "_") | ||
offer := fmt.Sprintf("0001-com-ubuntu-server-%s", series) | ||
desiredSKUPrefix := strings.ReplaceAll(base.Channel.Track, ".", "_") | ||
|
||
logger.Debugf("listing SKUs: Location=%s, Publisher=%s, Offer=%s", location, ubuntuPublisher, offer) | ||
result, err := client.ListSKUs(ctx, location, ubuntuPublisher, offer, nil) | ||
if err != nil { | ||
|
@@ -99,12 +173,12 @@ func ubuntuSKU(ctx envcontext.ProviderCallContext, base jujubase.Base, stream, l | |
var versions ubuntuVersions | ||
for _, img := range result.VirtualMachineImageResourceArray { | ||
skuName := *img.Name | ||
logger.Debugf("Found Azure SKU Name: %v", skuName) | ||
if !strings.HasPrefix(skuName, version) { | ||
logger.Debugf("ignoring SKU %q (does not match base %q with version %q)", skuName, base, version) | ||
logger.Debugf("found Azure SKU Name: %v", skuName) | ||
if !strings.HasPrefix(skuName, desiredSKUPrefix) { | ||
logger.Debugf("ignoring SKU %q (does not match series %q)", skuName, series) | ||
continue | ||
} | ||
version, tag, err := parseUbuntuSKU(skuName) | ||
version, tag, err := parselegacyUbuntuSKU(skuName) | ||
if err != nil { | ||
logger.Errorf("ignoring SKU %q (failed to parse: %s)", skuName, err) | ||
continue | ||
|
@@ -125,7 +199,7 @@ func ubuntuSKU(ctx envcontext.ProviderCallContext, base jujubase.Base, stream, l | |
versions = append(versions, version) | ||
} | ||
if len(versions) == 0 { | ||
return "", "", errors.NotFoundf("Ubuntu SKUs for %s stream", stream) | ||
return "", "", errors.NotFoundf("legacy ubuntu %q SKUs for %s stream", series, stream) | ||
} | ||
sort.Sort(versions) | ||
bestVersion := versions[len(versions)-1] | ||
|
@@ -138,9 +212,9 @@ type ubuntuVersion struct { | |
Point int | ||
} | ||
|
||
// parseUbuntuSKU splits an UbuntuServer SKU into its | ||
// parselegacyUbuntuSKU splits an UbuntuServer SKU into its | ||
// version ("22_04.3") and tag ("LTS") parts. | ||
func parseUbuntuSKU(sku string) (ubuntuVersion, string, error) { | ||
func parselegacyUbuntuSKU(sku string) (ubuntuVersion, string, error) { | ||
var version ubuntuVersion | ||
var tag string | ||
var err error | ||
|
Oops, something went wrong.