Python
fix(azure): use provider network receipts and safe DNS cleanup order
Rohit Pf598394b8599
diff --git a/harness/service-cli/src/deployment_azure_infrastructure.rs b/harness/service-cli/src/deployment_azure_infrastructure.rsindex 02d61eb7..b525831b 100644--- a/harness/service-cli/src/deployment_azure_infrastructure.rs+++ b/harness/service-cli/src/deployment_azure_infrastructure.rs@@ -266,17 +266,19 @@ fn assignment_resource(}/// Exact top-level workload IDs in dependency-safe deletion order. Nested children/// disappear with parents; the customer RG and AKS-generated node RG are not owned.+/// Delete the VNet before its private DNS zones: Azure removes its virtual-network+/// links on VNet deletion, whereas zone deletion refuses surviving links.pub(crate) fn inventory(p: &Plan) -> Vec<Value> {let n = names(p);let mut resources: Vec<Value> = [("cluster","Microsoft.ContainerService/managedClusters",format!("{}-aks",n.prefix),"2024-10-01","/systemData/createdAt"),("foundation","Microsoft.DBforPostgreSQL/flexibleServers",format!("{}-pg",n.prefix),"2024-08-01","/systemData/createdAt"),- ("foundation","Microsoft.Network/privateEndpoints",format!("{}-blob",n.prefix),"2024-05-01","/systemData/createdAt"),+ ("foundation","Microsoft.Network/privateEndpoints",format!("{}-blob",n.prefix),"2024-05-01","/properties/resourceGuid"),("foundation","Microsoft.Storage/storageAccounts",n.storage,"2023-05-01","/properties/creationTime"),("foundation","Microsoft.ContainerRegistry/registries",n.registry,"2023-07-01","/properties/creationDate"),- ("foundation","Microsoft.Network/privateDnsZones",format!("{}.postgres.database.azure.com",n.prefix),"2020-06-01","/systemData/createdAt"),- ("foundation","Microsoft.Network/privateDnsZones","privatelink.blob.core.windows.net".into(),"2020-06-01","/systemData/createdAt"),("foundation","Microsoft.Network/virtualNetworks",format!("{}-vnet",n.prefix),"2024-05-01","/properties/resourceGuid"),+ ("foundation","Microsoft.Network/privateDnsZones",format!("{}.postgres.database.azure.com",n.prefix),"2020-06-01","/properties/internalId"),+ ("foundation","Microsoft.Network/privateDnsZones","privatelink.blob.core.windows.net".into(),"2020-06-01","/properties/internalId"),("foundation","Microsoft.ManagedIdentity/userAssignedIdentities",format!("{}-artifacts",n.prefix),"2023-01-31","/properties/principalId"),("foundation","Microsoft.ManagedIdentity/userAssignedIdentities",format!("{}-kubelet",n.prefix),"2023-01-31","/properties/principalId"),("foundation","Microsoft.ManagedIdentity/userAssignedIdentities",format!("{}-cluster",n.prefix),"2023-01-31","/properties/principalId"),@@ -491,6 +493,10 @@ pub(crate) fn artifacts(p: &Plan) -> Result<BTreeMap<String, Vec<u8>>> {&format!("{}-aks", n.prefix),json!({"dnsPrefix":n.prefix,"kubernetesVersion":c.kubernetes_version,"enableRBAC":true,"disableLocalAccounts":true,"aadProfile":{"managed":true,"enableAzureRBAC":false,"adminGroupObjectIDs":c.admin_group_object_ids,"tenantID":tenant},"apiServerAccessProfile":{"enablePrivateCluster":true,"enablePrivateClusterPublicFQDN":false,"privateDNSZone":"System"},"oidcIssuerProfile":{"enabled":true},"securityProfile":{"workloadIdentity":{"enabled":true}},"linuxProfile":{"adminUsername":"owsadmin","ssh":{"publicKeys":[{"keyData":c.ssh_public_key}]}},"agentPoolProfiles":[{"name":"system","count":2,"vmSize":c.node_vm_size,"osDiskSizeGB":64,"osType":"Linux","osSKU":"Ubuntu","mode":"System","type":"VirtualMachineScaleSets","enableAutoScaling":false,"vnetSubnetID":aks_subnet}],"networkProfile":{"networkPlugin":"azure","networkPolicy":"azure","serviceCidr":"10.73.0.0/24","dnsServiceIP":"10.73.0.10","loadBalancerSku":"standard","outboundType":"loadBalancer"},"identityProfile":{"kubeletidentity":{"resourceId":kubelet,"clientId":format!("[reference('{kubelet}', '2023-01-31').clientId]"),"objectId":principal(&kubelet)}}}),);+ // This bounded, expiring trial has no quota/budget for upgrade surge nodes.+ // Long-lived installations must choose their own patch/upgrade policy.+ aks["properties"]["autoUpgradeProfile"] =+ json!({"upgradeChannel":"none","nodeOSUpgradeChannel":"None"});aks["identity"] = json!({"type":"UserAssigned","userAssignedIdentities":{cluster.clone():{}}});aks["sku"] = json!({"name":"Base","tier":"Free"});let ct = template(diff --git a/harness/service-cli/src/deployment_azure_lifecycle.rs b/harness/service-cli/src/deployment_azure_lifecycle.rsindex 23e8ba6c..f8ec99b3 100644--- a/harness/service-cli/src/deployment_azure_lifecycle.rs+++ b/harness/service-cli/src/deployment_azure_lifecycle.rs@@ -1178,7 +1178,7 @@ mod tests {.filter(|r| r["stage"] == stage.name()){let rid = item["id"].as_str().unwrap();- let mut v = json!({"id":rid,"tags":{"ows-deployment":self.control.plan.deployment_id,"ows-nonce":self.control.nonce,"ows-bundle":self.control.bundle_digest},"systemData":{"createdAt":"2026-10-31T00:00:00Z"},"properties":{"creationTime":"2026-10-31T00:00:00Z","creationDate":"2026-10-31T00:00:00Z","resourceGuid":"receipt-guid","principalId":"12345678-1234-4234-8234-123456789abc"}});+ let mut v = json!({"id":rid,"tags":{"ows-deployment":self.control.plan.deployment_id,"ows-nonce":self.control.nonce,"ows-bundle":self.control.bundle_digest},"systemData":{"createdAt":"2026-10-31T00:00:00Z"},"properties":{"creationTime":"2026-10-31T00:00:00Z","creationDate":"2026-10-31T00:00:00Z","resourceGuid":"receipt-guid","internalId":"opaque-zone-identity","principalId":"12345678-1234-4234-8234-123456789abc"}});v["etag"] = json!("ignored-mutable-etag");self.objects.insert(rid.into(), v);}@@ -1281,6 +1281,63 @@ mod tests {1);}+ #[tokio::test]+ async fn network_receipts_use_live_provider_fields_and_delete_vnet_before_dns() {+ let (mut c, mut s, mut e) = active().await;+ let mut protected = Vec::new();+ for item in graph::inventory(&s.plan) {+ let id = item["id"].as_str().unwrap();+ if id.contains("/privateEndpoints/") || id.contains("/privateDnsZones/") {+ let v = c.objects.get_mut(id).unwrap();+ v.as_object_mut().unwrap().remove("systemData");+ protected.push((+ id.to_owned(),+ item["incarnationPointer"].as_str().unwrap().to_owned(),+ ));+ }+ }+ observe(&mut c, &mut s, &mut e).await.unwrap();+ // Neither a mutable ETag nor ownership tags may replace the provider's identity.+ for (id, pointer) in protected {+ let original = c.objects[&id].pointer(&pointer).unwrap().clone();+ *c.objects+ .get_mut(&id)+ .unwrap()+ .pointer_mut(&pointer)+ .unwrap() = Value::Null;+ assert!(observe(&mut c, &mut s, &mut e).await.is_err());+ *c.objects+ .get_mut(&id)+ .unwrap()+ .pointer_mut(&pointer)+ .unwrap() = json!("replaced");+ assert!(observe(&mut c, &mut s, &mut e).await.is_err());+ *c.objects+ .get_mut(&id)+ .unwrap()+ .pointer_mut(&pointer)+ .unwrap() = original;+ }+ for _ in 0..15 {+ heartbeat(&mut c, &mut s, &mut e, 201).await.unwrap();+ }+ let deleted: Vec<_> = c+ .writes+ .iter()+ .filter(|(method, _)| *method == Method::DELETE)+ .map(|(_, id)| id)+ .collect();+ let network = deleted+ .iter()+ .position(|id| id.contains("/virtualNetworks/"))+ .unwrap();+ assert!(deleted+ .iter()+ .enumerate()+ .filter(|(_, id)| id.contains("/privateDnsZones/"))+ .all(|(i, _)| i > network));+ }+#[tokio::test]async fn replacement_or_missing_incarnation_refuses_deletion() {let (mut c, mut s, mut e) = active().await;diff --git a/harness/service-cli/tests/azure.rs b/harness/service-cli/tests/azure.rsindex 727339e9..3b9c7d99 100644--- a/harness/service-cli/tests/azure.rs+++ b/harness/service-cli/tests/azure.rs@@ -707,6 +707,10 @@ fn alternative_amd64_sku_exports_and_passes_selected_compute_preflight() {assert_eq!(pool["vmSize"], "Standard_D4as_v7");assert_eq!(pool["count"], 2);assert_eq!(pool["enableAutoScaling"], false);+ assert_eq!(+ arm["resources"][0]["properties"]["autoUpgradeProfile"],+ serde_json::json!({"upgradeChannel":"none","nodeOSUpgradeChannel":"None"})+ );let result = f.preflight_plan("alternative", "ready", "alternative-report");assert!(result.status.success(),