Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ protected void validateVpcTier(Network network) {
if (Network.State.Allocated.equals(network.getState())) { // Allocated networks won't have IP and rules
return;
}
if (network.getNetworkACLId() == NetworkACL.DEFAULT_DENY) {
if (Objects.equals(network.getNetworkACLId(), NetworkACL.DEFAULT_DENY)) {
throw new InvalidParameterValueException(String.format("Network ID: %s can not be used for Kubernetes cluster as it uses default deny ACL", network.getUuid()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ protected void setupKubernetesClusterIsolatedNetworkRules(IpAddress publicIp, Ne
}

protected void createVpcTierAclRules(Network network) throws ManagementServerException {
if (network.getNetworkACLId() == NetworkACL.DEFAULT_ALLOW) {
if (Objects.equals(network.getNetworkACLId(), NetworkACL.DEFAULT_ALLOW)) {
return;
}
// ACL rule for API access for control node VMs
Expand Down Expand Up @@ -781,7 +781,7 @@ protected void createVpcTierAclRules(Network network) throws ManagementServerExc
}

protected void removeVpcTierAclRules(Network network) throws ManagementServerException {
if (network.getNetworkACLId() == NetworkACL.DEFAULT_ALLOW) {
if (network.getNetworkACLId() == null || Objects.equals(network.getNetworkACLId(), NetworkACL.DEFAULT_ALLOW)) {
return;
}
// ACL rule for API access for control node VMs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ protected void setupKubernetesEtcdNetworkRules(List<UserVm> etcdVms, Network net
try {
if (Objects.isNull(network.getVpcId())) {
provisionFirewallRules(publicIp, owner, etcdStartPort, etcdStartPort);
} else if (network.getNetworkACLId() != NetworkACL.DEFAULT_ALLOW) {
} else if (!Objects.equals(network.getNetworkACLId(), NetworkACL.DEFAULT_ALLOW)) {
try {
provisionVpcTierAllowPortACLRule(network, ETCD_NODE_CLIENT_REQUEST_PORT, ETCD_NODE_CLIENT_REQUEST_PORT);
if (logger.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public void testValidateVpcTierValid() {
kubernetesClusterManager.validateVpcTier(network);
}

@Test
public void testValidateVpcTierNullAclId() {
// A VPC tier with no attached ACL is a valid state (aclid is optional on createNetwork).
// Validation must not NPE by unboxing the nullable Long against the primitive long DEFAULT_DENY. See GH-13761.
Network network = Mockito.mock(Network.class);
Mockito.when(network.getState()).thenReturn(Network.State.Implemented);
Mockito.when(network.getNetworkACLId()).thenReturn(null);
kubernetesClusterManager.validateVpcTier(network);
}

@Test
public void validateIsolatedNetworkIpRulesNoRules() {
long ipId = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDetailsDao;
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
import com.cloud.kubernetes.version.dao.KubernetesSupportedVersionDao;
import com.cloud.network.Network;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -135,4 +136,14 @@ public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldNotStart
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
}

@Test
public void removeVpcTierAclRulesNullAclIdIsNoOp() throws Exception {
// Deleting a cluster from a VPC tier that still has no ACL attached must be a no-op,
// not an unboxing NullPointerException. See GH-13761.
Network network = Mockito.mock(Network.class);
Mockito.when(network.getNetworkACLId()).thenReturn(null);
kubernetesClusterResourceModifierActionWorker.removeVpcTierAclRules(network);
// Reaching here without an exception is the regression assertion.
}
}