From e756b32602af5024c6ce95c28e9ded0de732c9e0 Mon Sep 17 00:00:00 2001 From: Jiangtian Li Date: Mon, 7 May 2018 16:36:07 -0700 Subject: [PATCH] refactor build script and download wincni from github --- scripts/build-windows-k8s.sh | 80 ++++++++++++++++++++++--------- windows/Hns.psm1 | 92 ------------------------------------ 2 files changed, 57 insertions(+), 115 deletions(-) delete mode 100644 windows/Hns.psm1 diff --git a/scripts/build-windows-k8s.sh b/scripts/build-windows-k8s.sh index fc4fe68f29..dcf78870d5 100755 --- a/scripts/build-windows-k8s.sh +++ b/scripts/build-windows-k8s.sh @@ -38,7 +38,8 @@ KUBERNETES_RELEASE=$(echo $version | cut -d'.' -f1,2) KUBERNETES_TAG_BRANCH=v${version} ACS_VERSION=${version}-${acs_patch_version} ACS_BRANCH_NAME=acs-v${ACS_VERSION} -DIST_DIR=${ACS_ENGINE_HOME}/_dist/k8s-windows-v${ACS_VERSION}/k +TOP_DIR=${ACS_ENGINE_HOME}/_dist/k8s-windows-v${ACS_VERSION} +DIST_DIR=${TOP_DIR}/k fetch_k8s() { git clone https://github.com/Azure/kubernetes ${GOPATH}/src/k8s.io/kubernetes || true @@ -285,11 +286,41 @@ build_kubeproxy() { download_kubectl() { kubectl="https://storage.googleapis.com/kubernetes-release/release/v${version}/bin/windows/amd64/kubectl.exe" echo "dowloading ${kubectl} ..." - wget ${kubectl} -P k - curl ${kubectl} -o ${DIST_DIR}/kubectl.exe + curl -L ${kubectl} -o ${DIST_DIR}/kubectl.exe chmod 775 ${DIST_DIR}/kubectl.exe } +get_kube_binaries() { + if version_lt "${KUBERNETES_RELEASE}" "1.9"; then + echo "building kubelet/kubeproxy from azure repo..." + fetch_k8s + set_git_config + create_version_branch + apply_acs_cherry_picks + + # Due to what appears to be a bug in the Kubernetes Windows build system, one + # has to first build a linux binary to generate _output/bin/deepcopy-gen. + # Building to Windows w/o doing this will generate an empty deepcopy-gen. + build/run.sh make WHAT=cmd/kubelet KUBE_BUILD_PLATFORMS=linux/amd64 + + build_kubelet + build_kubeproxy + + echo "downloading kubectl..." + download_kubectl + else + echo "downloading kubelet/kubeproxy/kubectl from upstream..." + WIN_TAR=kubernetes-node-windows-amd64.tar.gz + SUB_DIR=kubernetes/node/bin + curl -L https://storage.googleapis.com/kubernetes-release/release/v${version}/${WIN_TAR} -o ${TOP_DIR}/${WIN_TAR} + tar -xzvf ${TOP_DIR}/${WIN_TAR} -C ${TOP_DIR} + cp ${TOP_DIR}/${SUB_DIR}/kubelet.exe ${DIST_DIR} + cp ${TOP_DIR}/${SUB_DIR}/kube-proxy.exe ${DIST_DIR} + cp ${TOP_DIR}/${SUB_DIR}/kubectl.exe ${DIST_DIR} + chmod 775 ${DIST_DIR}/kubectl.exe + fi +} + download_nssm() { NSSM_VERSION=2.24 NSSM_URL=https://nssm.cc/release/nssm-${NSSM_VERSION}.zip @@ -303,11 +334,15 @@ download_nssm() { download_wincni() { mkdir -p ${DIST_DIR}/cni/config - az storage blob download -f ${DIST_DIR}/cni/wincni.exe -c ${AZURE_STORAGE_CONTAINER_NAME} -n wincni.exe + WINSDN_URL=https://github.com/Microsoft/SDN/raw/master/Kubernetes/windows/ + WINCNI_EXE=cni/wincni.exe + HNS_PSM1=hns.psm1 + curl -L ${WINSDN_URL}${WINCNI_EXE} -o ${DIST_DIR}/${WINCNI_EXE} + curl -L ${WINSDN_URL}${HNS_PSM1} -o ${DIST_DIR}/${HNS_PSM1} } -copy_dockerfile_and_hns_psm1() { - cp ${ACS_ENGINE_HOME}/windows/* ${DIST_DIR} +copy_dockerfile() { + cp ${ACS_ENGINE_HOME}/windows/Dockerfile ${DIST_DIR} } create_zip() { @@ -317,31 +352,30 @@ create_zip() { } upload_zip_to_blob_storage() { - az storage blob upload -f ${DIST_DIR}/../../v${ACS_VERSION}int.zip -c ${AZURE_STORAGE_CONTAINER_NAME} -n v${ACS_VERSION}int.zip + az storage blob upload -f ${TOP_DIR}/../v${ACS_VERSION}int.zip -c ${AZURE_STORAGE_CONTAINER_NAME} -n v${ACS_VERSION}int.zip } push_acs_branch() { - cd ${GOPATH}/src/k8s.io/kubernetes - git push origin ${ACS_BRANCH_NAME} + if version_lt "${KUBERNETES_RELEASE}" "1.9"; then + echo "push to azure repo..." + cd ${GOPATH}/src/k8s.io/kubernetes + git push origin ${ACS_BRANCH_NAME} + else + echo "no need to push to azure repo" + fi +} + +cleanup_output() { + rm ${TOP_DIR}/../v${ACS_VERSION}int.zip + rm -r ${TOP_DIR} } create_dist_dir -fetch_k8s -set_git_config -create_version_branch -apply_acs_cherry_picks - -# Due to what appears to be a bug in the Kubernetes Windows build system, one -# has to first build a linux binary to generate _output/bin/deepcopy-gen. -# Building to Windows w/o doing this will generate an empty deepcopy-gen. -build/run.sh make WHAT=cmd/kubelet KUBE_BUILD_PLATFORMS=linux/amd64 - -build_kubelet -build_kubeproxy -download_kubectl +get_kube_binaries download_nssm download_wincni -copy_dockerfile_and_hns_psm1 +copy_dockerfile create_zip upload_zip_to_blob_storage push_acs_branch +cleanup_output diff --git a/windows/Hns.psm1 b/windows/Hns.psm1 deleted file mode 100644 index db66bdd848..0000000000 --- a/windows/Hns.psm1 +++ /dev/null @@ -1,92 +0,0 @@ -function Get-VmComputeNativeMethods() -{ - $signature = @' - [DllImport("vmcompute.dll")] - public static extern void HNSCall([MarshalAs(UnmanagedType.LPWStr)] string method, [MarshalAs(UnmanagedType.LPWStr)] string path, [MarshalAs(UnmanagedType.LPWStr)] string request, [MarshalAs(UnmanagedType.LPWStr)] out string response); -'@ - - # Compile into runtime type - Add-Type -MemberDefinition $signature -Namespace VmCompute.PrivatePInvoke -Name NativeMethods -PassThru -} - -function New-HnsNetwork -{ - param - ( - [parameter(Mandatory=$false, Position=0)] - [string] $JsonString, - [ValidateSet('L2Bridge')] - [parameter(Mandatory = $false, Position = 0)] - [string] $Type, - [parameter(Mandatory = $false)] [string] $Name, - [parameter(Mandatory = $false)] [string] $AddressPrefix, - [parameter(Mandatory = $false)] [string] $Gateway, - [parameter(Mandatory = $false)] [string] $DNSServer - ) - - Begin { - if (!$JsonString) { - $netobj = @{ - Type = $Type; - }; - - if ($Name) { - $netobj += @{ - Name = $Name; - } - } - - if ($AddressPrefix -and $Gateway) { - $netobj += @{ - Subnets = @( - @{ - AddressPrefix = $AddressPrefix; - GatewayAddress = $Gateway; - } - ); - } - } - - if ($DNSServerName) { - $netobj += @{ - DNSServerList = $DNSServer - } - } - - $JsonString = ConvertTo-Json $netobj -Depth 10 - } - - } - Process { - $Method = "POST"; - $hnsPath = "/networks/"; - $request = $JsonString; - - Write-Verbose "Invoke-HNSRequest Method[$Method] Path[$hnsPath] Data[$request]" - - $output = ""; - $response = ""; - $hnsApi = Get-VmComputeNativeMethods - $hnsApi::HNSCall($Method, $hnsPath, "$request", [ref] $response); - - Write-Verbose "Result: $response" - if ($response) - { - try { - $output = ($response | ConvertFrom-Json); - } catch { - Write-Error $_.Exception.Message - return "" - } - if ($output.Error) - { - Write-Error $output; - } - $output = $output.Output; - } - - return $output; - } -} - -Export-ModuleMember -Function New-HNSNetwork