Skip to content

Commit

Permalink
Merge pull request #8210 from stubenhuang/issue-single-ipv6-8110
Browse files Browse the repository at this point in the history
feat: 支持ipv6单栈 #8110
  • Loading branch information
bkci-bot authored Feb 24, 2023
2 parents 62b72af + 14e103d commit 1684206
Show file tree
Hide file tree
Showing 74 changed files with 589 additions and 507 deletions.
1 change: 1 addition & 0 deletions docker-images/core/ci/dockerfile/backend.bkci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ java_argv+=(
"-Dservice-suffix="
"-Dspring.profiles.active=local,dev"
"-Dspring.application.name=$MS_NAME"
"-Dspring.main.allow-circular-references=true"
)

echo "run java"
Expand Down
32 changes: 28 additions & 4 deletions helm-charts/core/ci/build/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ serviceMonitor:
init:
sql: true
iam: true
turbo: true
turbo: false
bkrepo: true
defaultImage: true
plugin:
Expand Down Expand Up @@ -117,7 +117,7 @@ mysql:
datadir=/bitnami/mysql/data
tmpdir=/opt/bitnami/mysql/tmp
max_allowed_packet=16M
bind-address=0.0.0.0
bind-address=*
pid-file=/opt/bitnami/mysql/tmp/mysqld.pid
log-error=/opt/bitnami/mysql/logs/mysqld.log
character-set-server=UTF8
Expand Down Expand Up @@ -172,6 +172,26 @@ rabbitmq:
default_permissions.configure = .*
default_permissions.read = .*
default_permissions.write = .*
# 如果想在ipv6环境中运行, 需要开启这些选项
# initContainers:
# - name: ipv6-init
# image: "docker.io/busybox:1.33.1"
# imagePullPolicy: IfNotPresent
# volumeMounts:
# - name: ipv6-cfg
# mountPath: /ipv6
# command: ['sh', '-c', 'echo "{inet6, true}." > /ipv6/erl_inetrc']
# extraVolumes:
# - name: ipv6-cfg
# emptyDir: {}
# extraVolumeMounts:
# - name: ipv6-cfg
# mountPath: /ipv6
# extraEnvVars:
# - name: RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS
# value: "-kernel inetrc '/ipv6/erl_inetrc' -proto_dist inet6_tcp"
# - name: RABBITMQ_CTL_ERL_ARGS
# value: "-proto_dist inet6_tcp"
influxdb:
enabled: true
image:
Expand All @@ -185,9 +205,13 @@ influxdb:
persistence:
size: 10Gi
influxdb:
readinessProbe:
enabled: false
livenessProbe:
enabled: false
initdbScripts:
creata_db.sh: |
influx -host 127.0.0.1 -port "$INFLUXDB_HTTP_PORT_NUMBER" -username "${INFLUXDB_ADMIN_USER}" -password "${INFLUXDB_ADMIN_USER_PASSWORD}" -execute "create database agentMetrix;"
influx -host localhost -port "$INFLUXDB_HTTP_PORT_NUMBER" -username "${INFLUXDB_ADMIN_USER}" -password "${INFLUXDB_ADMIN_USER_PASSWORD}" -execute "create database agentMetrix;"
mongodb:
# 是否部署mongodb
# 如果需要使用外部数据库,设置为false并配置external.mongodb
Expand All @@ -204,7 +228,7 @@ mongodb:
size: 10Gi
initdbScripts:
create_admin_user.sh: |
$MONGODB_BIN_DIR/mongo admin --host 127.0.0.1 --port $MONGODB_PORT_NUMBER -u root -p $MONGODB_ROOT_PASSWORD << EOF
$MONGODB_BIN_DIR/mongo admin --host localhost --port $MONGODB_PORT_NUMBER -u root -p $MONGODB_ROOT_PASSWORD << EOF
use db_turbo
db.createUser({ user: "$MONGODB_USERNAME" , pwd: "$MONGODB_PASSWORD" , roles: [{role: "dbOwner" , db:"db_turbo"}]})
use db_quartz
Expand Down
3 changes: 2 additions & 1 deletion src/backend/ci/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ version.txt
support-files/etc
build.yml
.temp
.codecc
.codecc
*.log.gz
12 changes: 12 additions & 0 deletions src/backend/ci/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ allprojects {
dependencySet("io.github.resilience4j:${Versions.Resilience4j}") {
entry("resilience4j-circuitbreaker")
}
// TODO 修复IPv6单栈环境报错问题, 等后面Okhttp3版本升级上来就可以去掉
dependencySet("com.squareup.okhttp3:${Versions.Okhttp}") {
entry("logging-interceptor")
entry("mockwebserver")
entry("okcurl")
entry("okhttp")
entry("okhttp-dnsoverhttps")
entry("okhttp-sse")
entry("okhttp-testing-support")
entry("okhttp-tls")
entry("okhttp-urlconnection")
}
dependencySet("org.eclipse.jgit:${Versions.jgit}") {
entry("org.eclipse.jgit")
entry("org.eclipse.jgit.ssh.jsch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ object Versions {
const val mockk = "1.12.2"
const val Resilience4j = "1.7.1"
const val jjwt = "0.11.5"
const val Okhttp = "4.9.0"
const val jgit = "5.13.1.202206130422-r"
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class JobServiceExt @Autowired constructor(
.post(RequestBody.create(OkhttpUtils.jsonMediaType, requestBody))
.build()
OkhttpUtils.doHttp(httpReq).use { resp ->
val responseStr = resp.body()!!.string()
val responseStr = resp.body!!.string()
logger.info("response body: $responseStr")

val response: Map<String, Any> = jacksonObjectMapper().readValue(responseStr)
Expand All @@ -92,7 +92,7 @@ class JobServiceExt @Autowired constructor(
val url = "$jobUrl/service/history/$projectId/$taskInstanceId/status"
logger.info("Get request url: $url")
OkhttpUtils.doGet(url).use { resp ->
val responseStr = resp.body()!!.string()
val responseStr = resp.body!!.string()
// val responseStr = HttpUtils.get(url)
logger.info("responseBody: $responseStr")
val response: Map<String, Any> = jacksonObjectMapper().readValue(responseStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ import com.fasterxml.jackson.module.kotlin.readValue
import com.google.common.cache.CacheBuilder
import com.tencent.bk.sdk.iam.constants.ManagerScopesEnum
import com.tencent.bk.sdk.iam.dto.response.ResponseDTO
import com.tencent.devops.auth.common.Constants.LEVEL
import com.tencent.devops.auth.common.Constants.PARENT
import com.tencent.devops.auth.common.Constants.HTTP_RESULT
import com.tencent.devops.auth.common.Constants.LEVEL
import com.tencent.devops.auth.common.Constants.NAME
import com.tencent.devops.auth.common.Constants.PARENT
import com.tencent.devops.auth.common.Constants.USERNAME
import com.tencent.devops.auth.common.Constants.USER_LABLE
import com.tencent.devops.auth.constant.AuthMessageCode
import com.tencent.devops.auth.entity.SearchUserAndDeptEntity
import com.tencent.devops.auth.entity.SearchDeptUserEntity
import com.tencent.devops.auth.entity.SearchProfileDeptEntity
import com.tencent.devops.auth.entity.SearchRetrieveDeptEntity
import com.tencent.devops.auth.entity.SearchUserAndDeptEntity
import com.tencent.devops.auth.entity.UserDeptTreeInfo
import com.tencent.devops.auth.pojo.vo.BkUserInfoVo
import com.tencent.devops.auth.pojo.vo.DeptInfoVo
Expand All @@ -54,7 +54,7 @@ import com.tencent.devops.common.api.util.OkhttpUtils
import com.tencent.devops.common.auth.api.pojo.EsbBaseReq
import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.common.service.utils.MessageCodeUtil
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request
import okhttp3.RequestBody
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -280,7 +280,7 @@ class AuthDeptServiceImpl @Autowired constructor(
private fun callUserCenter(url: String, searchEntity: EsbBaseReq): String {
val url = getAuthRequestUrl(url)
val content = objectMapper.writeValueAsString(searchEntity)
val mediaType = MediaType.parse("application/json; charset=utf-8")
val mediaType = "application/json; charset=utf-8".toMediaTypeOrNull()
val requestBody = RequestBody.create(mediaType, content)
val request = Request.Builder().url(url)
.post(requestBody)
Expand All @@ -290,26 +290,28 @@ class AuthDeptServiceImpl @Autowired constructor(
// 请求错误
logger.warn(
"call user center fail: url = $url | searchEntity = $searchEntity" +
" | response = ($it)"
" | response = ($it)"
)
throw OperationException(
MessageCodeUtil.getCodeLanMessage(
messageCode = AuthMessageCode.USER_NOT_EXIST
))
messageCode = AuthMessageCode.USER_NOT_EXIST
)
)
}
val responseStr = it.body()!!.string()
val responseStr = it.body!!.string()
logger.info("callUserCenter : response = $responseStr")
val responseDTO = JsonUtil.to(responseStr, ResponseDTO::class.java)
if (responseDTO.code != 0L || responseDTO.result == false) {
// 请求错误
logger.warn(
"call user center fail: url = $url | searchEntity = $searchEntity" +
" | response = ($it)"
" | response = ($it)"
)
throw OperationException(
MessageCodeUtil.getCodeLanMessage(
messageCode = AuthMessageCode.USER_NOT_EXIST
))
)
)
}
logger.info("user center response:${objectMapper.writeValueAsString(responseDTO.data)}")
return objectMapper.writeValueAsString(responseDTO.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ import com.tencent.devops.common.api.auth.AUTH_HEADER_IAM_TOKEN
import com.tencent.devops.common.api.exception.ClientException
import com.tencent.devops.common.api.exception.RemoteServiceException
import com.tencent.devops.common.security.jwt.JwtManager
import okhttp3.Headers
import okhttp3.MediaType
import okhttp3.Headers.Companion.toHeaders
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.OkHttpClient.Builder
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import java.util.concurrent.TimeUnit
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import org.slf4j.LoggerFactory

@Service
class AuthHttpClientService @Autowired constructor(
Expand All @@ -68,7 +68,7 @@ class AuthHttpClientService @Autowired constructor(
try {
val response = httpClient.newCall(request).execute()
logger.info(
"Request($request) with code ${response.code()}"
"Request($request) with code ${response.code}"
)
return response
} catch (e: UnknownHostException) { // DNS问题导致请求未到达目标,可重试
Expand Down Expand Up @@ -106,14 +106,14 @@ class AuthHttpClientService @Autowired constructor(
writeTimeoutInSec = writeTimeoutInSec
).use { response ->
if (!response.isSuccessful) {
val responseContent = response.body()?.string()
val responseContent = response.body?.string()
logger.warn(
"Fail to request($request) with code ${response.code()} ," +
" message ${response.message()} and response ($responseContent)"
"Fail to request($request) with code ${response.code} ," +
" message ${response.message} and response ($responseContent)"
)
throw RemoteServiceException(errorMessage, response.code(), responseContent)
throw RemoteServiceException(errorMessage, response.code, responseContent)
}
return response.body()!!.string()
return response.body!!.string()
}
}

Expand All @@ -124,7 +124,7 @@ class AuthHttpClientService @Autowired constructor(
fun buildPost(path: String, requestBody: RequestBody, gateway: String, token: String?): Request {
val url = gateway + path
logger.info("iam callback url: $url")
return Request.Builder().url(url).post(requestBody).headers(Headers.of(buildJwtAndToken(token))).build()
return Request.Builder().url(url).post(requestBody).headers(buildJwtAndToken(token).toHeaders()).build()
}

private fun buildJwtAndToken(iamToken: String?): Map<String, String> {
Expand All @@ -147,7 +147,7 @@ class AuthHttpClientService @Autowired constructor(
.build()

companion object {
val JsonMediaType = MediaType.parse("application/json; charset=utf-8")
val JsonMediaType = "application/json; charset=utf-8".toMediaTypeOrNull()
private const val EMPTY = ""
private const val CONNECT_TIMEOUT = 5L
private const val READ_TIMEOUT = 1500L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import com.tencent.devops.common.service.config.CommonConfig
import com.tencent.devops.dispatch.docker.pojo.DockerIpInfoVO
import com.tencent.devops.dispatch.docker.pojo.enums.DockerHostClusterType
import okhttp3.Headers
import okhttp3.MediaType
import okhttp3.Headers.Companion.toHeaders
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request
import okhttp3.RequestBody
import org.slf4j.LoggerFactory
Expand All @@ -65,17 +66,17 @@ class DispatchClient @Autowired constructor(
val request = Request
.Builder()
.url(url)
.headers(Headers.of(makeHeaders()))
.headers(makeHeaders())
.put(
RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
"application/json; charset=utf-8".toMediaTypeOrNull(),
""
)
)
.build()

OkhttpUtils.doHttp(request).use { response ->
val responseContent = response.body()!!.string()
val responseContent = response.body!!.string()
if (!response.isSuccessful) {
logger.error("Update containerId $path fail. $responseContent")
throw TaskExecuteException(
Expand Down Expand Up @@ -124,18 +125,18 @@ class DispatchClient @Autowired constructor(
val request = Request
.Builder()
.url(url)
.headers(Headers.of(makeHeaders()))
.headers(makeHeaders())
.post(
RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
"application/json; charset=utf-8".toMediaTypeOrNull(),
JsonUtil.toJson(dockerIpInfoVO)
)
)
.build()

logger.info("Start refresh buildLess status $url")
OkhttpUtils.doHttp(request).use { response ->
val responseContent = response.body()!!.string()
val responseContent = response.body!!.string()
if (!response.isSuccessful) {
logger.error("Refresh buildLess status $url fail. $responseContent")
throw TaskExecuteException(
Expand Down Expand Up @@ -171,19 +172,19 @@ class DispatchClient @Autowired constructor(
}
}

private fun makeHeaders(): Map<String, String?> {
private fun makeHeaders(): Headers {
val gatewayHeaderTag = if (buildLessConfig.gatewayHeaderTag == null) {
bkTag.getLocalTag()
} else {
buildLessConfig.gatewayHeaderTag
}
} ?: ""
val headers = mutableMapOf(AUTH_HEADER_GATEWAY_TAG to gatewayHeaderTag)
// 新增devopsToken给网关校验
val devopsToken = EnvironmentUtil.gatewayDevopsToken()
if (devopsToken != null) {
headers["X-DEVOPS-TOKEN"] = devopsToken
}
return headers
return headers.toHeaders()
}

companion object {
Expand Down
Loading

0 comments on commit 1684206

Please sign in to comment.