Unverified Commit 7a380d5f authored by stuben's avatar stuben Committed by GitHub
Browse files

Merge pull request #5 from tangruotian/issue-kubernetes-4935-ruotian

feat: 提供kubernetes部署方案 issue Tencent#4935 
parents 52c64fcb d5584b75
Showing with 53 additions and 10 deletions
+53 -10
......@@ -27,7 +27,9 @@
package com.tencent.devops.dispatch.kubernetes.config
import com.tencent.devops.dispatch.kubernetes.kubernetes.model.pod.Toleration
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
@Component
......@@ -66,3 +68,9 @@ class DispatchBuildConfig {
@Value("\${dispatch.build.volume.hostPath.hostdir:#{null}}")
val volumeHostPathHostDir: String? = null
}
@Component
@ConfigurationProperties(prefix = "dispatch.build")
data class DispatchBuildConfiguration(
var tolerations: List<Toleration>? = null
)
......@@ -29,6 +29,7 @@ package com.tencent.devops.dispatch.kubernetes.kubernetes.client
import com.google.gson.Gson
import com.tencent.devops.dispatch.kubernetes.config.DispatchBuildConfig
import com.tencent.devops.dispatch.kubernetes.config.DispatchBuildConfiguration
import com.tencent.devops.dispatch.kubernetes.config.KubernetesClientConfig
import com.tencent.devops.dispatch.kubernetes.kubernetes.model.deployment.Deployment
import com.tencent.devops.dispatch.kubernetes.kubernetes.model.deployment.DeploymentData
......@@ -53,7 +54,8 @@ import org.springframework.stereotype.Component
class DeploymentClient @Autowired constructor(
private val k8sConfig: KubernetesClientConfig,
private val dispatchBuildConfig: DispatchBuildConfig,
private val kubernetesDataUtils: KubernetesDataUtils
private val kubernetesDataUtils: KubernetesDataUtils,
private val dispatchBuildConfiguration: DispatchBuildConfiguration
) {
companion object {
......@@ -91,7 +93,8 @@ class DeploymentClient @Autowired constructor(
volumeMounts = kubernetesDataUtils.getPodVolumeMount()
),
volumes = kubernetesDataUtils.getPodVolume(),
nodeSelector = null
nodeSelector = null,
tolerations = dispatchBuildConfiguration.tolerations
)
)
)
......@@ -140,7 +143,8 @@ class DeploymentClient @Autowired constructor(
volumeMounts = kubernetesDataUtils.getPodVolumeMount()
),
volumes = kubernetesDataUtils.getPodVolume(),
nodeSelector = null
nodeSelector = null,
tolerations = dispatchBuildConfiguration.tolerations
)
)
)
......
......@@ -2,6 +2,7 @@ package com.tencent.devops.dispatch.kubernetes.kubernetes.client
import com.tencent.devops.dispatch.kubernetes.common.NFS_VOLUME_NAME_PREFIX
import com.tencent.devops.dispatch.kubernetes.config.DispatchBuildConfig
import com.tencent.devops.dispatch.kubernetes.config.DispatchBuildConfiguration
import com.tencent.devops.dispatch.kubernetes.config.KubernetesClientConfig
import com.tencent.devops.dispatch.kubernetes.kubernetes.model.job.Job
import com.tencent.devops.dispatch.kubernetes.kubernetes.model.job.JobData
......@@ -23,7 +24,8 @@ import org.springframework.stereotype.Component
class JobClient @Autowired constructor(
private val k8sConfig: KubernetesClientConfig,
private val dispatchBuildConfig: DispatchBuildConfig,
private val kubernetesDataUtils: KubernetesDataUtils
private val kubernetesDataUtils: KubernetesDataUtils,
private val dispatchBuildConfiguration: DispatchBuildConfiguration
) {
companion object {
......@@ -93,7 +95,8 @@ class JobClient @Autowired constructor(
} else {
null
},
restartPolicy = "Never"
restartPolicy = "Never",
tolerations = dispatchBuildConfiguration.tolerations
)
)
)
......
......@@ -39,6 +39,7 @@ import io.kubernetes.client.openapi.models.V1ObjectMeta
import io.kubernetes.client.openapi.models.V1PodSpec
import io.kubernetes.client.openapi.models.V1PodTemplateSpec
import io.kubernetes.client.openapi.models.V1ResourceRequirements
import io.kubernetes.client.openapi.models.V1Toleration
import io.kubernetes.client.openapi.models.V1Volume
import io.kubernetes.client.openapi.models.V1VolumeMount
......@@ -69,6 +70,15 @@ object Pod {
if (restartPolicy != null) {
spec.restartPolicy(restartPolicy)
}
if (!tolerations.isNullOrEmpty()) {
spec.tolerations(tolerations.map {
V1Toleration()
.key(it.key)
.operator(it.operator)
.value(it.value)
.effect(it.effecf)
})
}
pods.spec(spec)
return pods
}
......
......@@ -34,7 +34,8 @@ data class PodData(
val container: ContainerData?,
val volumes: List<Volume>?,
val nodeSelector: NodeSelector?,
val restartPolicy: String? = null
val restartPolicy: String? = null,
val tolerations: List<Toleration>? = null
)
data class ContainerData(
......@@ -54,6 +55,15 @@ data class VolumeMount(
val name: String
)
data class Toleration(
var key: String,
var operator: String,
var value: String,
var effecf: String
){
constructor():this("","","","")
}
interface Volume {
val name: String
}
......
......@@ -32,13 +32,14 @@ package com.tencent.devops.store.pojo.image.enums
enum class ImageAgentTypeEnum(val type: Int) {
DOCKER(0), // Docker on Devnet 物理机
IDC(1), // Docker on IDC CVM
PUBLIC_DEVCLOUD(2); // Docker on DevCloud
PUBLIC_DEVCLOUD(2), // Docker on DevCloud
KUBERNETES(3); // Kubernetes
companion object {
fun getImageAgentType(name: String): ImageAgentTypeEnum? {
values().forEach { enumObj ->
if (enumObj.name.toLowerCase() == name.toLowerCase()) {
if (enumObj.name.equals(name, ignoreCase = true)) {
return enumObj
}
}
......@@ -50,6 +51,7 @@ enum class ImageAgentTypeEnum(val type: Int) {
0 -> DOCKER.name
1 -> IDC.name
2 -> PUBLIC_DEVCLOUD.name
3 -> KUBERNETES.name
else -> DOCKER.name
}
}
......@@ -58,7 +60,8 @@ enum class ImageAgentTypeEnum(val type: Int) {
return mutableListOf(
DOCKER,
IDC,
PUBLIC_DEVCLOUD
PUBLIC_DEVCLOUD,
KUBERNETES
)
}
}
......
......@@ -104,7 +104,7 @@
</form-field>
</template>
<form-field :label="$t('editPage.imageTicket')" v-if="(buildResourceType === 'DOCKER') && buildImageType === 'THIRD'">
<form-field :label="$t('editPage.imageTicket')" v-if="(buildResourceType === 'DOCKER' || buildResourceType === 'KUBERNETES') && buildImageType === 'THIRD'">
<select-input v-bind="imageCredentialOption" :disabled="!editable" name="credentialId" :value="buildImageCreId" :handle-change="changeBuildResource"></select-input>
</form-field>
......
......@@ -48,6 +48,11 @@ dispatch:
path: dispatch_kubernetes_init.sh
hostPath:
hostdir: /data/volume/bkci/dispatch-kubernetes
tolerations:
- key: "bk-codecc"
operator: "Equal"
value: "use"
effecf: "NoSchedule"
pipeline:
build:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment