Skip to content

Commit 7c5f220

Browse files
committed
Add ci test script to test the bundle feature flag in the connectedk8s extension and resolve the ruff check failure
1 parent 2355932 commit 7c5f220

4 files changed

Lines changed: 208 additions & 16 deletions

File tree

src/connectedk8s/azext_connectedk8s/custom.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,16 @@ def get_bundle_feature_flag_from_arc_agentry_config(
15611561
) -> str | None:
15621562
try:
15631563
for agentry_config in current_arc_agentry_config or []:
1564-
if agentry_config.feature == consts.Arc_Agentry_Bundle_Feature and agentry_config.settings and (
1565-
consts.Arc_Agentry_Bundle_Feature_Setting in agentry_config.settings
1564+
if (
1565+
agentry_config.feature == consts.Arc_Agentry_Bundle_Feature
1566+
and agentry_config.settings
1567+
and (
1568+
consts.Arc_Agentry_Bundle_Feature_Setting in agentry_config.settings
1569+
)
15661570
):
1567-
return agentry_config.settings[consts.Arc_Agentry_Bundle_Feature_Setting].lower()
1571+
return agentry_config.settings[
1572+
consts.Arc_Agentry_Bundle_Feature_Setting
1573+
].lower()
15681574
return None
15691575

15701576
except Exception as e: # pylint: disable=broad-except
@@ -1603,8 +1609,9 @@ def get_bundle_feature_flag_from_configuration_settings(
16031609
def validate_bundle_feature_flag_value(
16041610
configuration_settings: dict[str, Any],
16051611
) -> str | None:
1606-
1607-
print(f"Step: {utils.get_utctimestring()}: Validating the bundle feature flag value")
1612+
print(
1613+
f"Step: {utils.get_utctimestring()}: Validating the bundle feature flag value"
1614+
)
16081615
value = get_bundle_feature_flag_from_configuration_settings(configuration_settings)
16091616

16101617
if value is not None:
@@ -1623,8 +1630,12 @@ def validate_bundle_feature_flag_value(
16231630
)
16241631
raise InvalidArgumentValueError(err_msg)
16251632

1626-
configuration_settings[consts.Arc_Agentry_Bundle_Feature][consts.Arc_Agentry_Bundle_Feature_Setting] = value
1627-
print(f"Step: {utils.get_utctimestring()}: Setting the bundle feature flag value to '{value}'")
1633+
configuration_settings[consts.Arc_Agentry_Bundle_Feature][
1634+
consts.Arc_Agentry_Bundle_Feature_Setting
1635+
] = value
1636+
print(
1637+
f"Step: {utils.get_utctimestring()}: Setting the bundle feature flag value to '{value}'"
1638+
)
16281639

16291640
return value
16301641

@@ -1633,7 +1644,9 @@ def validate_connect_cluster_bundle_feature_flag_value(
16331644
configuration_settings: dict[str, Any],
16341645
yes: bool = False,
16351646
):
1636-
bundle_feature_flag_value = validate_bundle_feature_flag_value(configuration_settings)
1647+
bundle_feature_flag_value = validate_bundle_feature_flag_value(
1648+
configuration_settings
1649+
)
16371650

16381651
# If the bundle feature flag value is None, skip the validation
16391652
if bundle_feature_flag_value is None:
@@ -1675,13 +1688,17 @@ def validate_update_cluster_bundle_feature_flag_value(
16751688
resource_group_name: str,
16761689
cluster_name: str,
16771690
):
1678-
bundle_feature_flag_value = validate_bundle_feature_flag_value(configuration_settings)
1691+
bundle_feature_flag_value = validate_bundle_feature_flag_value(
1692+
configuration_settings
1693+
)
16791694

16801695
# If the bundle feature flag value is None, skip the validation
16811696
if bundle_feature_flag_value is None:
16821697
return
16831698

1684-
current_bundle_feature_flag_value = get_bundle_feature_flag_from_arc_agentry_config(current_arc_agentry_config)
1699+
current_bundle_feature_flag_value = get_bundle_feature_flag_from_arc_agentry_config(
1700+
current_arc_agentry_config
1701+
)
16851702

16861703
if bundle_feature_flag_value == "preview":
16871704
err_msg = (
@@ -1712,8 +1729,12 @@ def validate_update_cluster_bundle_feature_flag_value(
17121729

17131730
raise ArgumentUsageError(err_msg)
17141731

1715-
invalid_transition = (current_bundle_feature_flag_value == "enabled" and bundle_feature_flag_value == "") or (
1716-
current_bundle_feature_flag_value == "" and bundle_feature_flag_value == "disabled"
1732+
invalid_transition = (
1733+
current_bundle_feature_flag_value == "enabled"
1734+
and bundle_feature_flag_value == ""
1735+
) or (
1736+
current_bundle_feature_flag_value == ""
1737+
and bundle_feature_flag_value == "disabled"
17171738
)
17181739

17191740
if invalid_transition:
@@ -1730,11 +1751,17 @@ def validate_update_cluster_bundle_feature_flag_value(
17301751
raise ArgumentUsageError(err_msg)
17311752

17321753
# If the bundle feature flag is set to 'disabled', check if any bundle extensions are installed
1733-
if current_bundle_feature_flag_value == "enabled" and bundle_feature_flag_value == "disabled":
1734-
1735-
client_factory = get_k8s_extension_module(consts.CONST_K8S_EXTENSION_CLIENT_FACTORY_MOD_NAME)
1754+
if (
1755+
current_bundle_feature_flag_value == "enabled"
1756+
and bundle_feature_flag_value == "disabled"
1757+
):
1758+
client_factory = get_k8s_extension_module(
1759+
consts.CONST_K8S_EXTENSION_CLIENT_FACTORY_MOD_NAME
1760+
)
17361761
client = client_factory.cf_k8s_extension_operation(cmd.cli_ctx)
1737-
k8s_extension_custom_mod = get_k8s_extension_module(consts.CONST_K8S_EXTENSION_CUSTOM_MOD_NAME)
1762+
k8s_extension_custom_mod = get_k8s_extension_module(
1763+
consts.CONST_K8S_EXTENSION_CUSTOM_MOD_NAME
1764+
)
17381765

17391766
try:
17401767
extensions = k8s_extension_custom_mod.list_k8s_extension(

testing/pipeline/k8s-custom-pipelines.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ stages:
5656
parameters:
5757
jobName: ForcedDeleteTest
5858
path: ./test/configurations/ForcedDelete.Tests.ps1
59+
- template: ./templates/run-test.yml
60+
parameters:
61+
jobName: BundleFeatureFlagTest
62+
path: ./test/configurations/BundleFeatureFlag.Tests.ps1
5963
- job: BuildPublishExtension
6064
pool:
6165
vmImage: 'ubuntu-latest'
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Describe 'Setting Bundle Feature Flag Scenario' {
2+
BeforeAll {
3+
. $PSScriptRoot/../helper/Constants.ps1
4+
}
5+
6+
It 'Enable the bundle feature flag when connecting the cluster to Arc' {
7+
$output = & {
8+
az connectedk8s connect -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup -l $BUNDLE_FEATURE_TEST_ARC_LOCATION `
9+
--disable-auto-upgrade --config extensionSets.versionManagedExtensions='off' 2>&1 | Out-String
10+
}
11+
$output | Should -Match "Not supported value for the feature flag"
12+
13+
$output = & {
14+
az connectedk8s connect -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup -l $BUNDLE_FEATURE_TEST_ARC_LOCATION `
15+
--disable-auto-upgrade --config extensionSets.versionManagedExtensions='disabled' 2>&1 | Out-String
16+
}
17+
$output | Should -Match "'disabled' mode can only be set using 'az connectedk8s update'"
18+
19+
az connectedk8s connect -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup -l $BUNDLE_FEATURE_TEST_ARC_LOCATION `
20+
--disable-auto-upgrade --config extensionSets.versionManagedExtensions='preview' --no-wait --yes
21+
$? | Should -BeTrue
22+
Start-Sleep -Seconds 10
23+
24+
# Loop and retry until the configuration installs
25+
$n = 0
26+
do
27+
{
28+
$output = az connectedk8s show -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup
29+
$jsonOutput = [System.Text.Json.JsonDocument]::Parse($output)
30+
$provisioningState = ($output | ConvertFrom-Json).provisioningState
31+
$bundleFeatureFlag = $jsonOutput.RootElement.GetProperty("arcAgentryConfigurations")[0].GetProperty("settings").GetProperty("versionManagedExtensions").GetString()
32+
Write-Host "Provisioning State: $provisioningState"
33+
Write-Host "Bundle Feature Flag: $bundleFeatureFlag"
34+
if ($provisioningState -eq $SUCCEEDED -and $bundleFeatureFlag -eq "preview")
35+
{
36+
break
37+
}
38+
Start-Sleep -Seconds 10
39+
$n += 1
40+
} while ($n -le $MAX_RETRY_ATTEMPTS)
41+
$n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
42+
43+
$output = & {
44+
az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --auto-upgrade false `
45+
--config extensionSets.versionManagedExtensions='enabled' 2>&1 | Out-String
46+
}
47+
$output | Should -Match "The cluster is in versionManagedExtensions 'preview' mode, updating the value is not allowed."
48+
49+
az connectedk8s delete -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --force -y
50+
$? | Should -BeTrue
51+
Start-Sleep -Seconds 10
52+
53+
az connectedk8s connect -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup -l $BUNDLE_FEATURE_TEST_ARC_LOCATION `
54+
--disable-auto-upgrade --config extensionSets.versionManagedExtensions='enabled' --no-wait
55+
$? | Should -BeTrue
56+
Start-Sleep -Seconds 10
57+
58+
# Loop and retry until the configuration installs
59+
$n = 0
60+
do
61+
{
62+
$output = az connectedk8s show -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup
63+
$jsonOutput = [System.Text.Json.JsonDocument]::Parse($output)
64+
$provisioningState = ($output | ConvertFrom-Json).provisioningState
65+
$bundleFeatureFlag = $jsonOutput.RootElement.GetProperty("arcAgentryConfigurations")[0].GetProperty("settings").GetProperty("versionManagedExtensions").GetString()
66+
Write-Host "Provisioning State: $provisioningState"
67+
Write-Host "Bundle Feature Flag: $bundleFeatureFlag"
68+
if ($provisioningState -eq $SUCCEEDED -and $bundleFeatureFlag -eq "enabled")
69+
{
70+
break
71+
}
72+
Start-Sleep -Seconds 10
73+
$n += 1
74+
} while ($n -le $MAX_RETRY_ATTEMPTS)
75+
$n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
76+
}
77+
78+
It 'Enable the bundle feature flag using update cmd' {
79+
$output = & {
80+
az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --auto-upgrade false `
81+
--config extensionSets.versionManagedExtensions='on' 2>&1 | Out-String
82+
}
83+
$output | Should -Match "Not supported value for the feature flag"
84+
85+
$output = & {
86+
az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --auto-upgrade false `
87+
--config extensionSets.versionManagedExtensions='preview' 2>&1 | Out-String
88+
}
89+
$output | Should -Match "Updating the preview mode config with 'az connectedk8s update' is not allowed"
90+
91+
$output = & {
92+
az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --auto-upgrade false `
93+
--config extensionSets.versionManagedExtensions='' 2>&1 | Out-String
94+
}
95+
$output | Should -Match "Could not set extensionSets.versionManagedExtensions from 'enabled' to ''"
96+
97+
az k8s-extension create --cluster-name $ENVCONFIG.arcClusterName --resource-group $ENVCONFIG.resourceGroup `
98+
--cluster-type connectedClusters --extension-type microsoft.iotoperations.platform `
99+
--name azure-iot-operations-platform --release-train preview --auto-upgrade-minor-version False `
100+
--config installTrustManager=true --config installCertManager=true --version 0.7.6 `
101+
--release-namespace cert-manager --scope cluster
102+
$? | Should -BeTrue
103+
Start-Sleep -Seconds 10
104+
105+
az k8s-extension create --cluster-name $ENVCONFIG.arcClusterName --resource-group $ENVCONFIG.resourceGroup `
106+
--cluster-type connectedClusters --extension-type microsoft.azure.secretstore `
107+
--name azure-secret-store --auto-upgrade-minor-version False `
108+
--config rotationPollIntervalInSeconds=120 --config validatingAdmissionPolicies.applyPolicies=false `
109+
--scope cluster
110+
$? | Should -BeTrue
111+
Start-Sleep -Seconds 10
112+
113+
$output = & {
114+
az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --auto-upgrade false `
115+
--config extensionSets.versionManagedExtensions='disabled' 2>&1 | Out-String
116+
}
117+
$output | Should -Match "detected the following extension types on the cluster"
118+
119+
az k8s-extension delete --cluster-name $ENVCONFIG.arcClusterName --resource-group $ENVCONFIG.resourceGroup `
120+
--cluster-type connectedClusters --name azure-secret-store --yes
121+
$? | Should -BeTrue
122+
123+
az k8s-extension delete --cluster-name $ENVCONFIG.arcClusterName --resource-group $ENVCONFIG.resourceGroup `
124+
--cluster-type connectedClusters --name azure-iot-operations-platform --yes
125+
$? | Should -BeTrue
126+
127+
az connectedk8s update -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --auto-upgrade false `
128+
--config extensionSets.versionManagedExtensions='disabled'
129+
$? | Should -BeTrue
130+
Start-Sleep -Seconds 10
131+
132+
# Loop and retry until the configuration installs
133+
$n = 0
134+
do
135+
{
136+
$output = az connectedk8s show -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup
137+
$jsonOutput = [System.Text.Json.JsonDocument]::Parse($output)
138+
$provisioningState = ($output | ConvertFrom-Json).provisioningState
139+
$bundleFeatureFlag = $jsonOutput.RootElement.GetProperty("arcAgentryConfigurations")[0].GetProperty("settings").GetProperty("versionManagedExtensions").GetString()
140+
Write-Host "Provisioning State: $provisioningState"
141+
Write-Host "Bundle Feature Flag: $bundleFeatureFlag"
142+
if ($provisioningState -eq $SUCCEEDED -and $bundleFeatureFlag -eq "disabled")
143+
{
144+
break
145+
}
146+
Start-Sleep -Seconds 10
147+
$n += 1
148+
} while ($n -le $MAX_RETRY_ATTEMPTS)
149+
$n | Should -BeLessOrEqual $MAX_RETRY_ATTEMPTS
150+
}
151+
152+
It "Delete the connected instance" {
153+
az connectedk8s delete -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup --force -y
154+
$? | Should -BeTrue
155+
156+
# Configuration should be removed from the resource model
157+
az connectedk8s show -n $ENVCONFIG.arcClusterName -g $ENVCONFIG.resourceGroup
158+
$? | Should -BeFalse
159+
}
160+
}

testing/test/helper/Constants.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ $ENVCONFIG = Get-Content -Path $PSScriptRoot/../../settings.json | ConvertFrom-J
22

33
$MAX_RETRY_ATTEMPTS = 30
44
$ARC_LOCATION = "uksouth"
5+
$BUNDLE_FEATURE_TEST_ARC_LOCATION = "eastus2euap"
56
$SUCCEEDED = "Succeeded"

0 commit comments

Comments
 (0)