Skip to content

Commit

Permalink
集群apiserver证书支持直接配置IP和域名
Browse files Browse the repository at this point in the history
  • Loading branch information
denglouping committed Mar 4, 2024
1 parent a6e9ad8 commit d2a2868
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 17 additions & 10 deletions bcs-ops/functions/k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,19 @@ k8s::safe_add_helmrepo() {
#######################################
# add vip to K8S apiserver certs
# Arguments:
# $1: vip
# $1: op_type
# $2: excute (if op_type is $1, then $2 is path)
# $3: vips
# $4: path
# Return:
# add vip success - return 0
# add vip fail - return 1
# excute success - return 0
# excute - return 1
#######################################
k8s::config_master_vip() {
op_type=$1
excute=$2
vips=$3
path=$4

if [[ "${op_type}" == "list" ]];then
path=$2
fi
vips=${3:-""}
path=${4:-$2}

if [[ -z "${path}" ]];then
path=$(kubeadm_config_file="/tmp/kubeadm-$(date +%Y-%m-%d).yaml")
Expand All @@ -78,7 +77,7 @@ k8s::config_master_vip() {
add)
for vip in ${vips//,/ };do
if [[ -n "${vip}" ]];then
yq e -i '(select(.apiServer != null)|.apiServer.certSANs) += ["'${vip}'"]' ${path}
yq e -i '(select(.apiServer != null)|.apiServer.certSANs) += ["'${vip}'"]| select(.apiServer != null)|.apiServer.certSANs|= unique' ${path}
fi
done
;;
Expand Down Expand Up @@ -106,6 +105,14 @@ k8s::config_master_vip() {
utils::log "OK" "${op_type} ${vips} ${path}"
}

#######################################
# add vip to K8S apiserver certs
# Arguments:
# $1: vip
# Return:
# add vip success - return 0
# add vip fail - return 1
#######################################
k8s::add_vip_to_cert() {
vip=$1
local kubeadm_config_file
Expand Down
4 changes: 1 addition & 3 deletions bcs-ops/k8s/render_kubeadm
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,9 @@ safe_source() {
fi
}

safe_source "${ROOT_DIR}/functions/k8s.sh"

main() {
local source_files ipv6_status cri_type
source_files=("${ROOT_DIR}/functions/utils.sh" "${ROOT_DIR}/env/bcs.env")
source_files=("${ROOT_DIR}/functions/utils.sh" "${ROOT_DIR}/env/bcs.env" "${ROOT_DIR}/functions/k8s.sh")
for file in "${source_files[@]}"; do
safe_source "$file"
done
Expand Down

0 comments on commit d2a2868

Please sign in to comment.