Skip to content
Snippets Groups Projects
Commit c60453a4 authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Using a local checkIfReady implementation

parent de88c67b
Branches
No related tags found
2 merge requests!273Release 1.8.0 update,!246Using a local checkIfReady implementation
Pipeline #94887 passed
Showing
with 199 additions and 164 deletions
...@@ -2,8 +2,12 @@ package net.geant.nmaas.externalservices.kubernetes; ...@@ -2,8 +2,12 @@ package net.geant.nmaas.externalservices.kubernetes;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -40,4 +44,62 @@ public class RemoteClusterHelper { ...@@ -40,4 +44,62 @@ public class RemoteClusterHelper {
return hexString.toString(); return hexString.toString();
} }
public static class StringMultipartFile implements MultipartFile {
private final byte[] content;
private final String name;
private final String originalFilename;
private final String contentType;
public StringMultipartFile(String name, String originalFilename, String contentType, String contentStr) {
this.name = name;
this.originalFilename = originalFilename;
this.contentType = contentType;
this.content = contentStr.getBytes(StandardCharsets.UTF_8);
}
@Override
public String getName() {
return name;
}
@Override
public String getOriginalFilename() {
return originalFilename;
}
@Override
public String getContentType() {
return contentType;
}
@Override
public boolean isEmpty() {
return content.length == 0;
}
@Override
public long getSize() {
return content.length;
}
@Override
public byte[] getBytes() {
return content;
}
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(content);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
try (FileOutputStream out = new FileOutputStream(dest)) {
out.write(content);
}
}
}
} }
package net.geant.nmaas.externalservices.kubernetes;
import net.geant.nmaas.externalservices.kubernetes.api.model.RemoteClusterView;
import net.geant.nmaas.externalservices.kubernetes.entities.KCluster;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.util.List;
public interface RemoteClusterManagementService {
RemoteClusterView getCluster(Long id, Principal principal);
KCluster getClusterEntity(Long id);
List<RemoteClusterView> getAllClusters();
List<RemoteClusterView> getClustersInDomain(Long domainId);
RemoteClusterView saveCluster(KCluster entity, MultipartFile file) throws IOException, NoSuchAlgorithmException;
RemoteClusterView updateCluster(RemoteClusterView cluster, Long id);
void removeCluster(Long id);
boolean clusterExists(Long id);
RemoteClusterView saveClusterFile(RemoteClusterView view, MultipartFile file);
RemoteClusterView mapFile(RemoteClusterView view, MultipartFile file);
}
...@@ -18,7 +18,6 @@ import org.modelmapper.ModelMapper; ...@@ -18,7 +18,6 @@ import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.Principal; import java.security.Principal;
...@@ -35,7 +34,7 @@ import static net.geant.nmaas.externalservices.kubernetes.RemoteClusterHelper.sa ...@@ -35,7 +34,7 @@ import static net.geant.nmaas.externalservices.kubernetes.RemoteClusterHelper.sa
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class RemoteClusterManager { public class RemoteClusterManager implements RemoteClusterManagementService {
private final KClusterRepository clusterRepository; private final KClusterRepository clusterRepository;
private final KubernetesClusterIngressManager kClusterIngressManager; private final KubernetesClusterIngressManager kClusterIngressManager;
...@@ -45,10 +44,11 @@ public class RemoteClusterManager { ...@@ -45,10 +44,11 @@ public class RemoteClusterManager {
private final UserService userService; private final UserService userService;
private final ModelMapper modelMapper; private final ModelMapper modelMapper;
public RemoteClusterView getClusterView(Long id, Principal principal) { @Override
public RemoteClusterView getCluster(Long id, Principal principal) {
Optional<KCluster> cluster = clusterRepository.findById(id); Optional<KCluster> cluster = clusterRepository.findById(id);
if (cluster.isPresent()) { if (cluster.isPresent()) {
if(userService.isAdmin(principal.getName()) || userService.isUserAdminInAnyDomain(cluster.get().getDomains(), principal.getName()) ) { if (userService.isAdmin(principal.getName()) || userService.isUserAdminInAnyDomain(cluster.get().getDomains(), principal.getName())) {
return toView(cluster.get()); return toView(cluster.get());
} else { } else {
throw new IllegalArgumentException("No access to cluster " + id); throw new IllegalArgumentException("No access to cluster " + id);
...@@ -58,12 +58,14 @@ public class RemoteClusterManager { ...@@ -58,12 +58,14 @@ public class RemoteClusterManager {
} }
} }
public List<RemoteClusterView> getAllClusterView() { @Override
public List<RemoteClusterView> getAllClusters() {
List<KCluster> clusters = clusterRepository.findAll(); List<KCluster> clusters = clusterRepository.findAll();
return clusters.stream().map(this::toView).collect(Collectors.toList()); return clusters.stream().map(this::toView).collect(Collectors.toList());
} }
public KCluster getCluster(Long id) { @Override
public KCluster getClusterEntity(Long id) {
Optional<KCluster> cluster = clusterRepository.findById(id); Optional<KCluster> cluster = clusterRepository.findById(id);
if (cluster.isPresent()) { if (cluster.isPresent()) {
return cluster.get(); return cluster.get();
...@@ -72,13 +74,12 @@ public class RemoteClusterManager { ...@@ -72,13 +74,12 @@ public class RemoteClusterManager {
} }
} }
//if domain GLOBAL return all // if domain GLOBAL return all
public List<RemoteClusterView> getClustersInDomain(Long domainId) { public List<RemoteClusterView> getClustersInDomain(Long domainId) {
log.warn("Looking cluster in domain {}", domainId); Optional<Domain> domainFromDb = domainService.getGlobalDomain();
List<KCluster> clusters = new ArrayList<>(); List<KCluster> clusters;
Optional<Domain> domainOtp = domainService.getGlobalDomain(); if (domainFromDb.isPresent()) {
if(domainOtp.isPresent()) { if (domainId.equals(domainFromDb.get().getId())) {
if(domainId.equals(domainOtp.get().getId())) {
clusters = clusterRepository.findAll(); clusters = clusterRepository.findAll();
} else { } else {
clusters = clusterRepository.findByDomains_Id(domainId); clusters = clusterRepository.findByDomains_Id(domainId);
...@@ -89,11 +90,7 @@ public class RemoteClusterManager { ...@@ -89,11 +90,7 @@ public class RemoteClusterManager {
return clusters.stream().map(this::toView).collect(Collectors.toList()); return clusters.stream().map(this::toView).collect(Collectors.toList());
} }
public File getFileFromCluster(Long id) { @Override
KCluster cluster = getCluster(id);
return new File(cluster.getPathConfigFile());
}
public RemoteClusterView saveCluster(KCluster entity, MultipartFile file) throws IOException, NoSuchAlgorithmException { public RemoteClusterView saveCluster(KCluster entity, MultipartFile file) throws IOException, NoSuchAlgorithmException {
checkRequest(entity); checkRequest(entity);
...@@ -119,6 +116,7 @@ public class RemoteClusterManager { ...@@ -119,6 +116,7 @@ public class RemoteClusterManager {
} }
} }
@Override
public RemoteClusterView mapFile(RemoteClusterView view, MultipartFile file) { public RemoteClusterView mapFile(RemoteClusterView view, MultipartFile file) {
checkRequestRead(view); checkRequestRead(view);
...@@ -161,6 +159,7 @@ public class RemoteClusterManager { ...@@ -161,6 +159,7 @@ public class RemoteClusterManager {
return null; return null;
} }
@Override
public RemoteClusterView saveClusterFile(RemoteClusterView view, MultipartFile file) { public RemoteClusterView saveClusterFile(RemoteClusterView view, MultipartFile file) {
checkRequest(view); checkRequest(view);
try { try {
...@@ -212,6 +211,7 @@ public class RemoteClusterManager { ...@@ -212,6 +211,7 @@ public class RemoteClusterManager {
).toList(); ).toList();
} }
@Override
public RemoteClusterView updateCluster(RemoteClusterView cluster, Long id) { public RemoteClusterView updateCluster(RemoteClusterView cluster, Long id) {
Optional<KCluster> entity = clusterRepository.findById(id); Optional<KCluster> entity = clusterRepository.findById(id);
...@@ -280,10 +280,11 @@ public class RemoteClusterManager { ...@@ -280,10 +280,11 @@ public class RemoteClusterManager {
return view; return view;
} }
@Override
public void removeCluster(Long id) { public void removeCluster(Long id) {
try { try {
if (clusterRepository.existsById(id)) { if (clusterRepository.existsById(id)) {
this.clusterRepository.deleteById(id); clusterRepository.deleteById(id);
} }
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
log.warn("Can not delete cluster {}", id); log.warn("Can not delete cluster {}", id);
...@@ -291,6 +292,7 @@ public class RemoteClusterManager { ...@@ -291,6 +292,7 @@ public class RemoteClusterManager {
} }
} }
@Override
public boolean clusterExists(Long id) { public boolean clusterExists(Long id) {
if (id == null) { if (id == null) {
return false; return false;
......
...@@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.externalservices.kubernetes.entities.KCluster; import net.geant.nmaas.externalservices.kubernetes.entities.KCluster;
import net.geant.nmaas.externalservices.kubernetes.entities.KClusterState; import net.geant.nmaas.externalservices.kubernetes.entities.KClusterState;
import net.geant.nmaas.externalservices.kubernetes.repositories.KClusterRepository; import net.geant.nmaas.externalservices.kubernetes.repositories.KClusterRepository;
import net.geant.nmaas.kubernetes.KubernetesApiService; import net.geant.nmaas.kubernetes.KubernetesApiClientService;
import net.geant.nmaas.kubernetes.KubernetesClientSetupException; import net.geant.nmaas.kubernetes.KubernetesClientSetupException;
import net.geant.nmaas.notifications.templates.MailType; import net.geant.nmaas.notifications.templates.MailType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -28,14 +28,14 @@ import static net.geant.nmaas.externalservices.kubernetes.RemoteClusterHelper.sa ...@@ -28,14 +28,14 @@ import static net.geant.nmaas.externalservices.kubernetes.RemoteClusterHelper.sa
public class RemoteClusterMonitor implements RemoteClusterMonitoringService { public class RemoteClusterMonitor implements RemoteClusterMonitoringService {
private final KClusterRepository clusterRepository; private final KClusterRepository clusterRepository;
private final KubernetesApiService kubernetesApiService; private final KubernetesApiClientService kubernetesApiClientService;
private final RemoteClusterMailer mailer; private final RemoteClusterMailer mailer;
@Override @Override
public boolean clusterAvailable(Long id) { public boolean clusterAvailable(Long id) {
final KCluster cluster = clusterRepository.getReferenceById(id); final KCluster cluster = clusterRepository.getReferenceById(id);
try { try {
kubernetesApiService.getKubernetesVersion(cluster); kubernetesApiClientService.getKubernetesVersion(cluster);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
return false; return false;
...@@ -48,7 +48,7 @@ public class RemoteClusterMonitor implements RemoteClusterMonitoringService { ...@@ -48,7 +48,7 @@ public class RemoteClusterMonitor implements RemoteClusterMonitoringService {
List<KCluster> kClusters = clusterRepository.findAll(); List<KCluster> kClusters = clusterRepository.findAll();
kClusters.forEach(cluster -> { kClusters.forEach(cluster -> {
try { try {
final String version = kubernetesApiService.getKubernetesVersion(cluster); final String version = kubernetesApiClientService.getKubernetesVersion(cluster);
log.debug("Received version information for cluster {} -> {}", cluster.getCodename(), version); log.debug("Received version information for cluster {} -> {}", cluster.getCodename(), version);
updateStateIfNeeded(cluster, KClusterState.UP); updateStateIfNeeded(cluster, KClusterState.UP);
} catch (KubernetesClientSetupException e) { } catch (KubernetesClientSetupException e) {
...@@ -81,7 +81,7 @@ public class RemoteClusterMonitor implements RemoteClusterMonitoringService { ...@@ -81,7 +81,7 @@ public class RemoteClusterMonitor implements RemoteClusterMonitoringService {
List<KCluster> clusters = clusterRepository.findAll(); List<KCluster> clusters = clusterRepository.findAll();
clusters.forEach(cluster -> { clusters.forEach(cluster -> {
if (!isFileAvailable(cluster.getPathConfigFile())) { if (!isFileAvailable(cluster.getPathConfigFile())) {
MultipartFile file = new StringMultipartFile("file", MultipartFile file = new RemoteClusterHelper.StringMultipartFile("file",
"config.yaml", "config.yaml",
"application/x-yaml", "application/x-yaml",
cluster.getClusterConfigFile()); cluster.getClusterConfigFile());
......
...@@ -3,6 +3,7 @@ package net.geant.nmaas.externalservices.kubernetes; ...@@ -3,6 +3,7 @@ package net.geant.nmaas.externalservices.kubernetes;
public interface RemoteClusterMonitoringService { public interface RemoteClusterMonitoringService {
boolean clusterAvailable(Long id); boolean clusterAvailable(Long id);
void updateAllClusterState(); void updateAllClusterState();
} }
package net.geant.nmaas.externalservices.kubernetes;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class StringMultipartFile implements MultipartFile {
private final byte[] content;
private final String name;
private final String originalFilename;
private final String contentType;
public StringMultipartFile(String name, String originalFilename, String contentType, String contentStr) {
this.name = name;
this.originalFilename = originalFilename;
this.contentType = contentType;
this.content = contentStr.getBytes(StandardCharsets.UTF_8);
}
@Override
public String getName() {
return name;
}
@Override
public String getOriginalFilename() {
return originalFilename;
}
@Override
public String getContentType() {
return contentType;
}
@Override
public boolean isEmpty() {
return content.length == 0;
}
@Override
public long getSize() {
return content.length;
}
@Override
public byte[] getBytes() {
return content;
}
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(content);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
try (FileOutputStream out = new FileOutputStream(dest)) {
out.write(content);
}
}
}
\ No newline at end of file
...@@ -3,8 +3,7 @@ package net.geant.nmaas.externalservices.kubernetes.api; ...@@ -3,8 +3,7 @@ package net.geant.nmaas.externalservices.kubernetes.api;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManagementService;
import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManager;
import net.geant.nmaas.externalservices.kubernetes.api.model.RemoteClusterView; import net.geant.nmaas.externalservices.kubernetes.api.model.RemoteClusterView;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
...@@ -24,22 +23,20 @@ import java.util.List; ...@@ -24,22 +23,20 @@ import java.util.List;
@RestController @RestController
@RequestMapping(value = "/api/management/cluster") @RequestMapping(value = "/api/management/cluster")
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class RemoteClusterManagerController { public class RemoteClusterManagerController {
private final RemoteClusterManager remoteClusterManager; private final RemoteClusterManagementService remoteClusterManager;
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_OPERATOR') || hasRole('ROLE_DOMAIN_ADMIN')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_OPERATOR') || hasRole('ROLE_DOMAIN_ADMIN')")
@GetMapping("/{id}") @GetMapping("/{id}")
public RemoteClusterView getKubernetesCluster(@PathVariable Long id, Principal principal) { public RemoteClusterView getKubernetesCluster(@PathVariable Long id, Principal principal) {
return remoteClusterManager.getCluster(id, principal);
return remoteClusterManager.getClusterView(id, principal);
} }
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_OPERATOR')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_OPERATOR')")
@GetMapping("/all") @GetMapping("/all")
public List<RemoteClusterView> getAllKubernetesCluster() { public List<RemoteClusterView> getAllKubernetesCluster() {
return remoteClusterManager.getAllClusterView(); return remoteClusterManager.getAllClusters();
} }
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_OPERATOR') || hasPermission(#domainId, 'domain', 'OWNER')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_OPERATOR') || hasPermission(#domainId, 'domain', 'OWNER')")
...@@ -54,7 +51,6 @@ public class RemoteClusterManagerController { ...@@ -54,7 +51,6 @@ public class RemoteClusterManagerController {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
RemoteClusterView cluster = objectMapper.readValue(viewString, RemoteClusterView.class); RemoteClusterView cluster = objectMapper.readValue(viewString, RemoteClusterView.class);
log.info("New remote Kubernetes cluster created");
return remoteClusterManager.saveClusterFile(cluster, file); return remoteClusterManager.saveClusterFile(cluster, file);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -79,7 +75,6 @@ public class RemoteClusterManagerController { ...@@ -79,7 +75,6 @@ public class RemoteClusterManagerController {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
RemoteClusterView cluster = objectMapper.readValue(viewString, RemoteClusterView.class); RemoteClusterView cluster = objectMapper.readValue(viewString, RemoteClusterView.class);
log.info("New remote Kubernetes cluster to be readed");
return remoteClusterManager.mapFile(cluster, file); return remoteClusterManager.mapFile(cluster, file);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
package net.geant.nmaas.kubernetes; package net.geant.nmaas.kubernetes;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -11,7 +12,7 @@ import java.util.Objects; ...@@ -11,7 +12,7 @@ import java.util.Objects;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class KubernetesApiService { public class KubernetesApiClientService {
private final KubernetesApiClientFactory kubernetesApiClientFactory; private final KubernetesApiClientFactory kubernetesApiClientFactory;
...@@ -22,6 +23,16 @@ public class KubernetesApiService { ...@@ -22,6 +23,16 @@ public class KubernetesApiService {
return version; return version;
} }
public Deployment getDeployment(KCluster kCluster, String namespace, String deploymentName) {
try (KubernetesClient client = initClient(kCluster)) {
return client.apps()
.deployments()
.inNamespace(namespace)
.withName(deploymentName)
.get();
}
}
public void scaleDeployment(KCluster kCluster, String namespace, String deploymentName, int replicas) { public void scaleDeployment(KCluster kCluster, String namespace, String deploymentName, int replicas) {
KubernetesClient client = initClient(kCluster); KubernetesClient client = initClient(kCluster);
client.apps() client.apps()
......
package net.geant.nmaas.kubernetes;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterNamespaceService;
import net.geant.nmaas.externalservices.kubernetes.entities.KCluster;
import net.geant.nmaas.orchestration.Identifier;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component
@RequiredArgsConstructor
@Slf4j
public class KubernetesApiJanitorService {
private final KubernetesClusterNamespaceService namespaceService;
private final KubernetesApiClientService kubernetesApiClientService;
public boolean checkIfReady(KCluster kCluster, Identifier deploymentId, String domain) {
final String namespace = namespaceService.namespace(domain);
final Deployment deployment = kubernetesApiClientService.getDeployment(kCluster, deploymentId.value(), namespace);
if (Objects.nonNull(deployment)) {
return Objects.equals(deployment.getSpec().getReplicas(), deployment.getStatus().getReadyReplicas());
}
log.info("Deployment {} not found in namespace {}", deploymentId.value(), namespace);
return false;
}
}
\ No newline at end of file
...@@ -4,12 +4,13 @@ import com.google.common.base.Strings; ...@@ -4,12 +4,13 @@ import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterIngressManager; import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterIngressManager;
import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManager; import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManagementService;
import net.geant.nmaas.externalservices.kubernetes.RemoteClusterMonitoringService; import net.geant.nmaas.externalservices.kubernetes.RemoteClusterMonitoringService;
import net.geant.nmaas.externalservices.kubernetes.entities.IngressControllerConfigOption; import net.geant.nmaas.externalservices.kubernetes.entities.IngressControllerConfigOption;
import net.geant.nmaas.externalservices.kubernetes.entities.KCluster; import net.geant.nmaas.externalservices.kubernetes.entities.KCluster;
import net.geant.nmaas.gitlab.GitLabManager; import net.geant.nmaas.gitlab.GitLabManager;
import net.geant.nmaas.gitlab.exceptions.GitLabInvalidConfigurationException; import net.geant.nmaas.gitlab.exceptions.GitLabInvalidConfigurationException;
import net.geant.nmaas.kubernetes.KubernetesApiJanitorService;
import net.geant.nmaas.nmservice.deployment.ContainerOrchestrator; import net.geant.nmaas.nmservice.deployment.ContainerOrchestrator;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.KClusterCheckException; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.KClusterCheckException;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.helm.HelmChartIngressVariable; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.helm.HelmChartIngressVariable;
...@@ -86,8 +87,9 @@ public class KubernetesManager implements ContainerOrchestrator { ...@@ -86,8 +87,9 @@ public class KubernetesManager implements ContainerOrchestrator {
private final KubernetesClusterIngressManager ingressManager; private final KubernetesClusterIngressManager ingressManager;
private final GitLabManager gitLabManager; private final GitLabManager gitLabManager;
private final JanitorService janitorService; private final JanitorService janitorService;
private final RemoteClusterManager remoteClusterManager; private final KubernetesApiJanitorService kubernetesApiJanitorService;
private final RemoteClusterMonitoringService remoteClusterMonitoringService; private final RemoteClusterManagementService remoteClusterManager;
private final RemoteClusterMonitoringService remoteClusterMonitor;
@Override @Override
@Loggable(LogLevel.INFO) @Loggable(LogLevel.INFO)
...@@ -108,7 +110,7 @@ public class KubernetesManager implements ContainerOrchestrator { ...@@ -108,7 +110,7 @@ public class KubernetesManager implements ContainerOrchestrator {
if (!remoteClusterManager.clusterExists(appDeployment.getRemoteClusterId())) { if (!remoteClusterManager.clusterExists(appDeployment.getRemoteClusterId())) {
throw new NmServiceRequestVerificationException(String.format("Remote cluster with id %s doesn't exist", appDeployment.getRemoteClusterId())); throw new NmServiceRequestVerificationException(String.format("Remote cluster with id %s doesn't exist", appDeployment.getRemoteClusterId()));
} else { } else {
if (!remoteClusterMonitoringService.clusterAvailable(appDeployment.getRemoteClusterId())) { if (!remoteClusterMonitor.clusterAvailable(appDeployment.getRemoteClusterId())) {
throw new NmServiceRequestVerificationException(String.format("Remote cluster with id %s is currently unavailable", appDeployment.getRemoteClusterId())); throw new NmServiceRequestVerificationException(String.format("Remote cluster with id %s is currently unavailable", appDeployment.getRemoteClusterId()));
} }
} }
...@@ -121,7 +123,7 @@ public class KubernetesManager implements ContainerOrchestrator { ...@@ -121,7 +123,7 @@ public class KubernetesManager implements ContainerOrchestrator {
appDeployment.getDescriptiveDeploymentId() appDeployment.getDescriptiveDeploymentId()
); );
if (Objects.nonNull(appDeployment.getRemoteClusterId())) { if (Objects.nonNull(appDeployment.getRemoteClusterId())) {
serviceInfo.setRemoteCluster(remoteClusterManager.getCluster(appDeployment.getRemoteClusterId())); serviceInfo.setRemoteCluster(remoteClusterManager.getClusterEntity(appDeployment.getRemoteClusterId()));
} }
serviceInfo.setKubernetesTemplate(KubernetesTemplate.copy(appDeploymentSpec.getKubernetesTemplate())); serviceInfo.setKubernetesTemplate(KubernetesTemplate.copy(appDeploymentSpec.getKubernetesTemplate()));
serviceInfo.setStorageVolumes(generateTemplateStorageVolumes(appDeploymentSpec.getStorageVolumes())); serviceInfo.setStorageVolumes(generateTemplateStorageVolumes(appDeploymentSpec.getStorageVolumes()));
...@@ -343,7 +345,8 @@ public class KubernetesManager implements ContainerOrchestrator { ...@@ -343,7 +345,8 @@ public class KubernetesManager implements ContainerOrchestrator {
KubernetesNmServiceInfo service = repositoryManager.loadService(deploymentId); KubernetesNmServiceInfo service = repositoryManager.loadService(deploymentId);
if (!janitorService.checkIfReady( if (!kubernetesApiJanitorService.checkIfReady(
service.getRemoteCluster(),
getDeploymentIdForJanitorStatusCheck( getDeploymentIdForJanitorStatusCheck(
service.getDescriptiveDeploymentId().value(), service.getDescriptiveDeploymentId().value(),
service.getKubernetesTemplate().getMainDeploymentName()), service.getKubernetesTemplate().getMainDeploymentName()),
......
...@@ -3,7 +3,7 @@ package net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.c ...@@ -3,7 +3,7 @@ package net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.c
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterNamespaceService; import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterNamespaceService;
import net.geant.nmaas.kubernetes.KubernetesApiService; import net.geant.nmaas.kubernetes.KubernetesApiClientService;
import net.geant.nmaas.kubernetes.KubernetesClientSetupException; import net.geant.nmaas.kubernetes.KubernetesClientSetupException;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.KServiceOperationsManager; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.KServiceOperationsManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.KubernetesRepositoryManager; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.KubernetesRepositoryManager;
...@@ -25,7 +25,7 @@ public class DefaultKServiceOperationsManager implements KServiceOperationsManag ...@@ -25,7 +25,7 @@ public class DefaultKServiceOperationsManager implements KServiceOperationsManag
private final KubernetesClusterNamespaceService namespaceService; private final KubernetesClusterNamespaceService namespaceService;
private final KubernetesRepositoryManager repositoryManager; private final KubernetesRepositoryManager repositoryManager;
private final KubernetesApiService kubernetesApiService; private final KubernetesApiClientService kubernetesApiClientService;
@Override @Override
@Loggable(LogLevel.INFO) @Loggable(LogLevel.INFO)
...@@ -43,7 +43,7 @@ public class DefaultKServiceOperationsManager implements KServiceOperationsManag ...@@ -43,7 +43,7 @@ public class DefaultKServiceOperationsManager implements KServiceOperationsManag
Stream.of(serviceInfo.getDescriptiveDeploymentId().getValue(), serviceInfo.getKubernetesTemplate().getMainDeploymentName()) Stream.of(serviceInfo.getDescriptiveDeploymentId().getValue(), serviceInfo.getKubernetesTemplate().getMainDeploymentName())
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.joining("-")); .collect(Collectors.joining("-"));
kubernetesApiService.scaleDeployment(serviceInfo.getRemoteCluster(), namespace, kubernetesDeploymentName, replicas); kubernetesApiClientService.scaleDeployment(serviceInfo.getRemoteCluster(), namespace, kubernetesDeploymentName, replicas);
} catch (KubernetesClientSetupException e) { } catch (KubernetesClientSetupException e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }
......
...@@ -2,7 +2,7 @@ package net.geant.nmaas.orchestration.tasks.app; ...@@ -2,7 +2,7 @@ package net.geant.nmaas.orchestration.tasks.app;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManager; import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManagementService;
import net.geant.nmaas.nmservice.deployment.NmServiceDeploymentProvider; import net.geant.nmaas.nmservice.deployment.NmServiceDeploymentProvider;
import net.geant.nmaas.orchestration.Identifier; import net.geant.nmaas.orchestration.Identifier;
import net.geant.nmaas.orchestration.entities.AppDeployment; import net.geant.nmaas.orchestration.entities.AppDeployment;
...@@ -31,7 +31,7 @@ public class AppRequestVerificationTask { ...@@ -31,7 +31,7 @@ public class AppRequestVerificationTask {
private AppDeploymentRepository repository; private AppDeploymentRepository repository;
private ApplicationRepository appRepository; private ApplicationRepository appRepository;
private RemoteClusterManager remoteClusterManager; private RemoteClusterManagementService remoteClusterManager;
@EventListener @EventListener
@Loggable(LogLevel.INFO) @Loggable(LogLevel.INFO)
......
...@@ -40,7 +40,6 @@ class ClusterServiceTest { ...@@ -40,7 +40,6 @@ class ClusterServiceTest {
private final RemoteClusterManager remoteClusterManager = new RemoteClusterManager( private final RemoteClusterManager remoteClusterManager = new RemoteClusterManager(
kClusterRepository, kClusterIngressManager, kClusterDeploymentManager, domainService, null, userService, modelMapper); kClusterRepository, kClusterIngressManager, kClusterDeploymentManager, domainService, null, userService, modelMapper);
private Domain globalDomain; private Domain globalDomain;
private Domain specificDomain; private Domain specificDomain;
private KCluster cluster1; private KCluster cluster1;
...@@ -48,7 +47,6 @@ class ClusterServiceTest { ...@@ -48,7 +47,6 @@ class ClusterServiceTest {
private KCluster cluster3; private KCluster cluster3;
private Principal mockPrincipal; private Principal mockPrincipal;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
globalDomain = new Domain("global", "global.example.com"); globalDomain = new Domain("global", "global.example.com");
...@@ -78,7 +76,7 @@ class ClusterServiceTest { ...@@ -78,7 +76,7 @@ class ClusterServiceTest {
when(kClusterRepository.findById(id)).thenReturn(Optional.of(remoteCluster)); when(kClusterRepository.findById(id)).thenReturn(Optional.of(remoteCluster));
when(userService.isAdmin(anyString())).thenReturn(true); when(userService.isAdmin(anyString())).thenReturn(true);
RemoteClusterView result = remoteClusterManager.getClusterView(id, mockPrincipal); RemoteClusterView result = remoteClusterManager.getCluster(id, mockPrincipal);
assertEquals(remoteCluster.getName(), result.getName()); assertEquals(remoteCluster.getName(), result.getName());
verify(kClusterRepository, times(1)).findById(id); verify(kClusterRepository, times(1)).findById(id);
...@@ -86,7 +84,6 @@ class ClusterServiceTest { ...@@ -86,7 +84,6 @@ class ClusterServiceTest {
verify(userService, never()).isUserAdminInAnyDomain(anyList(), anyString()); verify(userService, never()).isUserAdminInAnyDomain(anyList(), anyString());
} }
@Test @Test
void getClusterView_validId_domainAdminUser_returnsRemoteClusterView() throws AccessDeniedException { void getClusterView_validId_domainAdminUser_returnsRemoteClusterView() throws AccessDeniedException {
Long id = 1L; Long id = 1L;
...@@ -97,7 +94,7 @@ class ClusterServiceTest { ...@@ -97,7 +94,7 @@ class ClusterServiceTest {
when(userService.isAdmin(anyString())).thenReturn(false); when(userService.isAdmin(anyString())).thenReturn(false);
when(userService.isUserAdminInAnyDomain(anyList(), anyString())).thenReturn(true); when(userService.isUserAdminInAnyDomain(anyList(), anyString())).thenReturn(true);
RemoteClusterView result = remoteClusterManager.getClusterView(id, mockPrincipal); RemoteClusterView result = remoteClusterManager.getCluster(id, mockPrincipal);
assertEquals(remoteCluster.getName(), result.getName()); assertEquals(remoteCluster.getName(), result.getName());
verify(kClusterRepository, times(1)).findById(id); verify(kClusterRepository, times(1)).findById(id);
...@@ -115,20 +112,19 @@ class ClusterServiceTest { ...@@ -115,20 +112,19 @@ class ClusterServiceTest {
when(userService.isAdmin(anyString())).thenReturn(false); when(userService.isAdmin(anyString())).thenReturn(false);
when(userService.isUserAdminInAnyDomain(anyList(), anyString())).thenReturn(false); when(userService.isUserAdminInAnyDomain(anyList(), anyString())).thenReturn(false);
assertThrows(IllegalArgumentException.class, () -> remoteClusterManager.getClusterView(id, mockPrincipal)); assertThrows(IllegalArgumentException.class, () -> remoteClusterManager.getCluster(id, mockPrincipal));
verify(kClusterRepository, times(1)).findById(id); verify(kClusterRepository, times(1)).findById(id);
verify(userService, times(1)).isAdmin(mockPrincipal.getName()); verify(userService, times(1)).isAdmin(mockPrincipal.getName());
verify(userService, times(1)).isUserAdminInAnyDomain(remoteCluster.getDomains(), mockPrincipal.getName()); verify(userService, times(1)).isUserAdminInAnyDomain(remoteCluster.getDomains(), mockPrincipal.getName());
} }
@Test @Test
void getClusterView_invalidId_throwsException() { void getClusterView_invalidId_throwsException() {
Long id = 100L; Long id = 100L;
when(kClusterRepository.findById(id)).thenReturn(Optional.empty()); when(kClusterRepository.findById(id)).thenReturn(Optional.empty());
assertThrows(IllegalArgumentException.class, () -> remoteClusterManager.getClusterView(id, mockPrincipal)); assertThrows(IllegalArgumentException.class, () -> remoteClusterManager.getCluster(id, mockPrincipal));
verify(kClusterRepository, times(1)).findById(id); verify(kClusterRepository, times(1)).findById(id);
} }
...@@ -139,45 +135,12 @@ class ClusterServiceTest { ...@@ -139,45 +135,12 @@ class ClusterServiceTest {
when(kClusterRepository.findAll()).thenReturn(List.of(cluster1, cluster2)); when(kClusterRepository.findAll()).thenReturn(List.of(cluster1, cluster2));
List<RemoteClusterView> result = remoteClusterManager.getAllClusterView(); List<RemoteClusterView> result = remoteClusterManager.getAllClusters();
assertEquals(2, result.size()); assertEquals(2, result.size());
verify(kClusterRepository, times(1)).findAll(); verify(kClusterRepository, times(1)).findAll();
} }
// @Test
// void saveCluster_validInput_savesCluster() throws IOException, NoSuchAlgorithmException {
// MultipartFile multipartFile = mock(MultipartFile.class);
// ClusterManager clusterManager = ClusterManager.builder().name("Cluster").description("Description").build();
//
// when(clusterManagerRepository.save(any(ClusterManager.class))).thenReturn(clusterManager);
//
// // Load config.yaml from test/resources directory
// ClassLoader classLoader = getClass().getClassLoader();
// try (var inputStream = classLoader.getResourceAsStream("test/resources/config.yaml")) {
// when(multipartFile.getInputStream()).thenReturn(inputStream);
//
// ClusterManagerView result = clusterService.saveCluster(clusterManager, multipartFile);
// assertEquals(clusterManager.getName(), result.getName());
// verify(clusterManagerRepository, times(1)).save(clusterManager);
// }
// }
//
// @Test
// void updateCluster_validInput_updatesCluster() {
// Long id = 1L;
// ClusterManager existingCluster = ClusterManager.builder().id(id).name("OldName").build();
// ClusterManagerView updatedView = ClusterManagerView.builder().id(id).name("NewName").build();
//
// when(clusterManagerRepository.findById(id)).thenReturn(Optional.of(existingCluster));
// when(clusterManagerRepository.save(any(ClusterManager.class))).thenReturn(existingCluster);
//
// ClusterManagerView result = clusterService.updateCluster(updatedView, id);
//
// assertEquals("NewName", result.getName());
// verify(clusterManagerRepository, times(1)).save(any(ClusterManager.class));
// }
@Test @Test
void shouldReturnAllClustersWhenDomainIdIsGlobalDomainId() { void shouldReturnAllClustersWhenDomainIdIsGlobalDomainId() {
// Given // Given
...@@ -195,7 +158,6 @@ class ClusterServiceTest { ...@@ -195,7 +158,6 @@ class ClusterServiceTest {
assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster1.getId()))); assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster1.getId())));
assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster2.getId()))); assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster2.getId())));
assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster3.getId()))); assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster3.getId())));
} }
@Test @Test
...@@ -214,7 +176,6 @@ class ClusterServiceTest { ...@@ -214,7 +176,6 @@ class ClusterServiceTest {
assertEquals(2, result.size()); assertEquals(2, result.size());
assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster1.getId()))); assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster1.getId())));
assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster2.getId()))); assertTrue(result.stream().anyMatch(v -> v.getId().equals(cluster2.getId())));
} }
@Test @Test
......
...@@ -2,10 +2,11 @@ package net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes; ...@@ -2,10 +2,11 @@ package net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterIngressManager; import net.geant.nmaas.externalservices.kubernetes.KubernetesClusterIngressManager;
import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManager; import net.geant.nmaas.externalservices.kubernetes.RemoteClusterManagementService;
import net.geant.nmaas.externalservices.kubernetes.RemoteClusterMonitoringService; import net.geant.nmaas.externalservices.kubernetes.RemoteClusterMonitoringService;
import net.geant.nmaas.externalservices.kubernetes.entities.IngressControllerConfigOption; import net.geant.nmaas.externalservices.kubernetes.entities.IngressControllerConfigOption;
import net.geant.nmaas.gitlab.GitLabManager; import net.geant.nmaas.gitlab.GitLabManager;
import net.geant.nmaas.kubernetes.KubernetesApiJanitorService;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.DefaultKClusterValidator; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.DefaultKClusterValidator;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.DefaultKServiceOperationsManager; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.DefaultKServiceOperationsManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.KClusterCheckException; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.cluster.KClusterCheckException;
...@@ -13,8 +14,6 @@ import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.co ...@@ -13,8 +14,6 @@ import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.co
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.helm.HelmKServiceManager; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.helm.HelmKServiceManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.ingress.DefaultIngressControllerManager; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.ingress.DefaultIngressControllerManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.ingress.DefaultIngressResourceManager; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.components.ingress.DefaultIngressResourceManager;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.janitor.JanitorResponseException;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.janitor.JanitorService;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesChart; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesChart;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesNmServiceInfo; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesNmServiceInfo;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesTemplate; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.KubernetesTemplate;
...@@ -22,6 +21,8 @@ import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.en ...@@ -22,6 +21,8 @@ import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.en
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.ServiceAccessMethod; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.ServiceAccessMethod;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.ServiceAccessMethodType; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.ServiceAccessMethodType;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.ServiceStorageVolumeType; import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.entities.ServiceStorageVolumeType;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.janitor.JanitorResponseException;
import net.geant.nmaas.nmservice.deployment.containerorchestrators.kubernetes.janitor.JanitorService;
import net.geant.nmaas.nmservice.deployment.exceptions.ContainerOrchestratorInternalErrorException; import net.geant.nmaas.nmservice.deployment.exceptions.ContainerOrchestratorInternalErrorException;
import net.geant.nmaas.nmservice.deployment.exceptions.NmServiceRequestVerificationException; import net.geant.nmaas.nmservice.deployment.exceptions.NmServiceRequestVerificationException;
import net.geant.nmaas.orchestration.AppUiAccessDetails; import net.geant.nmaas.orchestration.AppUiAccessDetails;
...@@ -71,8 +72,9 @@ public class KubernetesManagerTest { ...@@ -71,8 +72,9 @@ public class KubernetesManagerTest {
private final KubernetesClusterIngressManager ingressManager = mock(KubernetesClusterIngressManager.class); private final KubernetesClusterIngressManager ingressManager = mock(KubernetesClusterIngressManager.class);
private final GitLabManager gitLabManager = mock(GitLabManager.class); private final GitLabManager gitLabManager = mock(GitLabManager.class);
private final JanitorService janitorService = mock(JanitorService.class); private final JanitorService janitorService = mock(JanitorService.class);
private final RemoteClusterManager remoteClusterManager = mock(RemoteClusterManager.class); private final KubernetesApiJanitorService kubernetesApiJanitorService = mock(KubernetesApiJanitorService.class);
private final RemoteClusterMonitoringService remoteClusterMonitoringService = mock(RemoteClusterMonitoringService.class); private final RemoteClusterManagementService remoteClusterManager = mock(RemoteClusterManagementService.class);
private final RemoteClusterMonitoringService remoteClusterMonitor = mock(RemoteClusterMonitoringService.class);
private final KubernetesDeploymentRemoteClusterParametersProvider remoteClusterParametersProvider = mock(KubernetesDeploymentRemoteClusterParametersProvider.class); private final KubernetesDeploymentRemoteClusterParametersProvider remoteClusterParametersProvider = mock(KubernetesDeploymentRemoteClusterParametersProvider.class);
private static final Identifier DEPLOYMENT_ID = Identifier.newInstance("deploymentId"); private static final Identifier DEPLOYMENT_ID = Identifier.newInstance("deploymentId");
...@@ -89,8 +91,9 @@ public class KubernetesManagerTest { ...@@ -89,8 +91,9 @@ public class KubernetesManagerTest {
ingressManager, ingressManager,
gitLabManager, gitLabManager,
janitorService, janitorService,
kubernetesApiJanitorService,
remoteClusterManager, remoteClusterManager,
remoteClusterMonitoringService remoteClusterMonitor
); );
@BeforeEach @BeforeEach
...@@ -404,7 +407,7 @@ public class KubernetesManagerTest { ...@@ -404,7 +407,7 @@ public class KubernetesManagerTest {
@Test @Test
void shouldVerifyThatServiceIsDeployedAndUpdateServiceIp() { void shouldVerifyThatServiceIsDeployedAndUpdateServiceIp() {
when(serviceLifecycleManager.checkServiceDeployed(any(Identifier.class))).thenReturn(true); when(serviceLifecycleManager.checkServiceDeployed(any(Identifier.class))).thenReturn(true);
when(janitorService.checkIfReady(any(), any())).thenReturn(true); when(kubernetesApiJanitorService.checkIfReady(any(), any(), any())).thenReturn(true);
when(janitorService.retrieveServiceIp(Identifier.newInstance("deploymentId"), "domain")) when(janitorService.retrieveServiceIp(Identifier.newInstance("deploymentId"), "domain"))
.thenReturn("192.168.100.1"); .thenReturn("192.168.100.1");
when(janitorService.retrieveServiceIp(Identifier.newInstance("deploymentId-component1"), "domain")) when(janitorService.retrieveServiceIp(Identifier.newInstance("deploymentId-component1"), "domain"))
...@@ -447,7 +450,7 @@ public class KubernetesManagerTest { ...@@ -447,7 +450,7 @@ public class KubernetesManagerTest {
@Test @Test
void shouldVerifyThatServiceIsDeployedWithoutServiceIp() { void shouldVerifyThatServiceIsDeployedWithoutServiceIp() {
when(serviceLifecycleManager.checkServiceDeployed(any(Identifier.class))).thenReturn(true); when(serviceLifecycleManager.checkServiceDeployed(any(Identifier.class))).thenReturn(true);
when(janitorService.checkIfReady(any(), any())).thenReturn(true); when(kubernetesApiJanitorService.checkIfReady(any(), any(), any())).thenReturn(true);
when(janitorService.retrieveServiceIp(any(), any())).thenThrow(new JanitorResponseException("")); when(janitorService.retrieveServiceIp(any(), any())).thenThrow(new JanitorResponseException(""));
doThrow(new JanitorResponseException("")).when(janitorService).checkServiceExists(any(), any()); doThrow(new JanitorResponseException("")).when(janitorService).checkServiceExists(any(), any());
assertDoesNotThrow(() -> { assertDoesNotThrow(() -> {
...@@ -459,7 +462,7 @@ public class KubernetesManagerTest { ...@@ -459,7 +462,7 @@ public class KubernetesManagerTest {
@Test @Test
void shouldReturnFalseSinceServiceNotDeployed() { void shouldReturnFalseSinceServiceNotDeployed() {
when(serviceLifecycleManager.checkServiceDeployed(any(Identifier.class))).thenReturn(false); when(serviceLifecycleManager.checkServiceDeployed(any(Identifier.class))).thenReturn(false);
when(janitorService.checkIfReady(any(), any())).thenReturn(false); when(kubernetesApiJanitorService.checkIfReady(any(), any(), any())).thenReturn(false);
assertFalse(manager.checkService(Identifier.newInstance("deploymentId"))); assertFalse(manager.checkService(Identifier.newInstance("deploymentId")));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment