Skip to content

Commit

Permalink
Fix creating kubernetes client for OS-provisioner
Browse files Browse the repository at this point in the history
* Also add some improvements to deprovision
* Move docker bip setting to config (redefine it only at Mirantis demo config)
  • Loading branch information
Ekaterina Chernova committed Sep 24, 2018
1 parent 61deb07 commit c5dbf59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions kqueen/config/demo_mirantis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ class Config(BaseConfig):
KS_NO_PROXY = "127.0.0.1,localhost,docker-prod-local.docker.mirantis.net,172.16.48.254," \
"cloud-cz.bud.mirantis.net,172.17.45.80"
KS_OS_BLOCKSTORAGE_VERSION = "v2"
KS_DOCKER_BIP = "10.13.0.1/16"
37 changes: 22 additions & 15 deletions kqueen/engines/openstack_kubespray.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class OpenstackKubesprayEngine(BaseEngine):
"type": "text",
"order": 70,
"label": "Docker0 bridge IP",
"default": "10.13.0.1/16",
"default": config.KS_DOCKER_BIP if config.get("KS_DOCKER_BIP") else None,
"help_message": "network IP and netmask in CIDR format",
"validators": {
"cidr": True,
Expand Down Expand Up @@ -662,11 +662,8 @@ def validate_ip(address):
raise ValueError("Master node count must be an odd number")
self.meta["master_count"] = mc
self.meta["slave_count"] = self.cluster.metadata["slave_count"]
self.meta["docker_bip_network"] = self.cluster.metadata.get("docker_bip_network", "10.13.0.1/16")

self.meta["dns"] = [validate_ip(ip) for ip in
self.cluster.metadata.get("dns_nameservers", []).split(",")]

try:
self.meta["image"] = self.c.get_image(self.cluster.metadata["image_name"])
if self.meta["image"] is None:
Expand Down Expand Up @@ -756,6 +753,10 @@ def deprovision(self, volume_names):
self.c.remove_router_interface(router, port_id=i.id)
time.sleep(2)
self.c.delete_router(router.id)
logger.debug("Router {0} has been deleted".format(self.stack_name))
if "resources" not in self.cluster.metadata:
# Deployment failed before instance spawning
return
server_ids = [server["id"] for server in (*self.cluster.metadata["resources"]["masters"],
*self.cluster.metadata["resources"]["slaves"])]
for server_id in server_ids:
Expand All @@ -781,7 +782,6 @@ def deprovision(self, volume_names):
# Catch error that is raised for an object that is being deleting
pass

self.c.delete_network(self.stack_name)
for fip in floating_ips:
logger.info("Disassociating floating ip %s" % fip)
self.c.delete_floating_ip(fip)
Expand All @@ -791,6 +791,12 @@ def deprovision(self, volume_names):
if pvc_name in volume_names:
logger.info("Deleting volume %s" % v.id)
self.c.delete_volume(v.id, wait=False)
for attempt in range(3):
try:
self.c.delete_network(self.stack_name)
except Exception as e:
if attempt == 2:
raise e

def grow(self, *, resources, new_slave_count):
current_slave_count = len(resources["slaves"])
Expand All @@ -800,7 +806,7 @@ def grow(self, *, resources, new_slave_count):
servers_range=servers_range,
image=self.cluster.metadata["image_name"],
flavor=self.cluster.metadata["slave_flavor"],
network=self.c.get_network(resources["network_id"]),
network=resources["network_id"],
add_random_suffix=True,
)
for slave in new_slaves:
Expand All @@ -822,19 +828,20 @@ def shrink(self, *, resources, remove_hostnames):
return resources

def _get_userdata(self):
docker_bip = {"bip": self.meta["docker_bip_network"]}
userdata = {
"manage_etc_hosts": True,
"package_update": True,
"packages": ["python"],
"ssh_authorized_keys": [self.extra_ssh_key],
"write_files": [
{
"content": json.dumps(docker_bip),
"path": "/etc/docker/daemon.json",
},
],
"ssh_authorized_keys": [self.extra_ssh_key]
}
bip = self.cluster.metadata.get("docker_bip_network")
if bip:
docker_bip = {"bip": bip}
userdata["write_files"] = [
{"content": json.dumps(docker_bip),
"path": "/etc/docker/daemon.json",
}
]
return "#cloud-config\n" + yaml.dump(userdata)

def _boot_servers(self, *, name, servers_range, image, flavor, network,
Expand All @@ -851,7 +858,7 @@ def _boot_servers(self, *, name, servers_range, image, flavor, network,
userdata=self._get_userdata(),
network=network,
availability_zone=self.os_kwargs.get("availability_zone", "nova"),
key_name=self.cluster.metadata["ssh_key_name"],
key_name=self.cluster.metadata["ssh_key_name"]
)
server_ids.append(server.id)
retries = 50
Expand Down
4 changes: 3 additions & 1 deletion kqueen/kubeapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ def get_api_client(self):
kcl = KubeConfigLoader(
config_dict=kubeconfig,
)
kcl.load_and_set(client_config)

kcl.load_and_set(client_config)
if self.cluster.provisioner.engine == 'kqueen.engines.OpenstackKubesprayEngine':
client_config.assert_hostname = False
return client.ApiClient(configuration=client_config)

def get_version(self):
Expand Down

0 comments on commit c5dbf59

Please sign in to comment.