Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local-up-karmada.sh 只需下载一次文件即可 #5836

Open
suyanhj opened this issue Nov 19, 2024 · 8 comments
Open

local-up-karmada.sh 只需下载一次文件即可 #5836

suyanhj opened this issue Nov 19, 2024 · 8 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@suyanhj
Copy link

suyanhj commented Nov 19, 2024

What would you like to be added:

local-up-karmada.sh 只需要下载一次依赖文件即可

Why is this needed:
国内访问github有时候会超时,我使用官方文档中快速开始的脚本启动时,有下载失败报错,发现脚本中,在每次做集群初始化时都会去github下载一次文件,且去修改配置,但文件和配置的内容都是一样,可以省去这些步骤

以下是我调整的部分

** hack/deploy-k8s-metrics-server.sh **

set -o errexit
set -o nounset

_tmp=$(mktemp -d)
download_dir=/tmp/karmada/download

function usage() {
  echo "This script will deploy metrics-server in member clusters."
  echo "Usage: hack/deploy-k8s-metrics-server.sh <MEMBER_CLUSTER_KUBECONFIG> <MEMBER_CLUSTER_NAME>"
  echo "Example: hack/deploy-k8s-metrics-server.sh ~/.kube/members.config member1"
}

cleanup() {
  rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT

if [[ $# -ne 2 ]]; then
  usage
  exit 1
fi

# create download dir
mkdir -p $download_dir

# check kube config file existence
if [[ ! -f "${1}" ]]; then
  echo -e "ERROR: failed to get kubernetes config file: '${1}', not existed.\n"
  usage
  exit 1
fi
MEMBER_CLUSTER_KUBECONFIG=$1

# check context existence
if ! kubectl config get-contexts "${2}" --kubeconfig="${MEMBER_CLUSTER_KUBECONFIG}" > /dev/null 2>&1;
then
  echo -e "ERROR: failed to get context: '${2}' not in ${MEMBER_CLUSTER_KUBECONFIG}. \n"
  usage
  exit 1
fi
MEMBER_CLUSTER_NAME=$2

# get deploy yaml
download_file=$download_dir/components.yaml
[ -f $download_file ] || \
    wget -t 3 https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.6.3/components.yaml -O "$download_file" && \
    sed -i'' -e 's/args:/args:\n        - --kubelet-insecure-tls=true/' "$download_file"

# deploy metrics-server in member cluster
kubectl --kubeconfig="${MEMBER_CLUSTER_KUBECONFIG}" --context="${MEMBER_CLUSTER_NAME}" apply -f "$download_file"

** hack/install-cli.sh **

download() {
  err_msg_start='The file already exists: '
  err_msg_end='. If an error occurs, please delete the file and re-run the current script.'
  [[ $# -eq 2 ]] || fatal 'download needs exactly 2 arguments'

  ret=0
  case $DOWNLOADER in
    curl)
      [ -f $1 ] && echo $err_msg_start $1 $err_msg_end || curl -o "$1" -sfL "$2" || ret=$?
      ;;
    wget)
      [ -f $1 ] && echo $err_msg_start $1 $err_msg_end || wget -t 3 -qO "$1" "$2" || ret=$?
      ;;
    *)
      fatal "Incorrect executable '${DOWNLOADER}'"
      ;;
    esac

  # Abort if download command failed
  [[ $ret -eq 0 ]] || fatal 'Download failed'
}
@suyanhj suyanhj added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 19, 2024
@zhzhuang-zju
Copy link
Contributor

@suyanhj 你是期望加上一个远端文件本地缓存的能力从而减小因国内访问github超时导致安装失败的概率吗?

@suyanhj
Copy link
Author

suyanhj commented Nov 19, 2024

@zhzhuang-zju 是的,对于重复下载相同文件,相同配置的操作,做一次就行了,节省时间,还不会因为因为下载文件报错的原因导致安装失败,进而重新执行脚本时又要走一遍全部的流程

@RainbowMango
Copy link
Member

我印象中local-up-karmada.sh会下载不少内容,只修改这一处难以切实缓解开发者的痛点。其他地方没有问题吗?

另外,上面的缓存方式在升级metrics组件配置时会导致缓存失效,因为版本不再匹配,且增加额外定位成本。

@chaosi-zju
Copy link
Member

是否可以这样:

  • curlwget 下载文件的动作都封装在一个函数里
  • 除了文件链接,还把该文件的sha256值也记在脚本里,每次下载文件时,先判断本地是否已存在,若已存在则判断sha256值对不对,不对再去下载新的
  • 如果脚本要更新文件链接,例如升组件版本,顺便把sha256值也更新

@suyanhj
Copy link
Author

suyanhj commented Nov 20, 2024

@RainbowMango 其他的没遇到,我改的部分,只是我在使用脚本安装时,遇到报错的时候改的,使用修改后的脚本,在下载一次文件后,后续是正常启动了。提到的更新问题,我觉得这个应该算另外的功能了,初始化下载和更新应该分开去做比较合理吧

@suyanhj
Copy link
Author

suyanhj commented Nov 20, 2024

@chaosi-zju 这个我感觉可行, 不过github我记得通过raw的那个域名直接下载文件时,github本身没有提供校验,也得下载原始文件到本地后再生成sha256(我以前是这么做的),这个是要关注的一个点,还有一个对于url文件直接更新的方式,可否考虑改成下载到本地文件,不是使用类似kubectl apply -f https://github.com/example.yaml的呢,kubectl本身对远程url是没有重试的吧,一次不成功也会中断执行,比较繁琐

@chaosi-zju
Copy link
Member

chaosi-zju commented Nov 20, 2024

也得下载原始文件到本地后再生成sha256

这个只需我们更新脚本里的下载链接时,手动下载一次生成sha256值,然后写死在脚本里;后续链接不变这个值不需动,我们要改变链接,就要把相应sha256也修改一下

@chaosi-zju
Copy link
Member

对于url文件直接更新的方式,可否考虑改成下载到本地文件,不是使用类似kubectl apply -f https://github.com/example.yaml的呢

我们当前就是先下载到本地文件,没有使用 kubectl apply -f https://xxx 吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
Status: No status
Development

No branches or pull requests

4 participants