All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.digital.integration.server.common.cluster.helm.GcpGkeHelmHelper.kt Maven / Gradle / Ivy

There is a newer version: 23.3.0-1025.941
Show newest version
package ai.digital.integration.server.common.cluster.helm

import ai.digital.integration.server.common.cluster.setup.GcpGkeHelper
import ai.digital.integration.server.common.constant.ProductName
import ai.digital.integration.server.common.domain.providers.GcpGkeProvider
import ai.digital.integration.server.common.util.YamlFileUtil
import org.gradle.api.Project
import java.io.File

open class GcpGkeHelmHelper(project: Project, productName: ProductName) : HelmHelper(project, productName) {

    private val gcpGkeHelper: GcpGkeHelper = GcpGkeHelper(project, productName, getProfile())

    fun launchCluster() {
        gcpGkeHelper.launchCluster()
    }

    fun setupHelmValues() {
        copyValuesYamlFile()
        updateHelmValuesYaml()
        updateHelmDependency()
    }

    fun helmInstallCluster() {
        installCluster()

        waitForDeployment(getProfile().ingressType.get(), getProfile().deploymentTimeoutSeconds.get(), skipOperator = true)
        waitForMasterPods(getProfile().deploymentTimeoutSeconds.get())
        waitForWorkerPods(getProfile().deploymentTimeoutSeconds.get())
        val ip = getKubectlHelper().getServiceExternalIp("service/${getCrName()}-nginx-ingress-controller")
        gcpGkeHelper.applyDnsOpenApi(ip, getFqdn(), getHost())
        createClusterMetadata()
        waitForBoot(getContextRoot(), getFqdn())
    }

    fun shutdownCluster() {
        val gcpGkeProvider: GcpGkeProvider = getProvider()
        val projectName = gcpGkeProvider.projectName.get()
        val name = gcpGkeProvider.name.get()
        val regionZone = gcpGkeProvider.regionZone.get()
        val accountName = gcpGkeProvider.accountName.get()

        val existsCluster = gcpGkeHelper.existsCluster(accountName, projectName, name, regionZone)
        if (existsCluster) {
            helmCleanUpCluster()
            getKubectlHelper().deleteAllPVCs()
        }
        gcpGkeHelper.destroyClusterOnShutdown(existsCluster, accountName, projectName, name, regionZone, getFqdn())
    }

    override fun getProvider(): GcpGkeProvider {
        return getProfile().gcpGke
    }

    override fun updateCustomHelmValues(valuesFile: File) {
        val pairs: MutableMap = mutableMapOf(
                "ingress.hosts" to arrayOf(getFqdn())
        )
        YamlFileUtil.overlayFile(valuesFile, pairs, minimizeQuotes = false)
    }

    override fun getFqdn(): String {
        return gcpGkeHelper.getFqdn()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy