vishesh92 commented on code in PR #7515:
URL: https://github.com/apache/cloudstack/pull/7515#discussion_r1218932926
##########
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java:
##########
@@ -607,8 +622,58 @@ private void validateEndpointUrl() {
throw new InvalidParameterValueException(error);
}
}
+ private void validateUnmanagedKubernetesClusterCreateParameters(final
CreateKubernetesClusterCmd cmd) throws CloudRuntimeException {
+ final String name = cmd.getName();
+ final Long zoneId = cmd.getZoneId();
+ final Account owner =
accountService.getActiveAccountById(cmd.getEntityOwnerId());
+ final Long networkId = cmd.getNetworkId();
+ final String sshKeyPair = cmd.getSSHKeyPairName();
+ final String dockerRegistryUserName = cmd.getDockerRegistryUserName();
+ final String dockerRegistryPassword = cmd.getDockerRegistryPassword();
+ final String dockerRegistryUrl = cmd.getDockerRegistryUrl();
+ final Long nodeRootDiskSize = cmd.getNodeRootDiskSize();
+ final String externalLoadBalancerIpAddress =
cmd.getExternalLoadBalancerIpAddress();
+
+ if (name == null || name.isEmpty()) {
+ throw new InvalidParameterValueException("Invalid name for the
Kubernetes cluster name: " + name);
+ }
+
+ DataCenter zone = dataCenterDao.findById(zoneId);
+ if (zone == null) {
+ throw new InvalidParameterValueException("Unable to find zone by
ID: " + zoneId);
+ }
+
+ if (zone.getAllocationState() == Grouping.AllocationState.Disabled) {
+ throw new PermissionDeniedException(String.format("Cannot perform
this operation, zone ID: %s is currently disabled", zone.getUuid()));
+ }
- private void validateKubernetesClusterCreateParameters(final
CreateKubernetesClusterCmd cmd) throws CloudRuntimeException {
+ if (!StringUtils.isBlank(sshKeyPair)) {
+ SSHKeyPairVO sshKeyPairVO =
sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), sshKeyPair);
+ if (sshKeyPairVO == null) {
+ throw new InvalidParameterValueException(String.format("Given
SSH key pair with name: %s was not found for the account %s", sshKeyPair,
owner.getAccountName()));
+ }
+ }
+
+ if (nodeRootDiskSize != null && nodeRootDiskSize <= 0) {
+ throw new InvalidParameterValueException(String.format("Invalid
value for %s", ApiConstants.NODE_ROOT_DISK_SIZE));
+ }
+
+ validateDockerRegistryParams(dockerRegistryUserName,
dockerRegistryPassword, dockerRegistryUrl);
+
+ Network network = null;
+ if (networkId != null) {
+ network = networkService.getNetwork(networkId);
+ if (network == null) {
+ throw new InvalidParameterValueException("Unable to find
network with given ID");
+ }
+ }
+
+ if (StringUtils.isNotEmpty(externalLoadBalancerIpAddress) &&
(!NetUtils.isValidIp4(externalLoadBalancerIpAddress) &&
!NetUtils.isValidIp6(externalLoadBalancerIpAddress))) {
+ throw new InvalidParameterValueException("Invalid external load
balancer IP address");
+ }
+ }
+
+ private void validateManagedKubernetesClusterCreateParameters(final
CreateKubernetesClusterCmd cmd) throws CloudRuntimeException {
Review Comment:
I kept the methods separate for code readability. I have extracted some
shared validations into separate methods. Is this better now?
--
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]