From 2f453992980ae5585e842c31639d2c8708ec581f Mon Sep 17 00:00:00 2001 From: Smana Date: Tue, 14 Jun 2016 20:59:54 +0200 Subject: [PATCH 1/4] use python script to update sha256 sum in the vars --- roles/download/defaults/kube_versions.yml | 9 ++ roles/download/defaults/main.yml | 7 +- roles/uploads/defaults/kube_versions.yml | 9 ++ roles/uploads/defaults/main.yml | 6 +- scripts/change_k8s_version.py | 85 ++++++++++++++++ scripts/change_k8s_version.sh | 117 ---------------------- 6 files changed, 108 insertions(+), 125 deletions(-) create mode 100644 roles/download/defaults/kube_versions.yml create mode 100644 roles/uploads/defaults/kube_versions.yml create mode 100644 scripts/change_k8s_version.py delete mode 100755 scripts/change_k8s_version.sh diff --git a/roles/download/defaults/kube_versions.yml b/roles/download/defaults/kube_versions.yml new file mode 100644 index 000000000..dabe543e5 --- /dev/null +++ b/roles/download/defaults/kube_versions.yml @@ -0,0 +1,9 @@ +kube_version: + v1.2.3: + kube_apiserver_checksum: ebaeeeb72cb29b358337b330617a96355ff2d08a5a523fc1a81beba36cc9d6f9 + kubectl_checksum: 394853edd409a721bcafe4f1360009ef9f845050719fe7d6fc7176f45cc92a8c + kubelet_checksum: 633bb41c51c5c0df0645dd60ba82b12eba39d009eb87bae9227de7d9a89c0797 + v1.2.4: + kube_apiserver_checksum: 6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e + kubectl_checksum: dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897 + kubelet_checksum: 4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341 diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml index 2be226e62..51db5d1b0 100644 --- a/roles/download/defaults/main.yml +++ b/roles/download/defaults/main.yml @@ -4,8 +4,10 @@ local_release_dir: /tmp # if this is set to true will only download files once download_run_once: False + # Versions -kube_version: "v1.2.4" +include_vars: kube_versions.yml + etcd_version: v2.3.7 calico_version: v0.20.0 calico_cni_version: v1.3.1 @@ -28,9 +30,6 @@ calico_cni_checksum: "ac05cb9254b5aaa5822cf10325983431bd25489147f2edf9dec7e43d99 calico_cni_ipam_checksum: "3df6951a30749c279229e7e318e74ac4e41263996125be65257db7cd25097273" weave_checksum: "28d2c4e2b1ad8600da69882501eba697679aea10a5e61c769aa3a9ee72b0d89a" etcd_checksum: "ab102d271026a4060c9f85ecad11f454d82b1df7b8e676cc3da69f67eb078729" -kubectl_checksum: "dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897" -kubelet_checksum: "4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341" -kube_apiserver_checksum: "6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e" downloads: calico: diff --git a/roles/uploads/defaults/kube_versions.yml b/roles/uploads/defaults/kube_versions.yml new file mode 100644 index 000000000..dabe543e5 --- /dev/null +++ b/roles/uploads/defaults/kube_versions.yml @@ -0,0 +1,9 @@ +kube_version: + v1.2.3: + kube_apiserver_checksum: ebaeeeb72cb29b358337b330617a96355ff2d08a5a523fc1a81beba36cc9d6f9 + kubectl_checksum: 394853edd409a721bcafe4f1360009ef9f845050719fe7d6fc7176f45cc92a8c + kubelet_checksum: 633bb41c51c5c0df0645dd60ba82b12eba39d009eb87bae9227de7d9a89c0797 + v1.2.4: + kube_apiserver_checksum: 6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e + kubectl_checksum: dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897 + kubelet_checksum: 4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341 diff --git a/roles/uploads/defaults/main.yml b/roles/uploads/defaults/main.yml index 3dadb504b..a776dfeae 100644 --- a/roles/uploads/defaults/main.yml +++ b/roles/uploads/defaults/main.yml @@ -2,7 +2,8 @@ local_release_dir: /tmp # Versions -kube_version: "v1.2.4" +include_vars: kube_versions.yml + etcd_version: v2.3.7 calico_version: v0.20.0 calico_cni_version: v1.3.1 @@ -22,9 +23,6 @@ calico_cni_checksum: "ac05cb9254b5aaa5822cf10325983431bd25489147f2edf9dec7e43d99 calico_cni_ipam_checksum: "3df6951a30749c279229e7e318e74ac4e41263996125be65257db7cd25097273" weave_checksum: "28d2c4e2b1ad8600da69882501eba697679aea10a5e61c769aa3a9ee72b0d89a" etcd_checksum: "ab102d271026a4060c9f85ecad11f454d82b1df7b8e676cc3da69f67eb078729" -kubectl_checksum: "dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897" -kubelet_checksum: "4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341" -kube_apiserver_checksum: "6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e" downloads: - name: calico diff --git a/scripts/change_k8s_version.py b/scripts/change_k8s_version.py new file mode 100644 index 000000000..8db6aee07 --- /dev/null +++ b/scripts/change_k8s_version.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of Kargo. +# +# Foobar is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Foobar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Foobar. If not, see . +import sys +import hashlib +import urllib2 +import yaml +import argparse + + +def get_remote_sha256_sum(url, max_file_size=100*1024*1024): + remote = urllib2.urlopen(url) + hash = hashlib.sha256() + total_read = 0 + while True: + data = remote.read(4096) + total_read += 4096 + if not data or total_read > max_file_size: + break + hash.update(data) + return hash.hexdigest() + + +def read_vars(var_file): + """ + Read the variables file + """ + try: + with open(var_file, "r") as f: + kargovars = yaml.load(f) + except: + print( + "Can't read variables file %s" % var_file + ) + sys.exit(1) + return kargovars + + +def get_kube_sha256(version, download_url, binaries): + kube_sha256 = dict() + for k in binaries: + s = get_remote_sha256_sum(download_url + '/' + k) + kube_sha256[k] = s + kube_sha256[k + '_checksum'] = kube_sha256.pop(k) + kube_sha256['kube_apiserver_checksum'] = kube_sha256.pop('kube-apiserver_checksum') + return(kube_sha256) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + prog='change_k8s_version', + description='%(prog)s changes the version to be installed with kargo', + ) + + parser.add_argument( + '-v', '--version', dest='kube_version', required=True, + help="kubernetes version" + ) + args = parser.parse_args() + + kube_binaries = ['kubelet', 'kubectl', 'kube-apiserver'] + kargo_root = ".." + var_files = ['../roles/uploads/defaults/kube_versions.yml', '../roles/download/defaults/kube_versions.yml'] + kube_download_url = "https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64" % args.kube_version + + new = get_kube_sha256(args.kube_version, kube_download_url, kube_binaries) + for f in var_files: + current = read_vars(f) + current['kube_version'][args.kube_version] = new + with open(f, 'w') as out: + out.write(yaml.dump(current, indent=4, default_flow_style=False)) diff --git a/scripts/change_k8s_version.sh b/scripts/change_k8s_version.sh deleted file mode 100755 index 8c00e7168..000000000 --- a/scripts/change_k8s_version.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -# This file is part of Kargo. -# -# Foobar is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Foobar is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Foobar. If not, see . - -#color variables -txtbld=$(tput bold) # Bold -bldred=${txtbld}$(tput setaf 1) # red -bldgre=${txtbld}$(tput setaf 2) # green -bldylw=${txtbld}$(tput setaf 3) # yellow -txtrst=$(tput sgr0) # Reset -err=${bldred}ERROR${txtrst} -info=${bldgre}INFO${txtrst} -warn=${bldylw}WARNING${txtrst} - -usage() -{ - cat << EOF -Update ansible playbook with a specific kubernetes version - -Usage : $(basename $0) -v - -h | --help : Show this message - -i | --init : Initial upgrade (download binaries) - -v | --version : Kubernetes version - - ex : switch to kubernetes v1.2.4 - $(basename $0) -v v1.2.4 -EOF -} - -# Options parsing -while (($#)); do - case "$1" in - -h | --help) usage; exit 0;; - -i | --init) INIT=1; shift;; - -v | --version) VERS=${2}; shift 2;; - *) - usage - echo "ERROR : Unknown option" - exit 3 - ;; - esac -done - -if [ -z ${VERS} ]; then - usage - echo -e "\n${err}: The option version must be defined" - exit 3 -else - if ! [[ ${VERS} =~ ^v[0-9]\.[0-9]\.[0-9]$ ]]; then - echo -e "\n${err}: Invalid version format (ex: v1.2.4)" - exit 1 - fi -fi - -UPLOAD_VARFILE="roles/uploads/defaults/main.yml" -DOWNLOAD_VARFILE="roles/download/defaults/main.yml" -K8S_BIN="kubelet kubectl kube-apiserver" - -if [[ ${INIT} -eq 1 ]]; then - DOWNLOAD_URL=https://storage.googleapis.com/kubernetes-release/release/${VERS}/bin/linux/amd64 - TMP_DIR=$(mktemp -d --tmpdir kubernetes_tmpbin_XXXXXXX) - sed -i "s/^hyperkube_image_tag.*$/hyperkube_image_tag: \"${VERS}\"/" roles/kubernetes/node/defaults/main.yml - trap 'rm -rf "${tmpdir}"' EXIT - cd "${tmpdir}" - - for BIN in ${K8S_BIN}; do - curl -s -o ${BIN} ${DOWNLOAD_URL}/${BIN} - if [ $? -ne 0 ]; then - echo -e "\n${err}: Downloading ${BIN} failed! Try again" - exit 1 - else - echo -e "\n${info}: ${BIN} downloaded successfuly" - fi - done - - for varfile in ${UPLOAD_VARFILE} ${DOWNLOAD_VARFILE}; do - sed -i "s/^kube_version.*$/kube_version: \"${VERS}\"/" ${varfile} - - for BIN in ${K8S_BIN}; do - CHECKSUM=$(sha256sum ${BIN} | cut -d' ' -f1) - BIN=$(echo ${BIN} | tr '-' '_') - sed -i "s/^${BIN}_checksum.*$/${BIN}_checksum: \"${CHECKSUM}\"/" ${varfile} - done - done - - rm -rf "${tmpdir}" -else - CHECKSUM_URL=https://storage.googleapis.com/kargo/${VERS}_k8s-sha256 - sed -i "s/^hyperkube_image_tag.*$/hyperkube_image_tag: \"${VERS}\"/" roles/kubernetes/node/defaults/main.yml - for varfile in ${UPLOAD_VARFILE} ${DOWNLOAD_VARFILE}; do - sed -i "s/^kube_version.*$/kube_version: \"${VERS}\"/" ${varfile} - for BIN in ${K8S_BIN}; do - if [[ "${BIN}" =~ "apiserver" ]]; then - BIN="apiserver" - fi - line=$(curl -sk ${CHECKSUM_URL} | grep ${BIN}) - CHECKSUM=$(echo ${line} | cut -d':' -f2) - if [[ "${BIN}" =~ "apiserver" ]]; then - BIN="kube_apiserver" - fi - sed -i "s/^${BIN}_checksum.*$/${BIN}_checksum: \"${CHECKSUM}\"/" ${varfile} - done - done -fi From a736930f358b8aa275015c523cb5b8d627dfef2d Mon Sep 17 00:00:00 2001 From: Smana Date: Wed, 15 Jun 2016 20:25:58 +0200 Subject: [PATCH 2/4] change hyperkube repository --- roles/download/defaults/kube_versions.yml | 13 +++++++---- roles/download/defaults/main.yml | 6 ++--- roles/kubernetes/node/defaults/main.yml | 2 +- roles/uploads/defaults/kube_versions.yml | 13 +++++++---- roles/uploads/defaults/main.yml | 6 ++--- scripts/change_k8s_version.py | 28 +++++++++++++++++++---- 6 files changed, 49 insertions(+), 19 deletions(-) diff --git a/roles/download/defaults/kube_versions.yml b/roles/download/defaults/kube_versions.yml index dabe543e5..a915bb258 100644 --- a/roles/download/defaults/kube_versions.yml +++ b/roles/download/defaults/kube_versions.yml @@ -1,9 +1,14 @@ -kube_version: +kube_checksum: + v1.2.2: + kube_apiserver: eb1bfd8b877052cbd1991b8c429a1d06661f4cb019905e20e128174f724e16de + kubectl: 473e6924569fba30d4a50cecdc2cae5f31d97d1f662463e85b74a472105dcff4 + kubelet: f16827dc7e7c82f0e215f0fc73eb01e2dfe91a2ec83f9cbcaf8d37c91b64fd3b v1.2.3: kube_apiserver_checksum: ebaeeeb72cb29b358337b330617a96355ff2d08a5a523fc1a81beba36cc9d6f9 kubectl_checksum: 394853edd409a721bcafe4f1360009ef9f845050719fe7d6fc7176f45cc92a8c kubelet_checksum: 633bb41c51c5c0df0645dd60ba82b12eba39d009eb87bae9227de7d9a89c0797 v1.2.4: - kube_apiserver_checksum: 6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e - kubectl_checksum: dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897 - kubelet_checksum: 4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341 + kube_apiserver: 6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e + kubectl: dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897 + kubelet: 4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341 +kube_version: v1.2.4 diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml index 51db5d1b0..4643086b6 100644 --- a/roles/download/defaults/main.yml +++ b/roles/download/defaults/main.yml @@ -76,7 +76,7 @@ downloads: kubernetes_kubelet: version: "{{kube_version}}" dest: kubernetes/bin/kubelet - sha256: "{{kubelet_checksum}}" + sha256: "{{kube_checksum.kubelet}}" source_url: "{{ kubelet_download_url }}" url: "{{ kubelet_download_url }}" owner: "kube" @@ -84,7 +84,7 @@ downloads: kubernetes_kubectl: dest: kubernetes/bin/kubectl version: "{{kube_version}}" - sha256: "{{kubectl_checksum}}" + sha256: "{{kube_checksum.kubectl}}" source_url: "{{ kubectl_download_url }}" url: "{{ kubectl_download_url }}" owner: "kube" @@ -92,7 +92,7 @@ downloads: kubernetes_apiserver: dest: kubernetes/bin/kube-apiserver version: "{{kube_version}}" - sha256: "{{kube_apiserver_checksum}}" + sha256: "{{kube_checksum.kube_apiserver}}" source_url: "{{ apiserver_download_url }}" url: "{{ apiserver_download_url }}" owner: "kube" diff --git a/roles/kubernetes/node/defaults/main.yml b/roles/kubernetes/node/defaults/main.yml index e96e7115b..98b1f8b7c 100644 --- a/roles/kubernetes/node/defaults/main.yml +++ b/roles/kubernetes/node/defaults/main.yml @@ -31,7 +31,7 @@ dns_domain: "{{ cluster_name }}" kube_proxy_mode: userspace -hyperkube_image_repo: quay.io/smana/kubernetes-hyperkube +hyperkube_image_repo: "quay.io/smana/kubernetes-hyperkube" hyperkube_image_tag: "v1.2.4" # IP address of the DNS server. diff --git a/roles/uploads/defaults/kube_versions.yml b/roles/uploads/defaults/kube_versions.yml index dabe543e5..a915bb258 100644 --- a/roles/uploads/defaults/kube_versions.yml +++ b/roles/uploads/defaults/kube_versions.yml @@ -1,9 +1,14 @@ -kube_version: +kube_checksum: + v1.2.2: + kube_apiserver: eb1bfd8b877052cbd1991b8c429a1d06661f4cb019905e20e128174f724e16de + kubectl: 473e6924569fba30d4a50cecdc2cae5f31d97d1f662463e85b74a472105dcff4 + kubelet: f16827dc7e7c82f0e215f0fc73eb01e2dfe91a2ec83f9cbcaf8d37c91b64fd3b v1.2.3: kube_apiserver_checksum: ebaeeeb72cb29b358337b330617a96355ff2d08a5a523fc1a81beba36cc9d6f9 kubectl_checksum: 394853edd409a721bcafe4f1360009ef9f845050719fe7d6fc7176f45cc92a8c kubelet_checksum: 633bb41c51c5c0df0645dd60ba82b12eba39d009eb87bae9227de7d9a89c0797 v1.2.4: - kube_apiserver_checksum: 6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e - kubectl_checksum: dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897 - kubelet_checksum: 4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341 + kube_apiserver: 6ac99b36b02968459e026fcfc234207c66064b5e11816b69dd8fc234b2ffec1e + kubectl: dac61fbd506f7a17540feca691cd8a9d9d628d59661eebce788a50511f578897 + kubelet: 4adaf40592248eef6fd4fa126464915ea41e624a70dc77178089760ed235e341 +kube_version: v1.2.4 diff --git a/roles/uploads/defaults/main.yml b/roles/uploads/defaults/main.yml index a776dfeae..039c6656c 100644 --- a/roles/uploads/defaults/main.yml +++ b/roles/uploads/defaults/main.yml @@ -74,7 +74,7 @@ downloads: - name: kubernetes-kubelet version: "{{kube_version}}" dest: kubernetes/bin/kubelet - sha256: "{{kubelet_checksum}}" + sha256: "{{kube_checksum.kubelet}}" source_url: "{{ kube_download_url }}/kubelet" url: "{{ kube_download_url }}/kubelet" owner: "kube" @@ -83,7 +83,7 @@ downloads: - name: kubernetes-kubectl dest: kubernetes/bin/kubectl version: "{{kube_version}}" - sha256: "{{kubectl_checksum}}" + sha256: "{{kube_checksum.kubectl}}" source_url: "{{ kube_download_url }}/kubectl" url: "{{ kube_download_url }}/kubectl" owner: "kube" @@ -92,7 +92,7 @@ downloads: - name: kubernetes-apiserver dest: kubernetes/bin/kube-apiserver version: "{{kube_version}}" - sha256: "{{kube_apiserver_checksum}}" + sha256: "{{kube_checksum.kube_apiserver}}" source_url: "{{ kube_download_url }}/kube-apiserver" url: "{{ kube_download_url }}/kube-apiserver" owner: "kube" diff --git a/scripts/change_k8s_version.py b/scripts/change_k8s_version.py index 8db6aee07..1fc7d0972 100644 --- a/scripts/change_k8s_version.py +++ b/scripts/change_k8s_version.py @@ -15,11 +15,14 @@ # # You should have received a copy of the GNU General Public License # along with Foobar. If not, see . +import os import sys import hashlib import urllib2 import yaml import argparse +import shutil +from re import sub def get_remote_sha256_sum(url, max_file_size=100*1024*1024): @@ -55,11 +58,22 @@ def get_kube_sha256(version, download_url, binaries): for k in binaries: s = get_remote_sha256_sum(download_url + '/' + k) kube_sha256[k] = s - kube_sha256[k + '_checksum'] = kube_sha256.pop(k) - kube_sha256['kube_apiserver_checksum'] = kube_sha256.pop('kube-apiserver_checksum') + kube_sha256['kube_apiserver'] = kube_sha256.pop('kube-apiserver') return(kube_sha256) +def file_sub(file, regex, string): + "Substitute string in a file" + shutil.move(file, file + '~') + f = open(file + '~', 'r') + data = f.read() + o = open(file, 'w') + o.write(sub(regex, string, data)) + f.close() + o.close() + os.remove(file + '~') + + if __name__ == '__main__': parser = argparse.ArgumentParser( prog='change_k8s_version', @@ -70,16 +84,22 @@ if __name__ == '__main__': '-v', '--version', dest='kube_version', required=True, help="kubernetes version" ) + parser.add_argument( + '-r', '--repository', dest='docker_repository', required=True, + help="hyperkube docker repository" + ) args = parser.parse_args() + file_sub('../roles/kubernetes/node/defaults/main.yml', r'.*hyperkube_image_repo.*', 'hyperkube_image_repo: "%s"' % args.docker_repository) + file_sub('../roles/kubernetes/node/defaults/main.yml', r'.*hyperkube_image_tag.*', 'hyperkube_image_tag: "%s"' % args.kube_version) + kube_binaries = ['kubelet', 'kubectl', 'kube-apiserver'] - kargo_root = ".." var_files = ['../roles/uploads/defaults/kube_versions.yml', '../roles/download/defaults/kube_versions.yml'] kube_download_url = "https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64" % args.kube_version new = get_kube_sha256(args.kube_version, kube_download_url, kube_binaries) for f in var_files: current = read_vars(f) - current['kube_version'][args.kube_version] = new + current['kube_checksum'][args.kube_version] = new with open(f, 'w') as out: out.write(yaml.dump(current, indent=4, default_flow_style=False)) From 908fb20b2f95d32bbdc4ae97f328c0597627c1c9 Mon Sep 17 00:00:00 2001 From: Smana Date: Sun, 26 Jun 2016 21:14:45 +0200 Subject: [PATCH 3/4] include variables from a distinct file --- roles/download/defaults/main.yml | 7 +++---- roles/download/tasks/main.yml | 2 ++ roles/download/{defaults => vars}/kube_versions.yml | 0 roles/uploads/defaults/main.yml | 6 +++--- roles/uploads/tasks/main.yml | 2 ++ roles/uploads/{defaults => vars}/kube_versions.yml | 0 scripts/change_k8s_version.py | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) rename roles/download/{defaults => vars}/kube_versions.yml (100%) rename roles/uploads/{defaults => vars}/kube_versions.yml (100%) diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml index 4643086b6..5128e8f3e 100644 --- a/roles/download/defaults/main.yml +++ b/roles/download/defaults/main.yml @@ -4,7 +4,6 @@ local_release_dir: /tmp # if this is set to true will only download files once download_run_once: False - # Versions include_vars: kube_versions.yml @@ -76,7 +75,7 @@ downloads: kubernetes_kubelet: version: "{{kube_version}}" dest: kubernetes/bin/kubelet - sha256: "{{kube_checksum.kubelet}}" + sha256: "{{vars['kube_checksum'][kube_version]['kubelet']}}" source_url: "{{ kubelet_download_url }}" url: "{{ kubelet_download_url }}" owner: "kube" @@ -84,7 +83,7 @@ downloads: kubernetes_kubectl: dest: kubernetes/bin/kubectl version: "{{kube_version}}" - sha256: "{{kube_checksum.kubectl}}" + sha256: "{{vars['kube_checksum'][kube_version]['kubectl']}}" source_url: "{{ kubectl_download_url }}" url: "{{ kubectl_download_url }}" owner: "kube" @@ -92,7 +91,7 @@ downloads: kubernetes_apiserver: dest: kubernetes/bin/kube-apiserver version: "{{kube_version}}" - sha256: "{{kube_checksum.kube_apiserver}}" + sha256: "{{vars['kube_checksum'][kube_version]['kube_apiserver']}}" source_url: "{{ apiserver_download_url }}" url: "{{ apiserver_download_url }}" owner: "kube" diff --git a/roles/download/tasks/main.yml b/roles/download/tasks/main.yml index 40bd3c902..40c52f5ea 100644 --- a/roles/download/tasks/main.yml +++ b/roles/download/tasks/main.yml @@ -1,4 +1,6 @@ --- +- include_vars: kube_versions.yml + - name: downloading... debug: msg: "{{ download.url }}" diff --git a/roles/download/defaults/kube_versions.yml b/roles/download/vars/kube_versions.yml similarity index 100% rename from roles/download/defaults/kube_versions.yml rename to roles/download/vars/kube_versions.yml diff --git a/roles/uploads/defaults/main.yml b/roles/uploads/defaults/main.yml index 039c6656c..a8f1002e2 100644 --- a/roles/uploads/defaults/main.yml +++ b/roles/uploads/defaults/main.yml @@ -74,7 +74,7 @@ downloads: - name: kubernetes-kubelet version: "{{kube_version}}" dest: kubernetes/bin/kubelet - sha256: "{{kube_checksum.kubelet}}" + sha256: "{{vars['kube_checksum'][kube_version]['kubelet']}}" source_url: "{{ kube_download_url }}/kubelet" url: "{{ kube_download_url }}/kubelet" owner: "kube" @@ -83,7 +83,7 @@ downloads: - name: kubernetes-kubectl dest: kubernetes/bin/kubectl version: "{{kube_version}}" - sha256: "{{kube_checksum.kubectl}}" + sha256: "{{vars['kube_checksum'][kube_version]['kubectl']}}" source_url: "{{ kube_download_url }}/kubectl" url: "{{ kube_download_url }}/kubectl" owner: "kube" @@ -92,7 +92,7 @@ downloads: - name: kubernetes-apiserver dest: kubernetes/bin/kube-apiserver version: "{{kube_version}}" - sha256: "{{kube_checksum.kube_apiserver}}" + sha256: "{{vars['kube_checksum'][kube_version]['kube_apiserver']}}" source_url: "{{ kube_download_url }}/kube-apiserver" url: "{{ kube_download_url }}/kube-apiserver" owner: "kube" diff --git a/roles/uploads/tasks/main.yml b/roles/uploads/tasks/main.yml index 279d26dd5..b19c2aa93 100644 --- a/roles/uploads/tasks/main.yml +++ b/roles/uploads/tasks/main.yml @@ -1,4 +1,6 @@ --- +- include_vars: "kube_versions.yml" + - name: Create the checksum file lineinfile: create: yes diff --git a/roles/uploads/defaults/kube_versions.yml b/roles/uploads/vars/kube_versions.yml similarity index 100% rename from roles/uploads/defaults/kube_versions.yml rename to roles/uploads/vars/kube_versions.yml diff --git a/scripts/change_k8s_version.py b/scripts/change_k8s_version.py index 1fc7d0972..6ffbc7946 100644 --- a/scripts/change_k8s_version.py +++ b/scripts/change_k8s_version.py @@ -94,7 +94,7 @@ if __name__ == '__main__': file_sub('../roles/kubernetes/node/defaults/main.yml', r'.*hyperkube_image_tag.*', 'hyperkube_image_tag: "%s"' % args.kube_version) kube_binaries = ['kubelet', 'kubectl', 'kube-apiserver'] - var_files = ['../roles/uploads/defaults/kube_versions.yml', '../roles/download/defaults/kube_versions.yml'] + var_files = ['../roles/uploads/vars/kube_versions.yml', '../roles/download/vars/kube_versions.yml'] kube_download_url = "https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64" % args.kube_version new = get_kube_sha256(args.kube_version, kube_download_url, kube_binaries) From 2bad4cd564cc998280b12132685ffc2ceb7e351c Mon Sep 17 00:00:00 2001 From: Smana Date: Mon, 27 Jun 2016 13:02:11 +0200 Subject: [PATCH 4/4] change licence to apache2 --- scripts/change_k8s_version.py | 40 ++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/scripts/change_k8s_version.py b/scripts/change_k8s_version.py index 6ffbc7946..316a2d5e4 100644 --- a/scripts/change_k8s_version.py +++ b/scripts/change_k8s_version.py @@ -1,20 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +# Copyright 2016 Kubespray # -# This file is part of Kargo. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# Foobar is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# http://www.apache.org/licenses/LICENSE-2.0 # -# Foobar is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Foobar. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import sys import hashlib @@ -90,11 +89,22 @@ if __name__ == '__main__': ) args = parser.parse_args() - file_sub('../roles/kubernetes/node/defaults/main.yml', r'.*hyperkube_image_repo.*', 'hyperkube_image_repo: "%s"' % args.docker_repository) - file_sub('../roles/kubernetes/node/defaults/main.yml', r'.*hyperkube_image_tag.*', 'hyperkube_image_tag: "%s"' % args.kube_version) + kargo_root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + file_sub( + os.path.join(kargo_root_path, 'roles/kubernetes/node/defaults/main.yml'), + r'.*hyperkube_image_repo.*', 'hyperkube_image_repo: "%s"' % args.docker_repository + ) + file_sub( + os.path.join(kargo_root_path, 'roles/kubernetes/node/defaults/main.yml'), + r'.*hyperkube_image_tag.*', 'hyperkube_image_tag: "%s"' % args.kube_version + ) kube_binaries = ['kubelet', 'kubectl', 'kube-apiserver'] - var_files = ['../roles/uploads/vars/kube_versions.yml', '../roles/download/vars/kube_versions.yml'] + var_files = [ + os.path.join(kargo_root_path, 'roles/uploads/vars/kube_versions.yml'), + os.path.join(kargo_root_path, 'roles/download/vars/kube_versions.yml') + ] kube_download_url = "https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64" % args.kube_version new = get_kube_sha256(args.kube_version, kube_download_url, kube_binaries)