-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from So1S/SO1S-268-backend-deployment-상태-변경-감지
SO1S-268 backend deployment 상태 변경 감지
- Loading branch information
Showing
12 changed files
with
307 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/io/so1s/backend/domain/kubernetes/utils/ApplicationHealthChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.so1s.backend.domain.kubernetes.utils; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
public class ApplicationHealthChecker { | ||
|
||
public boolean checkApplicationHealth(String url) { | ||
try { | ||
new RestTemplate().getForObject("https://" + url + "/healthz", String.class); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/io/so1s/backend/domain/kubernetes/utils/DeploymentStatusCheckScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.so1s.backend.domain.kubernetes.utils; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.so1s.backend.domain.deployment.entity.Deployment; | ||
import io.so1s.backend.domain.deployment.repository.DeploymentRepository; | ||
import io.so1s.backend.global.entity.Status; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class DeploymentStatusCheckScheduler { | ||
|
||
private final KubernetesClient client; | ||
private final DeploymentRepository deploymentRepository; | ||
private final ApplicationHealthChecker applicationHealthChecker; | ||
|
||
@Scheduled(fixedDelay = 1000L * 60) | ||
public void checkDeploymentStatus() { | ||
List<Deployment> deployments = deploymentRepository.findAll(); | ||
|
||
List<io.fabric8.kubernetes.api.model.apps.Deployment> k8sDeployments = client.apps() | ||
.deployments().inNamespace("default").withLabel("app", "inference").list().getItems(); | ||
|
||
for (Deployment deployment : deployments) { | ||
Optional<io.fabric8.kubernetes.api.model.apps.Deployment> find = k8sDeployments.stream() | ||
.parallel().filter(d -> d.getMetadata().getName().equalsIgnoreCase(deployment.getName())) | ||
.findAny(); | ||
if (find.isPresent()) { | ||
if (find.get().getStatus().getConditions().get(0).getStatus().equals("True")) { | ||
if (applicationHealthChecker.checkApplicationHealth(deployment.getEndPoint())) { | ||
setDeploymentStatus(deployment, Status.RUNNING); | ||
continue; | ||
} | ||
} | ||
setDeploymentStatus(deployment, Status.FAILED); | ||
} else { | ||
setDeploymentStatus(deployment, Status.UNKNOWN); | ||
} | ||
} | ||
} | ||
|
||
@Transactional | ||
public void setDeploymentStatus(Deployment deployment, Status status) { | ||
deployment.changeStatus(status); | ||
deploymentRepository.save(deployment); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/io/so1s/backend/global/config/ScheduledConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.so1s.backend.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@EnableScheduling | ||
@Configuration | ||
public class ScheduledConfig { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.