mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Fix UpdateAddonsTactic to use local repo, add KUBE_VERSION option
This commit is contained in:
parent
44aa1679c9
commit
d697b10885
@ -45,31 +45,46 @@ def clean_addon_dir(addon_dir):
|
|||||||
os.makedirs(addon_dir)
|
os.makedirs(addon_dir)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
def run_with_logging(command):
|
||||||
def kubernetes_repo():
|
""" Run a command with controlled logging """
|
||||||
""" Shallow clone kubernetes repo and clean up when we are done """
|
log.debug("Running: %s" % command)
|
||||||
repo = "https://github.com/kubernetes/kubernetes.git"
|
process = subprocess.Popen(command, stderr=subprocess.PIPE)
|
||||||
path = tempfile.mkdtemp(prefix="kubernetes")
|
|
||||||
try:
|
|
||||||
log.info("Cloning " + repo)
|
|
||||||
cmd = ["git", "clone", "--depth", "1", repo, path]
|
|
||||||
process = subprocess.Popen(cmd, stderr=subprocess.PIPE)
|
|
||||||
stderr = process.communicate()[1].rstrip()
|
stderr = process.communicate()[1].rstrip()
|
||||||
process.wait()
|
process.wait()
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
log.error(stderr)
|
log.error(stderr)
|
||||||
raise Exception("clone failed: exit code %d" % process.returncode)
|
raise Exception("%s: exit code %d" % (command, process.returncode))
|
||||||
log.debug(stderr)
|
log.debug(stderr)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def kubernetes_repo():
|
||||||
|
""" Yield a kubernetes repo to copy addons from.
|
||||||
|
|
||||||
|
If KUBE_VERSION is set, this will clone the local repo and checkout the
|
||||||
|
corresponding branch. Otherwise, the local branch will be used. """
|
||||||
|
repo = os.path.abspath("../../../..")
|
||||||
|
if "KUBE_VERSION" in os.environ:
|
||||||
|
branch = os.environ["KUBE_VERSION"]
|
||||||
|
log.info("Cloning %s with branch %s" % (repo, branch))
|
||||||
|
path = tempfile.mkdtemp(prefix="kubernetes")
|
||||||
|
try:
|
||||||
|
cmd = ["git", "clone", repo, path, "-b", branch]
|
||||||
|
run_with_logging(cmd)
|
||||||
yield path
|
yield path
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
else:
|
||||||
|
log.info("Using local repo " + repo)
|
||||||
|
yield repo
|
||||||
|
|
||||||
|
|
||||||
def add_addon(source, dest):
|
def add_addon(repo, source, dest):
|
||||||
""" Add an addon manifest from the given source.
|
""" Add an addon manifest from the given repo and source.
|
||||||
|
|
||||||
Any occurrences of 'amd64' are replaced with '{{ arch }}' so the charm can
|
Any occurrences of 'amd64' are replaced with '{{ arch }}' so the charm can
|
||||||
fill it in during deployment. """
|
fill it in during deployment. """
|
||||||
|
source = os.path.join(repo, "cluster/addons", source)
|
||||||
if os.path.isdir(dest):
|
if os.path.isdir(dest):
|
||||||
dest = os.path.join(dest, os.path.basename(source))
|
dest = os.path.join(dest, os.path.basename(source))
|
||||||
log.debug("Copying: %s -> %s" % (source, dest))
|
log.debug("Copying: %s -> %s" % (source, dest))
|
||||||
@ -86,20 +101,26 @@ def update_addons(dest):
|
|||||||
with kubernetes_repo() as repo:
|
with kubernetes_repo() as repo:
|
||||||
log.info("Copying addons to charm")
|
log.info("Copying addons to charm")
|
||||||
clean_addon_dir(dest)
|
clean_addon_dir(dest)
|
||||||
add_addon(repo + "/cluster/addons/dashboard/dashboard-controller.yaml",
|
add_addon(repo, "dashboard/dashboard-controller.yaml", dest)
|
||||||
dest)
|
add_addon(repo, "dashboard/dashboard-service.yaml", dest)
|
||||||
add_addon(repo + "/cluster/addons/dashboard/dashboard-service.yaml",
|
try:
|
||||||
dest)
|
add_addon(repo, "dns/kubedns-controller.yaml.in",
|
||||||
add_addon(repo + "/cluster/addons/dns/kubedns-controller.yaml.in",
|
|
||||||
dest + "/kubedns-controller.yaml")
|
dest + "/kubedns-controller.yaml")
|
||||||
add_addon(repo + "/cluster/addons/dns/kubedns-svc.yaml.in",
|
add_addon(repo, "dns/kubedns-svc.yaml.in",
|
||||||
dest + "/kubedns-svc.yaml")
|
dest + "/kubedns-svc.yaml")
|
||||||
influxdb = "/cluster/addons/cluster-monitoring/influxdb"
|
except IOError as e:
|
||||||
add_addon(repo + influxdb + "/grafana-service.yaml", dest)
|
# fall back to the older filenames
|
||||||
add_addon(repo + influxdb + "/heapster-controller.yaml", dest)
|
log.debug(e)
|
||||||
add_addon(repo + influxdb + "/heapster-service.yaml", dest)
|
add_addon(repo, "dns/skydns-rc.yaml.in",
|
||||||
add_addon(repo + influxdb + "/influxdb-grafana-controller.yaml", dest)
|
dest + "/kubedns-controller.yaml")
|
||||||
add_addon(repo + influxdb + "/influxdb-service.yaml", dest)
|
add_addon(repo, "dns/skydns-svc.yaml.in",
|
||||||
|
dest + "/kubedns-svc.yaml")
|
||||||
|
influxdb = "cluster-monitoring/influxdb"
|
||||||
|
add_addon(repo, influxdb + "/grafana-service.yaml", dest)
|
||||||
|
add_addon(repo, influxdb + "/heapster-controller.yaml", dest)
|
||||||
|
add_addon(repo, influxdb + "/heapster-service.yaml", dest)
|
||||||
|
add_addon(repo, influxdb + "/influxdb-grafana-controller.yaml", dest)
|
||||||
|
add_addon(repo, influxdb + "/influxdb-service.yaml", dest)
|
||||||
|
|
||||||
# Entry points
|
# Entry points
|
||||||
|
|
||||||
@ -151,8 +172,8 @@ def parse_args():
|
|||||||
def main():
|
def main():
|
||||||
""" Update addons into the layer's templates/addons folder """
|
""" Update addons into the layer's templates/addons folder """
|
||||||
parse_args()
|
parse_args()
|
||||||
dest = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
"../templates/addons"))
|
dest = "templates/addons"
|
||||||
update_addons(dest)
|
update_addons(dest)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user