Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-bk-bcs/master'
Browse files Browse the repository at this point in the history
* github-bk-bcs/master:
  fix:修复部分空间样式和交互问题 (#2718)
  fix: 默认helm repo 仓库修正 (#2717)
  前端体验问题修复 (#2714)
  feat: add frontend bkcc host variable (#2716)
  feat: bscp增加模版变量缓存机制 (#2715)
  fix:修复部分空间样式和交互问题 (#2713)
  • Loading branch information
wenxinlee2015 committed Oct 31, 2023
2 parents afafb1c + cafa5b6 commit 2cd3607
Show file tree
Hide file tree
Showing 87 changed files with 1,214 additions and 535 deletions.
6 changes: 0 additions & 6 deletions bcs-ops/install_master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,12 @@ safe_source "${ROOT_DIR}/functions/k8s.sh"
"${ROOT_DIR}"/system/config_envfile.sh -c init
"${ROOT_DIR}"/system/config_system.sh -c dns sysctl
"${ROOT_DIR}"/tools/install_tools.sh jq yq
"${ROOT_DIR}"/system/install_yq
"${ROOT_DIR}"/k8s/install_cri.sh
"${ROOT_DIR}"/k8s/install_k8s_tools
"${ROOT_DIR}"/k8s/render_kubeadm

safe_source "${ROOT_DIR}/env/bcs.env"

# pull image
if [[ -z ${BCS_OFFLINE:-} ]]; then
kubeadm --config="${ROOT_DIR}/kubeadm-config" config images pull \
|| utils::log "FATAL" "fail to pull k8s image"
fi

# wait to check kubelet start
sleep 30
Expand Down
4 changes: 0 additions & 4 deletions bcs-ops/install_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ case "${K8S_CSI,,}" in
;;
esac

if [[ -z ${BCS_OFFLINE:-} ]]; then
kubeadm --config="${ROOT_DIR}/kubeadm-config" config images pull \
|| utils::log "FATAL" "fail to pull k8s image"
fi

# wait kubelet to start
sleep 30
Expand Down
2 changes: 1 addition & 1 deletion bcs-ops/k8s/install_helm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for file in "${source_files[@]}"; do
safe_source "$file"
done

if ! helm version --short /dev/null | grep -qoE "^v${HELM_VER}"; then
if ! helm version --short 2>/dev/null | grep -qoE "^v${HELM_VER}"; then
helm_image=${BK_PUBLIC_REPO:-"docker.io"}/alpine/helm:3.7.2
utils::log "DEBUG" "helm image url: ${helm_image}"

Expand Down
8 changes: 5 additions & 3 deletions bcs-ops/k8s/install_k8s
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ for pod in ${pods[@]};do
fi
;;
"containerd")
if ! crictl ps |grep ${pod}|grep -i running;then
if ! crictl --runtime-endpoint=unix:///run/containerd/containerd.sock ps \
| grep "${pod}" \
| grep -i running; then
utils::log "ERROR" "${pod} fail to run "
fi
;;
Expand All @@ -155,7 +157,7 @@ if [[ -z ${MASTER_JOIN_CMD:-} ]]; then

kubectl get cm -n kube-system kube-proxy -o yaml|yq '.data.["kubeconfig.conf"]' > ${ROOT_DIR}/kubeconfig.conf
kubectl get cm -n kube-system kube-proxy -o yaml|yq '.data.["config.conf"]'|yq '.ipvs.udpTimeout="10s"' > ${ROOT_DIR}/config.conf
kubectl delete cm kube-proxy -n kube-system
kubectl delete cm kube-proxy -n kube-system
kubectl create cm kube-proxy -n kube-system --from-file config.conf --from-file kubeconfig.conf

if ! kubectl get ds -n kube-system kube-proxy -o yaml|grep madvdontneed;then
Expand All @@ -176,4 +178,4 @@ fi

#coredns configuration

utils::log "OK" "K8S configuration done!"
utils::log "OK" "K8S configuration done!"
40 changes: 36 additions & 4 deletions bcs-ops/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ip -6 route add fd00::/8 via <next hop> dev <interface> src <lan_ipv6>
> 注意:`fe80::/10` link-local 地址不能用于 k8s 的 node-ip。
## 安装示例

目前仅支持 k8s `1.20.15` (默认), `1.23.17``1.24.15` 版本。
### 集群创建与节点添加

1. 在第一台主机(后称中控机)上启动集群控制平面:`./bcs-ops --instal master`,集群启动成功后会显示加入集群的指令
Expand Down Expand Up @@ -105,6 +105,15 @@ ip -6 route add fd00::/8 via <next hop> dev <interface> src <lan_ipv6>
## 环境变量

通过配置环境变量来设置集群相关的参数。在中控机创建集群前,通过 `set -a` 设置环境变量。 你可以执行 `system/config_envfile.sh -init` 查看默认的环境变量。
注意,当你要使用多个特性时,相关的环境变量都得申明

### 示例:使用 containerd 作为容器运行时
```bash
set -a
K8S_VER="1.24.15"
CRI_TYPE="containerd"
set +a
```

### 示例:创建 ipv6 双栈集群

Expand All @@ -118,17 +127,37 @@ set +a
./bcs-ops -i master
```

### 示例: 修改镜像 registry,并信任
相关环境变量。镜像仓库默认为蓝鲸官方镜像仓库`hub.bktencent.com`,如果采用自己的镜像仓库,并且没有证书信任,需要添加下面两项环境变量
```bash
# 默认镜像地址
set -a
BK_PUBLIC_REPO=hub.bktencent.com
# 信任不安全的registry
INSECURE_REGISTRY=""
set +a
```

### 示例:离线安装

离线安装资源清单见 `env/offline-manifest.yaml`目前仅支持 k8s `1.20.15`, `1.23.17``1.24.15` 版本。
离线安装资源清单见 `env/offline-manifest.yaml`

你需要把对应的离线包解压到 bcs-ops 的工作根目录下 `tar xfvz bcs-ops-offline-${version}.tgz`,并且安装对应的版本 `${VERSION}`

```bash
set -a
BCS_OFFLINE="1"
K8S_VER="${VERSION}"
./bcs-ops -i master
set +a
```

### 示例:开启 apiserver 高可用
APISERVER_HA_MODE 支持 [bcs-apiserver-proxy](https://github.com/TencentBlueKing/bk-bcs/blob/master/docs/features/bcs-apiserver-proxy/bcs-apiserver-proxy.md)(默认) 和 kube-vip。
```bash
set -a
VIP=192.168.1.1 # 按照实际的需求填写,避免冲突
ENABLE_APISERVER_HA=true
APISERVER_HA_MODE=bcs-apiserver-proxy
set +a
```

Expand All @@ -138,11 +167,14 @@ bcs-ops 脚本工具集也支持安装 k8s 相关插件。多数的插件需要

### csi

安装的 k8s 组件由 `K8S_CSI` 环境变量决定,目前默认且只支持 `localpv`
安装的 k8s 组件由 `K8S_CSI` 环境变量决定,默认为空,只支持 `localpv`

#### localpv

相关配置项,中控机启动前需要运行
```bash
# 申明 CSI 组件 为 `localpv`
K8S_CSI=localpv
# localpv 挂载点,默认为${BK_HOME}/localpv
LOCALPV_DIR=${LOCALPV_DIR:-${BK_HOME}/localpv}
# 创建的 localpv 数量,默认为20个
Expand Down
2 changes: 1 addition & 1 deletion bcs-ops/system/config_envfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ init_env() {
BK_PUBLIC_REPO=${BK_PUBLIC_REPO:-"hub.bktencent.com"}

# helm
BKREPO_URL=${BKREPO_URL:-"https://hub.bktencent.com/chartrepo"}
BKREPO_URL=${BKREPO_URL:-"https://hub.bktencent.com/chartrepo/blueking"}

# apiserver HA
ENABLE_APISERVER_HA=${ENABLE_APISERVER_HA:-"false"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package service

import (
"bytes"
"context"
"sort"
"time"
Expand All @@ -28,7 +27,6 @@ import (
pbcontent "bscp.io/pkg/protocol/core/content"
pbtv "bscp.io/pkg/protocol/core/template-variable"
pbds "bscp.io/pkg/protocol/data-service"
"bscp.io/pkg/tools"
"bscp.io/pkg/types"
)

Expand All @@ -44,25 +42,15 @@ func (s *Service) ExtractAppTmplVariables(ctx context.Context, req *pbds.Extract
return nil, err
}

contents, err := s.downloadTmplContent(kt, tmplRevisions)
var allVars []string
_, _, allVars, err = s.getVariables(kt, tmplRevisions, cis)
if err != nil {
logs.Errorf("download template content failed, err: %v, rid: %s", err, kt.Rid)
logs.Errorf("get variables failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}
ciContents, err := s.downloadCIContent(kt, cis)
if err != nil {
logs.Errorf("download config item content failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}
contents = append(contents, ciContents...)

// merge all template content
allContent := bytes.Join(contents, []byte(" "))
// extract all template variables
variables := s.tmplProc.ExtractVariables(allContent)

return &pbds.ExtractAppTmplVariablesResp{
Details: variables,
Details: allVars,
}, nil
}

Expand Down Expand Up @@ -205,52 +193,35 @@ func getPbConfigItemsFromReleased(releasedCIs []*table.ReleasedConfigItem) []*pb
// GetAppTmplVariableRefs get app template variable references.
func (s *Service) getVariableReferences(kt *kit.Kit, tmplRevisions []*table.TemplateRevision, cis []*pbci.ConfigItem) (
[]*pbatv.AppTemplateVariableReference, error) {
contents, err := s.downloadTmplContent(kt, tmplRevisions)
vars, ciVars, allVars, err := s.getVariables(kt, tmplRevisions, cis)
if err != nil {
logs.Errorf("download template content failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}
ciContents, err := s.downloadCIContent(kt, cis)
if err != nil {
logs.Errorf("download config item content failed, err: %v, rid: %s", err, kt.Rid)
logs.Errorf("get variables failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}

allVariables := make([]string, 0)
revisionVariableMap := make(map[uint32]map[string]struct{}, len(tmplRevisions))
revisionMap := make(map[uint32]*table.TemplateRevision, len(tmplRevisions))
for idx, r := range tmplRevisions {
// extract template variables for one template config item
variables := s.tmplProc.ExtractVariables(contents[idx])
allVariables = append(allVariables, variables...)
revisionMap[r.ID] = r

revisionVariableMap[r.ID] = map[string]struct{}{}
for _, v := range variables {
for _, v := range vars[idx] {
revisionVariableMap[r.ID][v] = struct{}{}
}
}

ciVariableMap := make(map[uint32]map[string]struct{}, len(cis))
ciMap := make(map[uint32]*pbci.ConfigItem, len(cis))
for idx, ci := range cis {
// extract config item variables for one config item
variables := s.tmplProc.ExtractVariables(ciContents[idx])
allVariables = append(allVariables, variables...)
ciMap[ci.Id] = ci

ciVariableMap[ci.Id] = map[string]struct{}{}
for _, v := range variables {
for _, v := range ciVars[idx] {
ciVariableMap[ci.Id][v] = struct{}{}
}
}

allVariables = tools.RemoveDuplicateStrings(allVariables)
// Sort in ascending order
sort.Strings(allVariables)

refs := make([]*pbatv.AppTemplateVariableReference, len(allVariables))
for idx, v := range allVariables {
refs := make([]*pbatv.AppTemplateVariableReference, len(allVars))
for idx, v := range allVars {
ref := &pbatv.AppTemplateVariableReference{
VariableName: v,
}
Expand Down
22 changes: 11 additions & 11 deletions bcs-services/bcs-bscp/cmd/data-service/service/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package service

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -161,11 +160,18 @@ func (s *Service) doConfigItemOperations(kt *kit.Kit, variables []*pbtv.Template
inputVarMap[v.Name] = v.TemplateVariableSpec()
}

// NOTE: optimize to get config items whose content really contains variable
tmplRevisionsNeedRender := filterSizeForTmplRevisions(tmplRevisions)
tmplsNeedRender := filterSizeForTmplRevisions(tmplRevisions)
cisNeedRender := filterSizeForConfigItems(cis)

contents, err := s.downloadTmplContent(kt, tmplRevisionsNeedRender)
vars, ciVars, allVars, err := s.getVariables(kt, tmplsNeedRender, cisNeedRender)
if err != nil {
logs.Errorf("get variables failed, err: %v, rid: %s", err, kt.Rid)
return err
}
tmplsNeedRender = filterVarsForTmplRevisions(tmplsNeedRender, vars)
cisNeedRender = filterVarsForConfigItems(cisNeedRender, ciVars)

contents, err := s.downloadTmplContent(kt, tmplsNeedRender)
if err != nil {
logs.Errorf("download template content failed, err: %v, rid: %s", err, kt.Rid)
return err
Expand All @@ -175,12 +181,6 @@ func (s *Service) doConfigItemOperations(kt *kit.Kit, variables []*pbtv.Template
logs.Errorf("download config item content failed, err: %v, rid: %s", err, kt.Rid)
return err
}
contents = append(contents, ciContents...)

// merge all template content
allContent := bytes.Join(contents, []byte(" "))
// extract all template variables
allVars := s.tmplProc.ExtractVariables(allContent)

usedVars, renderKV, err := s.getRenderedVars(kt, allVars, inputVarMap)
if err != nil {
Expand All @@ -194,7 +194,7 @@ func (s *Service) doConfigItemOperations(kt *kit.Kit, variables []*pbtv.Template
byteSizeMap := make(map[uint32]uint64, len(tmplRevisions))
revisionMap := make(map[uint32]*table.TemplateRevision, len(tmplRevisions))
// data which need render
for idx, r := range tmplRevisionsNeedRender {
for idx, r := range tmplsNeedRender {
revisionMap[r.ID] = r
renderedContentMap[r.ID] = s.tmplProc.Render(contents[idx], renderKV)
signatureMap[r.ID] = tools.ByteSHA256(renderedContentMap[r.ID])
Expand Down
Loading

0 comments on commit 2cd3607

Please sign in to comment.