feat(frontend): reject duplicate subnet, NSG, and MRG on cluster create#6004
feat(frontend): reject duplicate subnet, NSG, and MRG on cluster create#6004JakobGray wants to merge 2 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JakobGray The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Skipping CI for Draft Pull Request. |
d8f9ac9 to
6e76b7c
Compare
There was a problem hiding this comment.
Pull request overview
This PR moves several platform “uniqueness” and NSG placement checks (previously enforced by Cluster Service) into the frontend’s admission/static validation so invalid cluster creates fail early with consistent error messages.
Changes:
- Prefetch subscription-scoped clusters and node pools during cluster CREATE admission and add best-effort checks rejecting duplicate managed RG, subnet, and NSG usage across clusters/node pools.
- Extend static validation so
networkSecurityGroupIdmust be in the same subscription and must not be in the cluster’s managed resource group. - Update unit/integration tests and test artifacts to reflect newly enforced CREATE-time validation behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test-integration/frontend/artifacts/FrontendCRUD/Cluster/experimental-features-no-afec/04-httpCreate-cluster-with-4.19/create-with-4.19.json | Updates test create payload resource IDs to avoid conflicts with new admission checks. |
| internal/validation/validate_cluster.go | Adds NSG “same subscription” and “not in managed RG” checks at the cluster-level validation layer. |
| internal/validation/validate_cluster_comprehensive_test.go | Adds/adjusts validation test coverage for new NSG subscription/RG constraints. |
| internal/validation/hcpopenshiftcluster_test.go | Updates test cluster setup to include an NSG ID consistent with the new rules. |
| internal/admission/admit_cluster.go | Introduces CREATE-only cross-cluster/nodepool uniqueness admission checks for MRG/subnet/NSG. |
| internal/admission/admit_cluster_test.go | Adds unit tests verifying the new CREATE-only admission checks. |
| frontend/pkg/frontend/cluster.go | Prefetches subscription clusters and their node pools to populate the admission context on CREATE. |
| existingSubnet := existing.CustomerProperties.Platform.SubnetID | ||
| if strings.EqualFold(subnetID, existingSubnet.String()) { |
| nodePoolSubnet := nodePool.Properties.Platform.SubnetID | ||
| if strings.EqualFold(subnetID, nodePoolSubnet.String()) { |
| existingNSG := existing.CustomerProperties.Platform.NetworkSecurityGroupID | ||
| if strings.EqualFold(nsgID, existingNSG.String()) { |
| subnetPath := fldPath.Child("subnetId") | ||
| subnetID := newObj.SubnetID.String() | ||
| var errs field.ErrorList |
| nsgPath := fldPath.Child("networkSecurityGroupId") | ||
| nsgID := newObj.NetworkSecurityGroupID.String() | ||
| var errs field.ErrorList |
Cluster Service no longer returns synchronous 400s for platform uniqueness checks after async CS create migration. Move those checks to the frontend so invalid cluster PUTs fail at admission time with the same error messages CS used in performSpecValidation. These checks are best-effort and may not catch concurrent creates. - Prefetch subscription clusters and node pools in newClusterAdmissionContext - Add admitClusterManagedResourceGroupName, admitClusterSubnetResourceID, and admitClusterNetworkSecurityGroupResourceID (CREATE only) - Add NSG same-subscription and not-in-MRG rules to static validation (parity with validateAroHcpClusterNetworkSecurityGroupResourceId)
6e76b7c to
03e5c54
Compare
| existingSubnet := existing.CustomerProperties.Platform.SubnetID | ||
| if strings.EqualFold(subnetID, existingSubnet.String()) { |
| nodePoolSubnet := nodePool.Properties.Platform.SubnetID | ||
| if strings.EqualFold(subnetID, nodePoolSubnet.String()) { |
| existingNSG := existing.CustomerProperties.Platform.NetworkSecurityGroupID | ||
| if strings.EqualFold(nsgID, existingNSG.String()) { |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| for _, existing := range admissionContext.SubscriptionClusters { | ||
| existingSubnet := existing.CustomerProperties.Platform.SubnetID | ||
| if strings.EqualFold(subnetID, existingSubnet.String()) { | ||
| errs = append(errs, field.Invalid( | ||
| subnetPath, | ||
| subnetID, | ||
| fmt.Sprintf("Subnet '%s' is already in use by another cluster", subnetID), | ||
| )) | ||
| break | ||
| } | ||
| } |
| for _, nodePool := range admissionContext.SubscriptionNodePools { | ||
| nodePoolSubnet := nodePool.Properties.Platform.SubnetID | ||
| if strings.EqualFold(subnetID, nodePoolSubnet.String()) { | ||
| errs = append(errs, field.Invalid( | ||
| subnetPath, | ||
| subnetID, | ||
| fmt.Sprintf("Subnet '%s' is already in use by another cluster", subnetID), | ||
| )) | ||
| break | ||
| } | ||
| } |
| for _, existing := range admissionContext.SubscriptionClusters { | ||
| existingNSG := existing.CustomerProperties.Platform.NetworkSecurityGroupID | ||
| if strings.EqualFold(nsgID, existingNSG.String()) { | ||
| errs = append(errs, field.Invalid( | ||
| nsgPath, | ||
| nsgID, | ||
| fmt.Sprintf("Network Security Group '%s' is already in use by another cluster", nsgID), | ||
| )) | ||
| break | ||
| } | ||
| } |
What
This change closes the following gaps in validation during cluster create between CS and ARO-HCP:
These mirror checks done in CS before a cluster create is accepted:
validateAroHcpClusterNetworkSecurityGroupResourceIdvalidateManagedResourceGroupUniquenessvalidateSubnetUniquenessvalidateNsgUniquenessThese checks are best-effort. Race conditions are possible for clusters admitted at the same time.
Why
Cluster Service no longer returns synchronous 400s for platform uniqueness checks after async CS create migration. Move those checks to the frontend so invalid cluster PUTs fail at admission time with the same error messages CS used in performSpecValidation.
Testing
Added unit tests for new functions. Modified integration tests where new errors were occurring because they are now being caught by the admission validation. Tested against existing E2E tests around subnet/NSG/MRG reuse between clusters (
test/e2e/cluster_nsg_subnet_reuse.goandtest/e2e/clusters_sharing_resgroup.go)Special notes for your reviewer
PR Checklist
If E2E tests are included:
demonstrate that the test is able to detect a defect/error and fail with
proper error message and logs which communicates nature of the problem.