Copilot commented on code in PR #11528:
URL: https://github.com/apache/cloudstack/pull/11528#discussion_r2329938475
##########
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java:
##########
@@ -367,18 +367,33 @@ private void logAndThrow(final Level logLevel, final
String message, final Excep
logTransitStateAndThrow(logLevel, message, null, null, ex);
}
- private boolean isKubernetesServiceNetworkOfferingConfigured(DataCenter
zone) {
+ private boolean isKubernetesServiceNetworkOfferingConfigured(DataCenter
zone, Long networkId) {
// Check network offering
String networkOfferingName = KubernetesClusterNetworkOffering.value();
- if (networkOfferingName == null || networkOfferingName.isEmpty()) {
- logger.warn(String.format("Global setting %s is empty. Admin has
not yet specified the network offering to be used for provisioning isolated
network for the cluster", KubernetesClusterNetworkOffering.key()));
+ if (StringUtils.isEmpty(networkOfferingName) && networkId == null) {
+ logger.warn("Global setting: {} is empty. Admin has not yet
specified the network offering to be used for provisioning isolated network for
the cluster nor has a pre-created network been passed",
KubernetesClusterNetworkOffering.key());
return false;
}
- NetworkOfferingVO networkOffering =
networkOfferingDao.findByUniqueName(networkOfferingName);
- if (networkOffering == null) {
- logger.warn(String.format("Unable to find the network offering %s
to be used for provisioning Kubernetes cluster", networkOfferingName));
- return false;
+ NetworkOfferingVO networkOffering = null;
+ if (networkId != null) {
+ NetworkVO network = networkDao.findById(networkId);
+ if (network == null) {
+ logger.warn("Unable to find the network with ID: {} passed for
the Kubernetes cluster", networkId);
+ return false;
+ }
+ networkOffering =
networkOfferingDao.findById(network.getNetworkOfferingId());
+ if (networkOffering == null) {
+ logger.warn("Unable to find the network offering of the
network: {} ({}) to be used for provisioning Kubernetes cluster",
network.getName(), network.getUuid());
+ return false;
+ }
+ } else if (StringUtils.isNotEmpty(networkOfferingName)) {
+ networkOffering =
networkOfferingDao.findByUniqueName(networkOfferingName);
+ if (networkOffering == null) {
+ logger.warn("Unable to find the network offering: {} to be
used for provisioning Kubernetes cluster", networkOfferingName);
+ return false;
+ }
}
+
Review Comment:
Potential null pointer exception. The networkOffering variable can be null
when both networkId is null and networkOfferingName is empty, but the code
still attempts to access networkOffering.getState() at line 397.
```suggestion
if (networkOffering == null) {
logger.warn("Network offering is null. Cannot check its state or
properties.");
return false;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]