From e013541573641f78bfaf7d316774561e6f7c75ff Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 11:08:09 -0500 Subject: [PATCH 1/7] Changing the util.sh to build kubernetes binaries locally. --- cluster/juju/util.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cluster/juju/util.sh b/cluster/juju/util.sh index 009dcd0c8b0..f253abd0c8c 100755 --- a/cluster/juju/util.sh +++ b/cluster/juju/util.sh @@ -30,11 +30,21 @@ function verify-prereqs() { gather_installation_reqs } +function build-local() { + # Build the binaries locally that are used in the charms. + make all WHAT="cmd/kube-apiserver cmd/kubectl cmd/kube-controller-manager plugin/cmd/kube-scheduler cmd/kubelet cmd/kube-proxy" + OUTPUT_DIR=_output/local/bin/linux/amd64 + mkdir -p cluster/juju/charms/trusty/kubernetes-master/files/output + # Copy the binary output to the charm directory. + cp -v $OUTPUT_DIR/* cluster/juju/charms/trusty/kubernetes-master/files/output +} + function get-password() { echo "TODO: Assign username/password security" } function kube-up() { + build-local if [[ -d "~/.juju/current-env" ]]; then juju quickstart -i --no-browser else From 08733d9362cd6add45834006f4d95838c03290a4 Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 11:16:14 -0500 Subject: [PATCH 2/7] Adding the 'local' option to install binaries from local filesystem. --- .../trusty/kubernetes-master/hooks/hooks.py | 82 +++++++++++-------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py index 1acbae98355..f68c1bfc665 100755 --- a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py +++ b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py @@ -59,46 +59,60 @@ def config_changed(): config = hookenv.config() # Get the version of kubernetes to install. version = config['version'] - # Get the package architecture, rather than the from the kernel (uname -m). - arch = subprocess.check_output(['dpkg', '--print-architecture']).strip() - kubernetes_dir = path('/opt/kubernetes') - if not kubernetes_dir.exists(): - print('The source directory {0} does not exist'.format(kubernetes_dir)) - print('Was the kubernetes code cloned during install?') - exit(1) - if version in ['source', 'head', 'master']: + if version == 'master': + # The 'master' branch of kuberentes is used when master is configured. branch = 'master' + elif version == 'local': + # Check for kubernetes binaries in the local files/output directory. + branch = None else: - # Create a branch to a tag. + # Create a branch to a tag to get the release version. branch = 'tags/{0}'.format(version) - # Construct the path to the binaries using the arch. - output_path = kubernetes_dir / '_output/local/bin/linux' / arch - installer = KubernetesInstaller(arch, version, output_path) + # Get the package architecture, rather than the from the kernel (uname -m). + arch = subprocess.check_output(['dpkg', '--print-architecture']).strip() - # Change to the kubernetes directory (git repository). - with kubernetes_dir: - # Create a command to get the current branch. - git_branch = 'git branch | grep "\*" | cut -d" " -f2' - current_branch = subprocess.check_output(git_branch, shell=True).strip() - print('Current branch: ', current_branch) - # Create the path to a file to indicate if the build was broken. - broken_build = charm_dir / '.broken_build' - # write out the .broken_build file while this block is executing. - with check_sentinel(broken_build) as last_build_failed: - print('Last build failed: ', last_build_failed) - # Rebuild if the current version is different or last build failed. - if current_branch != version or last_build_failed: - installer.build(branch) - if not output_path.exists(): - broken_build.touch() - else: - print('Notifying minions of verison ' + version) - # Notify the minions of a version change. - for r in hookenv.relation_ids('minions-api'): - hookenv.relation_set(r, version=version) - print('Done notifing minions of version ' + version) + if not branch: + output_path = charm_dir / 'files/output' + installer = KubernetesInstaller(arch, version, output_path) + else: + + # Build the kuberentes binaries from source on the units. + kubernetes_dir = path('/opt/kubernetes') + + # Construct the path to the binaries using the arch. + output_path = kubernetes_dir / '_output/local/bin/linux' / arch + installer = KubernetesInstaller(arch, version, output_path) + + if not kubernetes_dir.exists(): + print('The source directory {0} does not exist'.format(kubernetes_dir)) + print('Was the kubernetes code cloned during install?') + exit(1) + + # Change to the kubernetes directory (git repository). + with kubernetes_dir: + + # Create a command to get the current branch. + git_branch = 'git branch | grep "\*" | cut -d" " -f2' + current_branch = subprocess.check_output(git_branch, shell=True).strip() + print('Current branch: ', current_branch) + # Create the path to a file to indicate if the build was broken. + broken_build = charm_dir / '.broken_build' + # write out the .broken_build file while this block is executing. + with check_sentinel(broken_build) as last_build_failed: + print('Last build failed: ', last_build_failed) + # Rebuild if the current version is different or last build failed. + if current_branch != version or last_build_failed: + installer.build(branch) + if not output_path.exists(): + broken_build.touch() + else: + print('Notifying minions of verison ' + version) + # Notify the minions of a version change. + for r in hookenv.relation_ids('minions-api'): + hookenv.relation_set(r, version=version) + print('Done notifing minions of version ' + version) # Create the symoblic links to the right directories. installer.install() From b112606f54d9679298fca907568d74da595241c8 Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 13:36:53 -0500 Subject: [PATCH 3/7] Setting the alias variable on the template data. --- .../charms/trusty/kubernetes-master/hooks/hooks.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py index f68c1bfc665..fee63a5e39e 100755 --- a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py +++ b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py @@ -70,7 +70,7 @@ def config_changed(): # Create a branch to a tag to get the release version. branch = 'tags/{0}'.format(version) - # Get the package architecture, rather than the from the kernel (uname -m). + # Get the package architecture, rather than arch from the kernel (uname -m). arch = subprocess.check_output(['dpkg', '--print-architecture']).strip() if not branch: @@ -155,6 +155,7 @@ def relation_changed(): # Send api endpoint to minions notify_minions() + @hooks.hook('network-relation-changed') def network_relation_changed(): relation_id = hookenv.relation_id() @@ -175,6 +176,7 @@ def notify_minions(): def get_template_data(): rels = hookenv.relations() config = hookenv.config() + version = config['version'] template_data = {} template_data['etcd_servers'] = ",".join([ "http://%s:%s" % (s[0], s[1]) for s in sorted( @@ -186,8 +188,14 @@ def get_template_data(): template_data['api_server_address'] = "http://%s:%s" % ( hookenv.unit_private_ip(), 8080) arch = subprocess.check_output(['dpkg', '--print-architecture']).strip() - template_data['web_uri'] = "/kubernetes/%s/local/bin/linux/%s/" % ( - config['version'], arch) + + template_data['web_uri'] = "/kubernetes/%s/local/bin/linux/%s/" % (version, + arch) + if version == 'local': + template_data['alias'] = hookenv.charm_dir() + '/files/output/' + else: + directory = '/opt/kubernetes/_output/local/bin/linux/%s/' % arch + template_data['alias'] = directory _encode(template_data) return template_data From d344eb6cf0835b86294cf1b8a31f51e62bd0013b Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 13:39:11 -0500 Subject: [PATCH 4/7] Making the alias a variable to be replaced by the code. --- .../trusty/kubernetes-master/files/distribution.conf.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cluster/juju/charms/trusty/kubernetes-master/files/distribution.conf.tmpl b/cluster/juju/charms/trusty/kubernetes-master/files/distribution.conf.tmpl index 68e26ce2ab8..5a279cab874 100644 --- a/cluster/juju/charms/trusty/kubernetes-master/files/distribution.conf.tmpl +++ b/cluster/juju/charms/trusty/kubernetes-master/files/distribution.conf.tmpl @@ -1,6 +1,6 @@ server { listen %(api_bind_address)s:80; location %(web_uri)s { - alias /opt/kubernetes/_output/local/bin/linux/amd64/; + alias %(alias)s; } } From a464d624e6d594cf146c7499c43dffd62d643222 Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 13:40:25 -0500 Subject: [PATCH 5/7] Chaning the bundle to use the new config value. --- cluster/juju/bundles/local.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cluster/juju/bundles/local.yaml b/cluster/juju/bundles/local.yaml index 71022fe9f90..6b1e8bf2b49 100644 --- a/cluster/juju/bundles/local.yaml +++ b/cluster/juju/bundles/local.yaml @@ -7,7 +7,7 @@ kubernetes-local: "gui-y": "0" expose: true options: - version: "v0.15.0" + version: "local" docker: charm: cs:trusty/docker num_units: 2 From f261702ef6e2eb63d3c6aa5e43bd4c83e8e24b77 Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 16:58:55 -0500 Subject: [PATCH 6/7] Adding kube-down logic to utils.sh to clean up. --- cluster/juju/util.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cluster/juju/util.sh b/cluster/juju/util.sh index f253abd0c8c..3e11583ba01 100755 --- a/cluster/juju/util.sh +++ b/cluster/juju/util.sh @@ -60,6 +60,8 @@ function kube-up() { } function kube-down() { + # Remove the binary files from the charm directory. + rm -rf cluster/juju/charms/trusty/kubernetes-master/files/output/ local jujuenv jujuenv=$(cat ~/.juju/current-environment) juju destroy-environment $jujuenv From 774f7e37380b02c93cf2e0eafe52d59faba22892 Mon Sep 17 00:00:00 2001 From: Matt Bruzek Date: Thu, 28 May 2015 17:04:15 -0500 Subject: [PATCH 7/7] Changed a comment for flake8 reasons. --- .../charms/trusty/kubernetes-master/hooks/hooks.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py index fee63a5e39e..838420dccc9 100755 --- a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py +++ b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py @@ -102,17 +102,11 @@ def config_changed(): # write out the .broken_build file while this block is executing. with check_sentinel(broken_build) as last_build_failed: print('Last build failed: ', last_build_failed) - # Rebuild if the current version is different or last build failed. + # Rebuild if current version is different or last build failed. if current_branch != version or last_build_failed: installer.build(branch) - if not output_path.exists(): + if not output_path.isdir(): broken_build.touch() - else: - print('Notifying minions of verison ' + version) - # Notify the minions of a version change. - for r in hookenv.relation_ids('minions-api'): - hookenv.relation_set(r, version=version) - print('Done notifing minions of version ' + version) # Create the symoblic links to the right directories. installer.install() @@ -171,6 +165,7 @@ def notify_minions(): hostname=hookenv.unit_private_ip(), port=8080, version=config['version']) + print("Notified minions of version " + config['version']) def get_template_data():