When a VM fails validation in addNodesToKubernetesCluster, the revert
looked up the node's firewall rule with findByNetworkIdAndPorts. That
search has no purpose filter, so it could return the port-forwarding
rule on the same port. Revoking it as a firewall rule threw
"Unable to find <id> having purpose [Firewall, Ipv6Firewall]", and both
rules stayed until someone deleted them by hand.
| change | why |
|---|---|
| record the node's SSH rule ids before provisioning; revert only new ones | never touch a rule that was already there (e.g. one hit by a port conflict) |
| match firewall rules by public IP, port, tcp and purpose Firewall | the network+port lookup could return the PF rule or another IP's rule |
| match PF rules by public IP, source port and destination port 22 | leave the VM's other PF rules alone |
| revoke firewall then PF, each on its own, log any that fail; keep the PF if its firewall rule could not be removed | one failed revoke no longer aborts the batch, and what is left is a pair the next add-node cleans up |
| before adding, check the SSH ports the new nodes will use | rules left by an earlier failed add made the next add fail with a bare conflict |
Port check, over the rules on the IP that would clash with a new node's
SSH rules (tcp PF or LB overlapping the ports, or a firewall rule whose
CIDRs overlap 0.0.0.0/0 as detectRulesConflict sees it):
| found | action |
|---|---|
| single-port tcp PF open to all, to port 22 of a VM in this request that is in no cluster, plus a 0.0.0.0/0 firewall rule on that port | leftover of a failed add: revoke, log at INFO |
| anything else | fail before creating anything, listing the IP, ports and each rule's UUID, purpose and ports |
Signed-off-by: Brad House <bhouse@nexthop.ai>
Description
This PR fixes the revert in CKS add-node so a failed add removes exactly the SSH rules it created for that node, and makes the next add-node clean up (or clearly report) rules left behind by an earlier failure.
Fixes: #14774
Revert after a failed node
Unable to find <id> having purpose [Firewall, Ipv6Firewall]Check before adding nodes (runs before anything is created, over the SSH ports the new nodes will use)
A clashing rule is one CloudStack would reject next to the node's rules: any tcp PF/LB rule overlapping the port, or a firewall rule listing 0.0.0.0/0 with no destination CIDRs. Firewall rules for other CIDRs are left alone and don't block the add.
KubernetesClusterAddWorkeronly. The same code is on main.Related:
validateAndSetupNodeandKubernetesClusterAddWorkerTest. Whichever lands second reshapes this PR's leftover check to scan the whole SSH range instead of the old formula's window; a reference resolution is available.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
KubernetesClusterAddWorkerTest(19 tests):validateAndSetupNode: firewall conflict, PF conflict, PF apply failuremvn -pl plugins/integrations/kubernetes-service test: all tests pass.How did you try to break this feature and the system with this change?