diff --git a/src/main/java/kr/co/mcmp/softwarecatalog/kubernetes/service/HelmChartService.java b/src/main/java/kr/co/mcmp/softwarecatalog/kubernetes/service/HelmChartService.java index 7ac094f..3456242 100644 --- a/src/main/java/kr/co/mcmp/softwarecatalog/kubernetes/service/HelmChartService.java +++ b/src/main/java/kr/co/mcmp/softwarecatalog/kubernetes/service/HelmChartService.java @@ -19,6 +19,7 @@ import kr.co.mcmp.softwarecatalog.SoftwareCatalog; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; + @Service @Slf4j @RequiredArgsConstructor @@ -29,26 +30,32 @@ public Release deployHelmChart(KubernetesClient client, String namespace, Softwa String clusterName) { Path tempConfigFile = null; K8sClusterDto dto = api.getK8sClusterByName(namespace, clusterName); - String cspType = dto.getConnectionConfig().getProviderName().toUpperCase(); - log.info("CSP Type: {}", cspType); - try { addHelmRepository(catalog); String kubeconfig = dto.getCspViewK8sClusterDetail().getAccessInfo().getKubeconfig(); - - // GCP의 경우 gke-gcloud-auth-plugin 관련 설정 제거 - if ("GCP".equalsIgnoreCase(cspType)) { - kubeconfig = kubeconfig.replaceAll("command:\\s*gke-gcloud-auth-plugin", "") - .replaceAll("apiVersion:\\s*client.authentication.k8s.io/.*\\n", "") - .replaceAll("installHint:.*\\n", "") - .replaceAll("provideClusterInfo:.*\\n", ""); - } tempConfigFile = createTempKubeconfigFile(kubeconfig); - InstallCommand installCommand = createInstallCommand(catalog, namespace, tempConfigFile); - applyCspSpecificSettings(installCommand, cspType); + InstallCommand installCommand = Helm.install( + catalog.getHelmChart().getRepositoryName() + "/" + catalog.getHelmChart().getChartName()) + .withKubeConfig(tempConfigFile) + .withName(catalog.getHelmChart().getChartName()) + .withNamespace(namespace) + .withVersion(catalog.getHelmChart().getChartVersion()) + .set("replicaCount", catalog.getMinReplicas()) + .set("image.repository", catalog.getHelmChart().getImageRepository()) + .set("image.tag", "latest") + .set("image.pullPolicy", "Always") + .set("service.port", catalog.getDefaultPort()) + .set("resources.requests.cpu", catalog.getMinCpu().toString()) + .set("resources.requests.memory", catalog.getMinMemory() + "Mi") + .set("resources.limits.cpu", catalog.getRecommendedCpu().toString()) + .set("resources.limits.memory", catalog.getRecommendedMemory() + "Mi") + .set("persistence.enabled", false) + .set("securityContext.enabled", false) + .set("serviceAccount.create", true) + .withTimeout(300) + .waitReady(); - // HPA 설정 if (Boolean.TRUE.equals(catalog.getHpaEnabled())) { installCommand .set("autoscaling.enabled", true) @@ -59,60 +66,19 @@ public Release deployHelmChart(KubernetesClient client, String namespace, Softwa } Release result = installCommand.call(); - log.info("Helm Chart '{}' 배포 완료 - namespace: {}, CSP: {}", + log.info("Helm Chart '{}' 배포 완료 - namespace: {}", catalog.getHelmChart().getChartName(), - namespace, - cspType); + namespace); return result; } catch (Exception e) { - log.error("Helm Chart 배포 중 오류 발생 - CSP: {}", cspType, e); + log.error("Helm Chart 배포 중 오류 발생", e); throw new RuntimeException("Helm Chart 배포 실패", e); } finally { deleteTempFile(tempConfigFile); } } - - private InstallCommand createInstallCommand(SoftwareCatalog catalog, String namespace, Path configFile) { - return Helm.install(catalog.getHelmChart().getRepositoryName() + "/" + catalog.getHelmChart().getChartName()) - .withKubeConfig(configFile) - .withName(catalog.getHelmChart().getChartName()) - .withNamespace(namespace) - .withVersion(catalog.getHelmChart().getChartVersion()) - .set("replicaCount", catalog.getMinReplicas()) - .set("image.repository", catalog.getHelmChart().getImageRepository()) - .set("image.tag", "latest") - .set("image.pullPolicy", "Always") - .set("service.port", catalog.getDefaultPort()) - .set("resources.requests.cpu", catalog.getMinCpu().toString()) - .set("resources.requests.memory", catalog.getMinMemory() + "Mi") - .set("resources.limits.cpu", catalog.getRecommendedCpu().toString()) - .set("resources.limits.memory", catalog.getRecommendedMemory() + "Mi") - .set("persistence.enabled", false) - .set("securityContext.enabled", false) - .set("serviceAccount.create", true) - .withTimeout(300) - .waitReady(); - } - - private void applyCspSpecificSettings(InstallCommand command, String cspType) { - log.info("Applying CSP specific settings for: {}", cspType); - switch (cspType) { - case "GCP": - command.set("gcp.auth.enabled", false) - .set("serviceAccount.annotations.iam\\.gke\\.io/gcp-service-account", "false") - .set("rbac.create", true); - break; - case "AZURE": - command.set("azure.auth.enabled", false) - .set("serviceAccount.annotations.azure\\.workload\\.identity/use", "false"); - break; - default: - log.warn("알 수 없는 CSP 타입: {}", cspType); - } - } - private void addHelmRepository(SoftwareCatalog catalog) throws Exception { Helm.repo().add() .withName(catalog.getHelmChart().getRepositoryName()) @@ -141,16 +107,7 @@ public void uninstallHelmChart(String namespace, SoftwareCatalog catalog, String Path tempConfigFile = null; try { K8sClusterDto dto = api.getK8sClusterByName(namespace, clusterName); - String cspType = dto.getConnectionConfig().getProviderName().toUpperCase(); String kubeconfig = dto.getCspViewK8sClusterDetail().getAccessInfo().getKubeconfig(); - - // GCP의 경우 gke-gcloud-auth-plugin 관련 설정 제거 - if ("GCP".equalsIgnoreCase(cspType)) { - kubeconfig = kubeconfig.replaceAll("command:\\s*gke-gcloud-auth-plugin", "") - .replaceAll("apiVersion:\\s*client.authentication.k8s.io/.*\\n", "") - .replaceAll("installHint:.*\\n", "") - .replaceAll("provideClusterInfo:.*\\n", ""); - } tempConfigFile = createTempKubeconfigFile(kubeconfig); String result = Helm.uninstall(catalog.getHelmChart().getChartName()) @@ -158,10 +115,9 @@ public void uninstallHelmChart(String namespace, SoftwareCatalog catalog, String .withNamespace(namespace) .call(); - log.info("Helm Release '{}' 삭제 완료 - namespace: {}, CSP: {}", + log.info("Helm Release '{}' 삭제 완료 - namespace: {}", catalog.getHelmChart().getChartName(), - namespace, - cspType); + namespace); } catch (Exception e) { log.error("Helm Release 삭제 실패", e);