Skip to content
Snippets Groups Projects
Commit 644da20d authored by kbeyro's avatar kbeyro
Browse files

refactor

parent a163faff
No related branches found
No related tags found
1 merge request!213Resolve "Support deployment of applications on remote clusters"
......@@ -12,6 +12,10 @@ import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import net.geant.nmaas.orchestration.entities.DomainTechDetails;
import org.apache.commons.lang3.StringUtils;
import java.util.Optional;
@Entity
@Table(name = "k_cluster_deployment")
......
......@@ -98,26 +98,19 @@ public class KubernetesManager implements ContainerOrchestrator {
} catch (IllegalArgumentException iae) {
throw new NmServiceRequestVerificationException(iae.getMessage());
}
KubernetesNmServiceInfo serviceInfo;
//todo
KubernetesNmServiceInfo serviceInfo = new KubernetesNmServiceInfo(
deploymentId,
appDeployment.getDeploymentName(),
appDeployment.getDomain(),
appDeployment.getDescriptiveDeploymentId()
);
//verify cluster
if(remoteClusterManager.clusterExist(appDeployment.getRemoteClusterId())) {
serviceInfo = new KubernetesNmServiceInfo(
deploymentId,
appDeployment.getDeploymentName(),
appDeployment.getDomain(),
appDeployment.getDescriptiveDeploymentId(),
remoteClusterManager.getCluster(appDeployment.getRemoteClusterId()));
} else {
serviceInfo = new KubernetesNmServiceInfo(
deploymentId,
appDeployment.getDeploymentName(),
appDeployment.getDomain(),
appDeployment.getDescriptiveDeploymentId()
);
serviceInfo.setRemoteCluster(remoteClusterManager.getCluster(appDeployment.getRemoteClusterId()));
}
serviceInfo.setKubernetesTemplate(KubernetesTemplate.copy(appDeploymentSpec.getKubernetesTemplate()));
serviceInfo.setStorageVolumes(generateTemplateStorageVolumes(appDeploymentSpec.getStorageVolumes()));
serviceInfo.setAccessMethods(generateTemplateAccessMethods(appDeploymentSpec.getAccessMethods()));
......
......@@ -16,7 +16,7 @@ public abstract class HelmCommand implements Command {
protected static final String HELM_VERSION_2 = "v2";
protected static final String HELM_VERSION_3 = "v3";
protected static final String KUBECONFIG = "--kubeconfig";
protected static final String OPTION_KUBECONFIG = "--kubeconfig";
protected String command;
......
......@@ -7,6 +7,7 @@ import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterIngressManag
import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterNamespaceService;
import net.geant.nmaas.externalservices.kubernetes.entities.IngressCertificateConfigOption;
import net.geant.nmaas.externalservices.kubernetes.entities.IngressResourceConfigOption;
import net.geant.nmaas.externalservices.kubernetes.entities.KCluster;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.KServiceLifecycleManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.KubernetesRepositoryManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesNmServiceInfo;
......@@ -82,20 +83,34 @@ public class HelmKServiceManager implements KServiceLifecycleManager {
private Map<String, String> createArgumentsMap(KubernetesNmServiceInfo serviceInfo) {
Map<String, String> arguments = new HashMap<>();
if (deploymentManager.getForceDedicatedWorkers()) {
arguments.put(HELM_INSTALL_OPTION_DEDICATED_WORKERS, serviceInfo.getDomain());
}
Set<ServiceStorageVolume> serviceStorageVolumes = serviceInfo.getStorageVolumes();
if (!serviceStorageVolumes.isEmpty()) {
arguments.putAll(getPersistenceVariables(serviceStorageVolumes, deploymentManager.getStorageClass(serviceInfo.getDomain()), serviceInfo.getDescriptiveDeploymentId().getValue()));
}
Set<ServiceAccessMethod> externalAccessMethods = serviceExternalAccessMethods(serviceInfo.getAccessMethods());
if (!externalAccessMethods.isEmpty()) {
arguments.putAll(getIngressVariables(ingressManager.getResourceConfigOption(), externalAccessMethods, serviceInfo.getDomain()));
if(serviceInfo.getRemoteCluster() == null) {
if (deploymentManager.getForceDedicatedWorkers()) {
arguments.put(HELM_INSTALL_OPTION_DEDICATED_WORKERS, serviceInfo.getDomain());
}
Set<ServiceAccessMethod> externalAccessMethods = serviceExternalAccessMethods(serviceInfo.getAccessMethods());
if (!externalAccessMethods.isEmpty()) {
arguments.putAll(getIngressVariables(ingressManager.getResourceConfigOption(), externalAccessMethods, serviceInfo.getDomain()));
}
} else {
if (serviceInfo.getRemoteCluster().getDeployment().getForceDedicatedWorkers()) {
arguments.put(HELM_INSTALL_OPTION_DEDICATED_WORKERS, serviceInfo.getDomain());
}
Set<ServiceAccessMethod> externalAccessMethods = serviceExternalAccessMethods(serviceInfo.getAccessMethods());
if (!externalAccessMethods.isEmpty()) {
arguments.putAll(getIngressVariables(serviceInfo.getRemoteCluster().getIngress().getResourceConfigOption(), externalAccessMethods, serviceInfo.getDomain()));
}
}
if (serviceInfo.getAdditionalParameters() != null && !serviceInfo.getAdditionalParameters().isEmpty()) {
arguments.putAll(removeRedundantParameters(serviceInfo.getAdditionalParameters()));
}
return arguments;
}
......
......@@ -27,6 +27,10 @@ public class HelmInstallCommand extends HelmCommand {
*/
public static HelmInstallCommand commandWithRepo(String helmVersion, String namespace, String releaseName, Map<String, String> values, String chartName, String chartVersion, boolean enableTls, String kubeConfigPath) {
StringBuilder sb = buildBaseInstallCommand(helmVersion, namespace, releaseName, values);
if(kubeConfigPath != null && !kubeConfigPath.isEmpty()) {
sb.append(SPACE).append(OPTION_KUBECONFIG).append(SPACE).append(kubeConfigPath);
}
if (chartName == null || chartName.isEmpty()) {
throw new IllegalArgumentException("Chart name can't be null or empty");
}
......@@ -36,9 +40,6 @@ public class HelmInstallCommand extends HelmCommand {
}
addTlsOptionIfRequired(helmVersion, enableTls, sb);
if(kubeConfigPath != null && !kubeConfigPath.isEmpty()) {
sb.append(SPACE).append(KUBECONFIG).append(SPACE).append(kubeConfigPath);
}
return new HelmInstallCommand(sb.toString());
}
......
......@@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.naming.directory.InvalidAttributesException;
import java.time.LocalDateTime;
@Component
......@@ -43,7 +44,7 @@ public class AppRequestVerificationTask {
final Application application = appRepository.findById(Long.valueOf(appDeployment.getApplicationId().getValue())).orElseThrow(() ->
new InvalidApplicationIdException("Application for deployment " + deploymentId + " does not exist in repository"));
if(!remoteClusterManager.clusterExist(appDeployment.getRemoteClusterId())) {
throw new InvalidDeploymentIdException("Wrong remote cluster Id");
throw new InvalidAttributesException("Wrong remote cluster Id");
}
serviceDeployment.verifyRequest(
deploymentId,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment