From 57d0dc540d16a4e72076e10fdf8e0bcaebb9f335 Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Fri, 5 Jun 2020 11:23:58 -0700 Subject: [PATCH] Add csi-proxy installation into node setup script This PR follows the same step to install and start csi-proxy as kubelet binary --- cluster/gce/config-common.sh | 4 ++++ cluster/gce/util.sh | 3 ++- cluster/gce/windows/configure.ps1 | 2 ++ cluster/gce/windows/k8s-node-setup.psm1 | 30 ++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/cluster/gce/config-common.sh b/cluster/gce/config-common.sh index 80f6a687464..7da4250c83e 100644 --- a/cluster/gce/config-common.sh +++ b/cluster/gce/config-common.sh @@ -159,3 +159,7 @@ export WINDOWS_BOOTSTRAP_KUBECONFIG_FILE="${WINDOWS_K8S_DIR}\kubelet.bootstrap-k export WINDOWS_KUBEPROXY_KUBECONFIG_FILE="${WINDOWS_K8S_DIR}\kubeproxy.kubeconfig" # Pause container image for Windows container. export WINDOWS_INFRA_CONTAINER="gcr.io/gke-release/pause-win:1.2.1" +# Storage Path for csi-proxy. csi-proxy only needs to be installed for Windows. +export CSI_PROXY_STORAGE_PATH="https://storage.googleapis.com/gke-release/csi-proxy" +# Version for csi-proxy +export CSI_PROXY_VERSION="v0.1.0-gke.1" \ No newline at end of file diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 18b676cbe6c..3b04269c7fc 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -280,7 +280,6 @@ function set-preferred-region() { # Assumed vars: # PROJECT # SERVER_BINARY_TAR -# NODE_BINARY_TAR (optional) # KUBE_MANIFESTS_TAR # ZONE # Vars set: @@ -1543,6 +1542,8 @@ function build-windows-kube-env { WINDOWS_NODE_INSTANCE_PREFIX: $(yaml-quote ${WINDOWS_NODE_INSTANCE_PREFIX}) NODE_BINARY_TAR_URL: $(yaml-quote ${NODE_BINARY_TAR_URL}) NODE_BINARY_TAR_HASH: $(yaml-quote ${NODE_BINARY_TAR_HASH}) +CSI_PROXY_STORAGE_PATH: $(yaml-quote ${CSI_PROXY_STORAGE_PATH}) +CSI_PROXY_VERSION: $(yaml-quote ${CSI_PROXY_VERSION}) K8S_DIR: $(yaml-quote ${WINDOWS_K8S_DIR}) NODE_DIR: $(yaml-quote ${WINDOWS_NODE_DIR}) LOGS_DIR: $(yaml-quote ${WINDOWS_LOGS_DIR}) diff --git a/cluster/gce/windows/configure.ps1 b/cluster/gce/windows/configure.ps1 index 8a556590ae3..54e9d5238ae 100644 --- a/cluster/gce/windows/configure.ps1 +++ b/cluster/gce/windows/configure.ps1 @@ -136,6 +136,8 @@ try { Setup-ContainerRuntime DownloadAndInstall-AuthPlugin DownloadAndInstall-KubernetesBinaries + DownloadAndInstall-CSIProxyBinaries + Start-CSIProxy Create-NodePki Create-KubeletKubeconfig Create-KubeproxyKubeconfig diff --git a/cluster/gce/windows/k8s-node-setup.psm1 b/cluster/gce/windows/k8s-node-setup.psm1 index 336958b9a83..250cf197fd2 100644 --- a/cluster/gce/windows/k8s-node-setup.psm1 +++ b/cluster/gce/windows/k8s-node-setup.psm1 @@ -253,6 +253,8 @@ function Set-EnvironmentVars { "CNI_CONFIG_DIR" = ${kube_env}['CNI_CONFIG_DIR'] "WINDOWS_CNI_STORAGE_PATH" = ${kube_env}['WINDOWS_CNI_STORAGE_PATH'] "WINDOWS_CNI_VERSION" = ${kube_env}['WINDOWS_CNI_VERSION'] + "CSI_PROXY_STORAGE_PATH" = ${kube_env}['CSI_PROXY_STORAGE_PATH'] + "CSI_PROXY_VERSION" = ${kube_env}['CSI_PROXY_VERSION'] "PKI_DIR" = ${kube_env}['PKI_DIR'] "CA_FILE_PATH" = ${kube_env}['CA_FILE_PATH'] "KUBELET_CONFIG" = ${kube_env}['KUBELET_CONFIG_FILE'] @@ -386,6 +388,33 @@ function DownloadAndInstall-KubernetesBinaries { Remove-Item -Force -Recurse $tmp_dir } +# Downloads the csi-proxy binaries from kube-env's CSI_PROXY_STORAGE_PATH and +# CSI_PROXY_VERSION, and then puts them in a subdirectory of $env:NODE_DIR. +# Note: for now the installation is skipped for non-test clusters. Will be +# installed for all cluster after tests pass. +# Required ${kube_env} keys: +# CSI_PROXY_STORAGE_PATH and CSI_PROXY_VERSION +function DownloadAndInstall-CSIProxyBinaries { + if (Test-IsTestCluster $kube_env) { + if (ShouldWrite-File ${env:NODE_DIR}\csi-proxy.exe) { + $tmp_dir = 'C:\k8s_tmp' + New-Item -Force -ItemType 'directory' $tmp_dir | Out-Null + $filename = 'csi-proxy.exe' + $urls = "${env:CSI_PROXY_STORAGE_PATH}/${env:CSI_PROXY_VERSION}/$filename" + MustDownload-File -OutFile $tmp_dir\$filename -URLs $urls + Move-Item -Force $tmp_dir\$filename ${env:NODE_DIR}\$filename + # Clean up the temporary directory + Remove-Item -Force -Recurse $tmp_dir + } + } +} + +# TODO(jingxu97): Make csi-proxy.exe as a service similar to kubelet.exe +function Start-CSIProxy { + Log-Output 'Starting CSI Proxy' + Start-Process "${env:NODE_DIR}\csi-proxy.exe" +} + # TODO(pjh): this is copied from # https://github.com/Microsoft/SDN/blob/master/Kubernetes/windows/start-kubelet.ps1#L98. # See if there's a way to fetch or construct the "management subnet" so that @@ -901,7 +930,6 @@ Import-Module -Name $modulePath'.replace('K8S_DIR', ${env:K8S_DIR}) } Copy-Item ${env:K8S_DIR}\diskutil.exe -Destination "C:\Windows\system32" } - } # Setup cni network. This function supports both Docker and containerd.