@ -4,22 +4,21 @@
# run this script to update roles/kubespray-defaults/defaults/main/download.yml
# run this script to update roles/kubespray-defaults/defaults/main/download.yml
# with new hashes.
# with new hashes.
import hashlib
import sys
import sys
import requests
import requests
from ruamel.yaml import YAML
from ruamel.yaml import YAML
MAIN _YML = " ../roles/kubespray-defaults/defaults/main/download .yml "
CHECKSUMS _YML = " ../roles/kubespray-defaults/defaults/main/checksums .yml "
def open_main _yaml ( ) :
def open_checksums _yaml ( ) :
yaml = YAML ( )
yaml = YAML ( )
yaml . explicit_start = True
yaml . explicit_start = True
yaml . preserve_quotes = True
yaml . preserve_quotes = True
yaml . width = 4096
yaml . width = 4096
with open ( MAIN _YML, " r " ) as main _yml:
data = yaml . load ( main _yml)
with open ( CHECKSUMS _YML, " r " ) as checksums _yml:
data = yaml . load ( checksums _yml)
return data , yaml
return data , yaml
@ -28,7 +27,7 @@ def download_hash(versions):
architectures = [ " arm " , " arm64 " , " amd64 " , " ppc64le " ]
architectures = [ " arm " , " arm64 " , " amd64 " , " ppc64le " ]
downloads = [ " kubelet " , " kubectl " , " kubeadm " ]
downloads = [ " kubelet " , " kubectl " , " kubeadm " ]
data , yaml = open_main _yaml ( )
data , yaml = open_checksums _yaml ( )
for download in downloads :
for download in downloads :
checksum_name = f " {download}_checksums "
checksum_name = f " {download}_checksums "
@ -36,15 +35,25 @@ def download_hash(versions):
for version in versions :
for version in versions :
if not version . startswith ( " v " ) :
if not version . startswith ( " v " ) :
version = f " v{version} "
version = f " v{version} "
url = f " https://dl.k8s.io/release/{version}/bin/linux/{arch}/{download} "
download_file = requests . get ( url , allow_redirects = True )
download_file . raise_for_status ( )
sha256sum = hashlib . sha256 ( download_file . content ) . hexdigest ( )
url = f " https://dl.k8s.io/release/{version}/bin/linux/{arch}/{download}.sha256 "
hash_file = requests . get ( url , allow_redirects = True )
if hash_file . status_code == 404 :
print ( f " Unable to find hash file for release {version} (arch: {arch}) " )
continue
if hash_file . status_code != 200 :
raise Exception ( f " Received a non-200 HTTP response code: {hash_file.status_code} (arch: {arch}, version: {version}) " )
sha256sum = hash_file . content . decode ( ) . strip ( )
if len ( sha256sum ) != 64 :
raise Exception ( f " Checksum has an unexpected length: {len(sha256sum)} (arch: {arch}, version: {version}) " )
if checksum_name not in data :
data [ checksum_name ] = { }
if arch not in data [ checksum_name ] :
data [ checksum_name ] [ arch ] = { }
data [ checksum_name ] [ arch ] [ version ] = sha256sum
data [ checksum_name ] [ arch ] [ version ] = sha256sum
with open ( MAIN_YML , " w " ) as main_yml :
yaml . dump ( data , main_yml )
print ( f " \n \n Updated {MAIN_YML} \n " )
with open ( CHECKSUMS _YML, " w " ) as checksums _yml:
yaml . dump ( data , checksums _yml)
print ( f " \n \n Updated {CHECKSUMS _YML} \n " )
def usage ( ) :
def usage ( ) :