Skip to content

Commit e0098f4

Browse files
authored
fix(e2e): dynamically set Windows OS version for credential provider tests (#10415)
1 parent e044359 commit e0098f4

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

tests/e2e/auth/cred.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ var _ = Describe("Azure Credential Provider", Label(utils.TestSuiteLabelCredenti
141141

142142
testPull("mcr.microsoft.com/mirror/docker/library/nginx", "1.25", "linux")
143143
if tc.HasWindowsNodes {
144-
testPull("mcr.microsoft.com/windows/nanoserver", "ltsc2019", "windows")
144+
testPull("mcr.microsoft.com/windows/nanoserver", tc.WindowsOSVersion, "windows")
145145
}
146146
})
147147
})

tests/e2e/utils/azure_test_client.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141

4242
var (
4343
azureResourceGroupNameRE = regexp.MustCompile(`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/(?:.*)`)
44+
windowsServerYearRE = regexp.MustCompile(`\b20\d{2}\b`)
4445
nodeLabelLocation = "failure-domain.beta.kubernetes.io/region"
4546
defaultLocation = "eastus2"
4647
)
@@ -54,6 +55,7 @@ type AzureTestClient struct {
5455
azFactoryConfig *azclient.ClientFactoryConfig
5556
IPFamily IPFamily
5657
HasWindowsNodes bool
58+
WindowsOSVersion string
5759
}
5860

5961
// CreateAzureTestClient makes a new AzureTestClient
@@ -91,9 +93,11 @@ func CreateAzureTestClient() (*AzureTestClient, error) {
9193
}
9294

9395
hasWindowsNodes := false
96+
windowsOSVersion := ""
9497
for _, node := range nodes {
9598
if os, ok := node.Labels["kubernetes.io/os"]; ok && os == "windows" {
9699
hasWindowsNodes = true
100+
windowsOSVersion = nanoserverTagFromOSImage(node.Status.NodeInfo.OSImage)
97101
break
98102
}
99103
}
@@ -113,8 +117,9 @@ func CreateAzureTestClient() (*AzureTestClient, error) {
113117
location: location,
114118
resourceGroup: resourceGroup,
115119
IPFamily: ipFamily,
116-
HasWindowsNodes: hasWindowsNodes,
117-
authConfig: authConfig,
120+
HasWindowsNodes: hasWindowsNodes,
121+
WindowsOSVersion: windowsOSVersion,
122+
authConfig: authConfig,
118123
azFactoryConfig: clientFactoryConfig,
119124
client: azFactory,
120125
}
@@ -228,3 +233,12 @@ func getLocationFromNodeLabels(node *v1.Node) string {
228233
}
229234
return defaultLocation
230235
}
236+
237+
// nanoserverTagFromOSImage extracts the Windows Server year from the node's OSImage
238+
// (e.g. "Windows Server 2022 Datacenter") and returns the nanoserver tag (e.g. "ltsc2022").
239+
func nanoserverTagFromOSImage(osImage string) string {
240+
if year := windowsServerYearRE.FindString(osImage); year != "" {
241+
return "ltsc" + year
242+
}
243+
return "ltsc2022"
244+
}

0 commit comments

Comments
 (0)