Skip to content

Commit dc0c3fa

Browse files
authored
Merge pull request #1995 from CecileRobertMichon/fix-latest-patch-e2e
e2e: Use the intersection of images available for windows and ubuntu to determine latest patch
2 parents cd67290 + 450e2d9 commit dc0c3fa

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

test/e2e/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build e2e
12
// +build e2e
23

34
/*
@@ -70,6 +71,7 @@ const (
7071
ManagedClustersResourceType = "managedClusters"
7172
capiImagePublisher = "cncf-upstream"
7273
capiOfferName = "capi"
74+
capiWindowsOfferName = "capi-windows"
7375
)
7476

7577
func Byf(format string, a ...interface{}) {

test/e2e/config/azure-dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ providers:
183183

184184
variables:
185185
AKS_KUBERNETES_VERSION: "${KUBERNETES_VERSION:-stable-1.19}"
186-
KUBERNETES_VERSION: "${KUBERNETES_VERSION:=v1.22.5}"
186+
KUBERNETES_VERSION: "${KUBERNETES_VERSION:=stable-1.22}"
187187
ETCD_VERSION_UPGRADE_TO: "3.5.0-0"
188188
COREDNS_VERSION_UPGRADE_TO: "v1.8.4"
189-
KUBERNETES_VERSION_UPGRADE_TO: "${KUBERNETES_VERSION_UPGRADE_TO:=v1.22.5}"
189+
KUBERNETES_VERSION_UPGRADE_TO: "${KUBERNETES_VERSION_UPGRADE_TO:=stable-1.22}"
190190
KUBERNETES_VERSION_UPGRADE_FROM: "${KUBERNETES_VERSION_UPGRADE_FROM:-v1.22.1}" # this needs to be 1.22+ to support mixed windows/linux clusters until we update CAPI to v1.0.1.
191191
CNI: "${PWD}/templates/addons/calico.yaml"
192192
REDACT_LOG_SCRIPT: "${PWD}/hack/log/redact.sh"

test/e2e/e2e_suite_test.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build e2e
12
// +build e2e
23

34
/*
@@ -411,8 +412,19 @@ func tearDown(bootstrapClusterProvider bootstrap.ClusterProvider, bootstrapClust
411412
// resolveKubernetesVersions looks at Kubernetes versions set as variables in the e2e config and sets them to a valid k8s version
412413
// that has an existing capi offer image available. For example, if the version is "stable-1.22", the function will set it to the latest 1.22 version that has a published reference image.
413414
func resolveKubernetesVersions(config *clusterctl.E2EConfig) {
414-
skus := getAllCAPIImageSkus(context.TODO(), os.Getenv(AzureLocation))
415-
versions := parseImageSkuNames(skus)
415+
ubuntuSkus := getImageSkusInOffer(context.TODO(), os.Getenv(AzureLocation), capiImagePublisher, capiOfferName)
416+
ubuntuVersions := parseImageSkuNames(ubuntuSkus)
417+
418+
windowsSkus := getImageSkusInOffer(context.TODO(), os.Getenv(AzureLocation), capiImagePublisher, capiWindowsOfferName)
419+
windowsVersions := parseImageSkuNames(windowsSkus)
420+
421+
// find the intersection of ubuntu and windows versions available, since we need an image for both.
422+
var versions semver.Versions
423+
for k, v := range ubuntuVersions {
424+
if _, ok := windowsVersions[k]; ok {
425+
versions = append(versions, v)
426+
}
427+
}
416428

417429
if config.HasVariable(capi_e2e.KubernetesVersion) {
418430
resolveKubernetesVersion(config, versions, capi_e2e.KubernetesVersion)
@@ -433,8 +445,8 @@ func resolveKubernetesVersion(config *clusterctl.E2EConfig, versions semver.Vers
433445
config.Variables[varName] = v
434446
}
435447

436-
// getAllCAPIImageSkus returns all skus for the capi offer under the "cncf-upstream" publisher.
437-
func getAllCAPIImageSkus(ctx context.Context, location string) []string {
448+
// getImageSkusInOffer returns all skus for an offer that have at least one image.
449+
func getImageSkusInOffer(ctx context.Context, location, publisher, offer string) []string {
438450
settings, err := auth.GetSettingsFromEnvironment()
439451
Expect(err).NotTo(HaveOccurred())
440452
subscriptionID := settings.GetSubscriptionID()
@@ -443,9 +455,9 @@ func getAllCAPIImageSkus(ctx context.Context, location string) []string {
443455
imagesClient := compute.NewVirtualMachineImagesClient(subscriptionID)
444456
imagesClient.Authorizer = authorizer
445457

446-
Byf("Finding image skus for offer %s/%s in %s", capiImagePublisher, capiOfferName, location)
458+
Byf("Finding image skus for offer %s/%s in %s", publisher, offer, location)
447459

448-
res, err := imagesClient.ListSkus(ctx, location, capiImagePublisher, capiOfferName)
460+
res, err := imagesClient.ListSkus(ctx, location, publisher, offer)
449461
Expect(err).NotTo(HaveOccurred())
450462

451463
var skus []string
@@ -454,7 +466,7 @@ func getAllCAPIImageSkus(ctx context.Context, location string) []string {
454466
for i, sku := range *res.Value {
455467
// we have to do this to make sure the SKU has existing images
456468
// see https://github.com/Azure/azure-cli/issues/20115.
457-
res, err := imagesClient.List(ctx, location, capiImagePublisher, capiOfferName, *sku.Name, "", nil, "")
469+
res, err := imagesClient.List(ctx, location, publisher, offer, *sku.Name, "", nil, "")
458470
Expect(err).NotTo(HaveOccurred())
459471
if res.Value != nil && len(*res.Value) > 0 {
460472
skus[i] = *sku.Name
@@ -464,17 +476,19 @@ func getAllCAPIImageSkus(ctx context.Context, location string) []string {
464476
return skus
465477
}
466478

467-
// parseImageSkuNames parses SKU names in format "k8s-1dot17dot2-ubuntu-1804" to extract the Kubernetes version.
479+
// parseImageSkuNames parses SKU names in format "k8s-1dot17dot2-os-123" to extract the Kubernetes version.
468480
// it returns a sorted list of all k8s versions found.
469-
func parseImageSkuNames(skus []string) semver.Versions {
470-
var capiSku = regexp.MustCompile(`^k8s-(0|[1-9][0-9]*)dot(0|[1-9][0-9]*)dot(0|[1-9][0-9]*)-ubuntu.*$`)
471-
versions := make(semver.Versions, len(skus))
472-
for i, sku := range skus {
481+
func parseImageSkuNames(skus []string) map[string]semver.Version {
482+
capiSku := regexp.MustCompile(`^k8s-(0|[1-9][0-9]*)dot(0|[1-9][0-9]*)dot(0|[1-9][0-9]*)-[a-z]*.*$`)
483+
versions := make(map[string]semver.Version, len(skus))
484+
for _, sku := range skus {
473485
match := capiSku.FindStringSubmatch(sku)
474486
if len(match) != 0 {
475-
versions[i] = semver.MustParse(fmt.Sprintf("%s.%s.%s", match[1], match[2], match[3]))
487+
stringVer := fmt.Sprintf("%s.%s.%s", match[1], match[2], match[3])
488+
versions[stringVer] = semver.MustParse(stringVer)
476489
}
477490
}
491+
478492
return versions
479493
}
480494

0 commit comments

Comments
 (0)