Commit ca4afd87 authored by Rye Terrell's avatar Rye Terrell Committed by George Kraft

Update CDK charms to use snaps

parent 5d9905f4
...@@ -28,6 +28,9 @@ import os ...@@ -28,6 +28,9 @@ import os
import sys import sys
os.environ['PATH'] += os.pathsep + os.path.join(os.sep, 'snap', 'bin')
def main(): def main():
''' Control logic to enlist Ceph RBD volumes as PersistentVolumes in ''' Control logic to enlist Ceph RBD volumes as PersistentVolumes in
Kubernetes. This will invoke the validation steps, and only execute if Kubernetes. This will invoke the validation steps, and only execute if
......
...@@ -21,3 +21,8 @@ options: ...@@ -21,3 +21,8 @@ options:
privileged mode. If "auto", kube-apiserver will not run in privileged privileged mode. If "auto", kube-apiserver will not run in privileged
mode by default, but will switch to privileged mode if gpu hardware is mode by default, but will switch to privileged mode if gpu hardware is
detected on a worker node. detected on a worker node.
channel:
type: string
default: "stable"
description: |
Snap channel to install Kubernetes master services from
#!/bin/sh #!/bin/sh
set -ux set -ux
export PATH=$PATH:/snap/bin
alias kubectl="kubectl --kubeconfig=/home/ubuntu/config" alias kubectl="kubectl --kubeconfig=/home/ubuntu/config"
kubectl cluster-info > $DEBUG_SCRIPT_DIR/cluster-info kubectl cluster-info > $DEBUG_SCRIPT_DIR/cluster-info
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
set -ux set -ux
for service in kube-apiserver kube-controller-manager kube-scheduler; do for service in kube-apiserver kube-controller-manager kube-scheduler; do
systemctl status $service > $DEBUG_SCRIPT_DIR/$service-systemctl-status systemctl status snap.$service.daemon > $DEBUG_SCRIPT_DIR/$service-systemctl-status
journalctl -u $service > $DEBUG_SCRIPT_DIR/$service-journal journalctl -u snap.$service.daemon > $DEBUG_SCRIPT_DIR/$service-journal
done done
mkdir -p $DEBUG_SCRIPT_DIR/etc-default # FIXME: grab snap config or something
cp -v /etc/default/kube* $DEBUG_SCRIPT_DIR/etc-default
mkdir -p $DEBUG_SCRIPT_DIR/lib-systemd-system
cp -v /lib/systemd/system/kube* $DEBUG_SCRIPT_DIR/lib-systemd-system
repo: https://github.com/kubernetes/kubernetes.git repo: https://github.com/kubernetes/kubernetes.git
includes: includes:
- 'layer:basic' - 'layer:basic'
- 'layer:debug' - 'layer:snap'
- 'layer:tls-client'
- 'layer:leadership' - 'layer:leadership'
- 'layer:debug'
- 'layer:metrics' - 'layer:metrics'
- 'layer:nagios' - 'layer:nagios'
- 'layer:tls-client'
- 'interface:ceph-admin' - 'interface:ceph-admin'
- 'interface:etcd' - 'interface:etcd'
- 'interface:http' - 'interface:http'
...@@ -18,10 +19,8 @@ options: ...@@ -18,10 +19,8 @@ options:
packages: packages:
- socat - socat
tls-client: tls-client:
ca_certificate_path: '/srv/kubernetes/ca.crt' ca_certificate_path: '/root/cdk/ca.crt'
server_certificate_path: '/srv/kubernetes/server.crt' server_certificate_path: '/root/cdk/server.crt'
server_key_path: '/srv/kubernetes/server.key' server_key_path: '/root/cdk/server.key'
client_certificate_path: '/srv/kubernetes/client.crt' client_certificate_path: '/root/cdk/client.crt'
client_key_path: '/srv/kubernetes/client.key' client_key_path: '/root/cdk/client.key'
tactics:
- 'tactics.update_addons.UpdateAddonsTactic'
...@@ -17,10 +17,6 @@ ...@@ -17,10 +17,6 @@
import re import re
import subprocess import subprocess
from charmhelpers.core import unitdata
BIN_VERSIONS = 'bin_versions'
def get_version(bin_name): def get_version(bin_name):
"""Get the version of an installed Kubernetes binary. """Get the version of an installed Kubernetes binary.
...@@ -34,31 +30,6 @@ def get_version(bin_name): ...@@ -34,31 +30,6 @@ def get_version(bin_name):
(1, 6, 0) (1, 6, 0)
""" """
db = unitdata.kv()
bin_versions = db.get(BIN_VERSIONS, {})
cached_version = bin_versions.get(bin_name)
if cached_version:
return tuple(cached_version)
version = _get_bin_version(bin_name)
bin_versions[bin_name] = list(version)
db.set(BIN_VERSIONS, bin_versions)
return version
def reset_versions():
"""Reset the cache of bin versions.
"""
db = unitdata.kv()
db.unset(BIN_VERSIONS)
def _get_bin_version(bin_name):
"""Get a binary version by calling it with --version and parsing output.
"""
cmd = '{} --version'.format(bin_name).split() cmd = '{} --version'.format(bin_name).split()
version_string = subprocess.check_output(cmd).decode('utf-8') version_string = subprocess.check_output(cmd).decode('utf-8')
return tuple(int(q) for q in re.findall("[0-9]+", version_string)[:3]) return tuple(int(q) for q in re.findall("[0-9]+", version_string)[:3])
...@@ -118,6 +118,13 @@ class FlagManager: ...@@ -118,6 +118,13 @@ class FlagManager:
""" """
return self.data.get(key, default) return self.data.get(key, default)
def destroy_all(self):
'''
Destructively removes all data from the FlagManager.
'''
self.data.clear()
self.__save()
def to_s(self): def to_s(self):
''' '''
Render the flags to a single string, prepared for the Docker Render the flags to a single string, prepared for the Docker
......
...@@ -37,7 +37,23 @@ requires: ...@@ -37,7 +37,23 @@ requires:
ceph-storage: ceph-storage:
interface: ceph-admin interface: ceph-admin
resources: resources:
kubernetes: kubectl:
type: file type: file
filename: kubernetes.tar.gz filename: kubectl.snap
description: "A tarball packaged release of the kubernetes bins." description: kubectl snap
kube-apiserver:
type: file
filename: kube-apiserver.snap
description: kube-apiserver snap
kube-controller-manager:
type: file
filename: kube-controller-manager.snap
description: kube-controller-manager snap
kube-scheduler:
type: file
filename: kube-scheduler.snap
description: kube-scheduler snap
cdk-addons:
type: file
filename: cdk-addons.snap
description: CDK addons snap
...@@ -3,32 +3,32 @@ metrics: ...@@ -3,32 +3,32 @@ metrics:
pods: pods:
type: gauge type: gauge
description: number of pods description: number of pods
command: kubectl get po --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get po --all-namespaces | tail -n+2 | wc -l
services: services:
type: gauge type: gauge
description: number of services description: number of services
command: kubectl get svc --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get svc --all-namespaces | tail -n+2 | wc -l
replicasets: replicasets:
type: gauge type: gauge
description: number of replicasets description: number of replicasets
command: kubectl get rs --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get rs --all-namespaces | tail -n+2 | wc -l
replicationcontrollers: replicationcontrollers:
type: gauge type: gauge
description: number of replicationcontrollers description: number of replicationcontrollers
command: kubectl get rc --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get rc --all-namespaces | tail -n+2 | wc -l
nodes: nodes:
type: gauge type: gauge
description: number of kubernetes nodes description: number of kubernetes nodes
command: kubectl get nodes | tail -n+2 | wc -l command: /snap/bin/kubectl get nodes | tail -n+2 | wc -l
persistentvolume: persistentvolume:
type: gauge type: gauge
description: number of pv description: number of pv
command: kubectl get pv --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get pv --all-namespaces | tail -n+2 | wc -l
persistentvolumeclaims: persistentvolumeclaims:
type: gauge type: gauge
description: number of claims description: number of claims
command: kubectl get pvc --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get pvc --all-namespaces | tail -n+2 | wc -l
serviceaccounts: serviceaccounts:
type: gauge type: gauge
description: number of sa description: number of sa
command: kubectl get sa --all-namespaces | tail -n+2 | wc -l command: /snap/bin/kubectl get sa --all-namespaces | tail -n+2 | wc -l
#!/usr/bin/env python
# Copyright 2015 The Kubernetes Authors.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#!/usr/bin/env python
# Copyright 2015 The Kubernetes Authors.
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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 argparse
import os
import shutil
import subprocess
import tempfile
import logging
from contextlib import contextmanager
import charmtools.utils
from charmtools.build.tactics import Tactic
description = """
Update addon manifests for the charm.
This will clone the kubernetes repo and place the addons in
<charm>/templates/addons.
Can be run with no arguments and from any folder.
"""
log = logging.getLogger(__name__)
def clean_addon_dir(addon_dir):
""" Remove and recreate the addons folder """
log.debug("Cleaning " + addon_dir)
shutil.rmtree(addon_dir, ignore_errors=True)
os.makedirs(addon_dir)
def run_with_logging(command):
""" Run a command with controlled logging """
log.debug("Running: %s" % command)
process = subprocess.Popen(command, stderr=subprocess.PIPE)
stderr = process.communicate()[1].rstrip()
process.wait()
if process.returncode != 0:
log.error(stderr)
raise Exception("%s: exit code %d" % (command, process.returncode))
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
finally:
shutil.rmtree(path)
else:
log.info("Using local repo " + repo)
yield repo
def add_addon(repo, source, dest):
""" Add an addon manifest from the given repo and source.
Any occurrences of 'amd64' are replaced with '{{ arch }}' so the charm can
fill it in during deployment. """
source = os.path.join(repo, "cluster/addons", source)
if os.path.isdir(dest):
dest = os.path.join(dest, os.path.basename(source))
log.debug("Copying: %s -> %s" % (source, dest))
with open(source, "r") as f:
content = f.read()
content = content.replace("amd64", "{{ arch }}")
with open(dest, "w") as f:
f.write(content)
def update_addons(dest):
""" Update addons. This will clean the addons folder and add new manifests
from upstream. """
with kubernetes_repo() as repo:
log.info("Copying addons to charm")
clean_addon_dir(dest)
add_addon(repo, "dashboard/dashboard-controller.yaml", dest)
add_addon(repo, "dashboard/dashboard-service.yaml", dest)
try:
add_addon(repo, "dns/kubedns-sa.yaml",
dest + "/kubedns-sa.yaml")
add_addon(repo, "dns/kubedns-cm.yaml",
dest + "/kubedns-cm.yaml")
add_addon(repo, "dns/kubedns-controller.yaml.in",
dest + "/kubedns-controller.yaml")
add_addon(repo, "dns/kubedns-svc.yaml.in",
dest + "/kubedns-svc.yaml")
except IOError as e:
# fall back to the older filenames
log.debug(e)
add_addon(repo, "dns/skydns-rc.yaml.in",
dest + "/kubedns-controller.yaml")
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
class UpdateAddonsTactic(Tactic):
""" This tactic is used by charm-tools to dynamically populate the
template/addons folder at `charm build` time. """
@classmethod
def trigger(cls, entity, target=None, layer=None, next_config=None):
""" Determines which files the tactic should apply to. We only want
this tactic to trigger once, so let's use the templates/ folder
"""
relpath = entity.relpath(layer.directory) if layer else entity
return relpath == "templates"
@property
def dest(self):
""" The destination we are writing to. This isn't a Tactic thing,
it's just a helper for UpdateAddonsTactic """
return self.target / "templates" / "addons"
def __call__(self):
""" When the tactic is called, update addons and put them directly in
our build destination """
update_addons(self.dest)
def sign(self):
""" Return signatures for the charm build manifest. We need to do this
because the addon template files were added dynamically """
sigs = {}
for file in os.listdir(self.dest):
path = self.dest / file
relpath = path.relpath(self.target.directory)
sigs[relpath] = (
self.current.url,
"dynamic",
charmtools.utils.sign(path)
)
return sigs
def parse_args():
""" Parse args. This is solely done for the usage output with -h """
parser = argparse.ArgumentParser(description=description)
parser.parse_args()
def main():
""" Update addons into the layer's templates/addons folder """
parse_args()
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
dest = "templates/addons"
update_addons(dest)
if __name__ == "__main__":
main()
###
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#
# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-address=127.0.0.1"
# The port on the local server to listen on.
KUBE_API_PORT="--insecure-port=8080"
# default admission control policies
KUBE_ADMISSION_CONTROL=""
# Add your own!
KUBE_API_ARGS="{{ kube_apiserver_flags }}"
[Unit]
Description=Kubernetes API Server
Documentation=http://kubernetes.io/docs/admin/kube-apiserver/
After=network.target
[Service]
EnvironmentFile=-/etc/default/kube-defaults
EnvironmentFile=-/etc/default/kube-apiserver
ExecStart=/usr/local/bin/kube-apiserver \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_API_ADDRESS \
$KUBE_API_PORT \
$KUBE_ALLOW_PRIV \
$KUBE_ADMISSION_CONTROL \
$KUBE_API_ARGS
Restart=on-failure
Type=notify
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
###
# The following values are used to configure the kubernetes controller-manager
# defaults from config and apiserver should be adequate
# Add your own!
KUBE_CONTROLLER_MANAGER_ARGS="{{ kube_controller_manager_flags }}"
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
EnvironmentFile=-/etc/default/kube-defaults
EnvironmentFile=-/etc/default/kube-controller-manager
ExecStart=/usr/local/bin/kube-controller-manager \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_MASTER \
$KUBE_CONTROLLER_MANAGER_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
###
# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
# kube-apiserver.service
# kube-controller-manager.service
# kube-scheduler.service
# kubelet.service
# kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"
# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"
# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="{{ kube_allow_priv }}"
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://127.0.0.1:8080"
###
# kubernetes scheduler config
# default config should be adequate
# Add your own!
KUBE_SCHEDULER_ARGS="{{ kube_scheduler_flags }}"
[Unit]
Description=Kubernetes Scheduler Plugin
Documentation=http://kubernetes.io/docs/admin/multiple-schedulers/
[Service]
EnvironmentFile=-/etc/default/kube-defaults
EnvironmentFile=-/etc/default/kube-scheduler
ExecStart=/usr/local/bin/kube-scheduler \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_MASTER \
$KUBE_SCHEDULER_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
...@@ -15,3 +15,5 @@ microbot: ...@@ -15,3 +15,5 @@ microbot:
type: boolean type: boolean
default: False default: False
description: Removes a microbots deployment, service, and ingress if True. description: Removes a microbots deployment, service, and ingress if True.
upgrade:
description: Upgrade the kubernetes snaps
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
import sys import sys
from charmhelpers.core.hookenv import action_get from charmhelpers.core.hookenv import action_get
...@@ -22,6 +23,7 @@ from charmhelpers.core.hookenv import unit_public_ip ...@@ -22,6 +23,7 @@ from charmhelpers.core.hookenv import unit_public_ip
from charms.templating.jinja2 import render from charms.templating.jinja2 import render
from subprocess import call from subprocess import call
os.environ['PATH'] += os.pathsep + os.path.join(os.sep, 'snap', 'bin')
context = {} context = {}
context['replicas'] = action_get('replicas') context['replicas'] = action_get('replicas')
...@@ -32,7 +34,7 @@ if not context['replicas']: ...@@ -32,7 +34,7 @@ if not context['replicas']:
context['replicas'] = 3 context['replicas'] = 3
# Declare a kubectl template when invoking kubectl # Declare a kubectl template when invoking kubectl
kubectl = ['kubectl', '--kubeconfig=/srv/kubernetes/config'] kubectl = ['kubectl', '--kubeconfig=/root/cdk/kubeconfig']
# Remove deployment if requested # Remove deployment if requested
if context['delete']: if context['delete']:
...@@ -56,11 +58,11 @@ if context['delete']: ...@@ -56,11 +58,11 @@ if context['delete']:
# Creation request # Creation request
render('microbot-example.yaml', '/etc/kubernetes/addons/microbot.yaml', render('microbot-example.yaml', '/root/cdk/addons/microbot.yaml',
context) context)
create_command = kubectl + ['create', '-f', create_command = kubectl + ['create', '-f',
'/etc/kubernetes/addons/microbot.yaml'] '/root/cdk/addons/microbot.yaml']
create_response = call(create_command) create_response = call(create_command)
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
set -ex set -ex
kubectl --kubeconfig=/srv/kubernetes/config cordon $(hostname) export PATH=$PATH:/snap/bin
kubectl --kubeconfig=/srv/kubernetes/config drain $(hostname) --force
kubectl --kubeconfig=/root/cdk/kubeconfig cordon $(hostname)
kubectl --kubeconfig=/root/cdk/kubeconfig drain $(hostname) --force
status-set 'waiting' 'Kubernetes unit paused' status-set 'waiting' 'Kubernetes unit paused'
...@@ -2,5 +2,7 @@ ...@@ -2,5 +2,7 @@
set -ex set -ex
kubectl --kubeconfig=/srv/kubernetes/config uncordon $(hostname) export PATH=$PATH:/snap/bin
kubectl --kubeconfig=/root/cdk/kubeconfig uncordon $(hostname)
status-set 'active' 'Kubernetes unit resumed' status-set 'active' 'Kubernetes unit resumed'
#!/bin/sh
set -eux
charms.reactive set_state kubernetes-worker.snaps.upgrade-specified
exec hooks/config-changed
...@@ -20,3 +20,14 @@ options: ...@@ -20,3 +20,14 @@ options:
mode by default. If "false", kubelet will never run in privileged mode. mode by default. If "false", kubelet will never run in privileged mode.
If "auto", kubelet will not run in privileged mode by default, but will If "auto", kubelet will not run in privileged mode by default, but will
switch to privileged mode if gpu hardware is detected. switch to privileged mode if gpu hardware is detected.
channel:
type: string
default: "stable"
description: |
Snap channel to install Kubernetes worker services from
require-manual-upgrade:
type: boolean
default: true
description: |
When true, worker services will not be upgraded until the user triggers
it manually by running the upgrade action.
#!/bin/sh #!/bin/sh
set -ux set -ux
alias kubectl="kubectl --kubeconfig=/srv/kubernetes/config" export PATH=$PATH:/snap/bin
alias kubectl="kubectl --kubeconfig=/root/cdk/kubeconfig"
kubectl cluster-info > $DEBUG_SCRIPT_DIR/cluster-info kubectl cluster-info > $DEBUG_SCRIPT_DIR/cluster-info
kubectl cluster-info dump > $DEBUG_SCRIPT_DIR/cluster-info-dump kubectl cluster-info dump > $DEBUG_SCRIPT_DIR/cluster-info-dump
......
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
set -ux set -ux
for service in kubelet kube-proxy; do for service in kubelet kube-proxy; do
systemctl status $service > $DEBUG_SCRIPT_DIR/$service-systemctl-status systemctl status snap.$service.daemon > $DEBUG_SCRIPT_DIR/$service-systemctl-status
journalctl -u $service > $DEBUG_SCRIPT_DIR/$service-journal journalctl -u snap.$service.daemon > $DEBUG_SCRIPT_DIR/$service-journal
done done
mkdir -p $DEBUG_SCRIPT_DIR/etc-default # FIXME: get the snap config or something
cp -v /etc/default/kube* $DEBUG_SCRIPT_DIR/etc-default
mkdir -p $DEBUG_SCRIPT_DIR/lib-systemd-system
cp -v /lib/systemd/system/kube* $DEBUG_SCRIPT_DIR/lib-systemd-system
...@@ -2,6 +2,7 @@ repo: https://github.com/kubernetes/kubernetes.git ...@@ -2,6 +2,7 @@ repo: https://github.com/kubernetes/kubernetes.git
includes: includes:
- 'layer:basic' - 'layer:basic'
- 'layer:debug' - 'layer:debug'
- 'layer:snap'
- 'layer:docker' - 'layer:docker'
- 'layer:metrics' - 'layer:metrics'
- 'layer:nagios' - 'layer:nagios'
...@@ -18,8 +19,8 @@ options: ...@@ -18,8 +19,8 @@ options:
- 'ceph-common' - 'ceph-common'
- 'socat' - 'socat'
tls-client: tls-client:
ca_certificate_path: '/srv/kubernetes/ca.crt' ca_certificate_path: '/root/cdk/ca.crt'
server_certificate_path: '/srv/kubernetes/server.crt' server_certificate_path: '/root/cdk/server.crt'
server_key_path: '/srv/kubernetes/server.key' server_key_path: '/root/cdk/server.key'
client_certificate_path: '/srv/kubernetes/client.crt' client_certificate_path: '/root/cdk/client.crt'
client_key_path: '/srv/kubernetes/client.key' client_key_path: '/root/cdk/client.key'
...@@ -17,10 +17,6 @@ ...@@ -17,10 +17,6 @@
import re import re
import subprocess import subprocess
from charmhelpers.core import unitdata
BIN_VERSIONS = 'bin_versions'
def get_version(bin_name): def get_version(bin_name):
"""Get the version of an installed Kubernetes binary. """Get the version of an installed Kubernetes binary.
...@@ -34,31 +30,6 @@ def get_version(bin_name): ...@@ -34,31 +30,6 @@ def get_version(bin_name):
(1, 6, 0) (1, 6, 0)
""" """
db = unitdata.kv()
bin_versions = db.get(BIN_VERSIONS, {})
cached_version = bin_versions.get(bin_name)
if cached_version:
return tuple(cached_version)
version = _get_bin_version(bin_name)
bin_versions[bin_name] = list(version)
db.set(BIN_VERSIONS, bin_versions)
return version
def reset_versions():
"""Reset the cache of bin versions.
"""
db = unitdata.kv()
db.unset(BIN_VERSIONS)
def _get_bin_version(bin_name):
"""Get a binary version by calling it with --version and parsing output.
"""
cmd = '{} --version'.format(bin_name).split() cmd = '{} --version'.format(bin_name).split()
version_string = subprocess.check_output(cmd).decode('utf-8') version_string = subprocess.check_output(cmd).decode('utf-8')
return tuple(int(q) for q in re.findall("[0-9]+", version_string)[:3]) return tuple(int(q) for q in re.findall("[0-9]+", version_string)[:3])
...@@ -118,6 +118,13 @@ class FlagManager: ...@@ -118,6 +118,13 @@ class FlagManager:
""" """
return self.data.get(key, default) return self.data.get(key, default)
def destroy_all(self):
'''
Destructively removes all data from the FlagManager.
'''
self.data.clear()
self.__save()
def to_s(self): def to_s(self):
''' '''
Render the flags to a single string, prepared for the Docker Render the flags to a single string, prepared for the Docker
......
...@@ -29,7 +29,19 @@ provides: ...@@ -29,7 +29,19 @@ provides:
interface: kubernetes-cni interface: kubernetes-cni
scope: container scope: container
resources: resources:
kubernetes: cni:
type: file
filename: cni.tgz
description: CNI plugins
kubectl:
type: file
filename: kubectl.snap
description: kubectl snap
kubelet:
type: file
filename: kubelet.snap
description: kubelet snap
kube-proxy:
type: file type: file
filename: kubernetes.tar.gz filename: kube-proxy.snap
description: "An archive of kubernetes binaries for the worker." description: kube-proxy snap
###
# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
# kube-apiserver.service
# kube-controller-manager.service
# kube-scheduler.service
# kubelet.service
# kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"
# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"
# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="{{ kube_allow_priv }}"
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="{{ kube_api_endpoint }}"
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=http://kubernetes.io/docs/admin/kube-proxy/
After=network.target
[Service]
EnvironmentFile=-/etc/default/kube-default
EnvironmentFile=-/etc/default/kube-proxy
ExecStart=/usr/local/bin/kube-proxy \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_MASTER \
$KUBE_PROXY_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
# kubernetes kubelet (node) config
# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=0.0.0.0"
# The port for the info server to serve on
KUBELET_PORT="--port=10250"
# You may leave this blank to use the actual hostname. If you override this
# reachability problems become your own issue.
# KUBELET_HOSTNAME="--hostname-override={{ JUJU_UNIT_NAME }}"
# Add your own!
KUBELET_ARGS="{{ kubelet_opts }}"
[Unit]
Description=Kubernetes Kubelet Server
Documentation=http://kubernetes.io/docs/admin/kubelet/
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/default/kube-default
EnvironmentFile=-/etc/default/kubelet
ExecStart=/usr/local/bin/kubelet \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBELET_ADDRESS \
$KUBELET_PORT \
$KUBELET_HOSTNAME \
$KUBE_ALLOW_PRIV \
$KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
...@@ -47,7 +47,7 @@ cluster/juju/layers/kubernetes-master/reactive/kubernetes_master.py:def send_clu ...@@ -47,7 +47,7 @@ cluster/juju/layers/kubernetes-master/reactive/kubernetes_master.py:def send_clu
cluster/juju/layers/kubernetes-master/reactive/kubernetes_master.py:def service_cidr(): cluster/juju/layers/kubernetes-master/reactive/kubernetes_master.py:def service_cidr():
cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py: context.update({'kube_api_endpoint': ','.join(api_servers), cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py: context.update({'kube_api_endpoint': ','.join(api_servers),
cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py: ca_cert_path = layer_options.get('ca_certificate_path') cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py: ca_cert_path = layer_options.get('ca_certificate_path')
cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py:def render_init_scripts(api_servers): cluster/juju/layers/kubernetes-worker/reactive/kubernetes_worker.py:def configure_worker_services(api_servers, dns):
cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$frame_no]} cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$frame_no]}
cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$stack_skip]} cluster/lib/logging.sh: local source_file=${BASH_SOURCE[$stack_skip]}
cluster/log-dump.sh: local -r node_name="${1}" cluster/log-dump.sh: local -r node_name="${1}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment