From 61deb07aac4f31a6ff5febad727208560419e75f Mon Sep 17 00:00:00 2001 From: Ekaterina Chernova Date: Tue, 18 Sep 2018 18:11:48 +0300 Subject: [PATCH 1/2] Provide correct python when runs ansible --- kqueen/engines/openstack_kubespray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kqueen/engines/openstack_kubespray.py b/kqueen/engines/openstack_kubespray.py index 614b70f7..875c0c0e 100644 --- a/kqueen/engines/openstack_kubespray.py +++ b/kqueen/engines/openstack_kubespray.py @@ -565,7 +565,7 @@ def _get_cluster_path(self, *args): def _wait_for_ping(self, retries=15, sleep=10): args = [config.KS_ANSIBLE_CMD, "-m", - "ping", "all", "-i", "hosts.json"] + "ping", "all", "-i", "hosts.json", "-e", "ansible_python_interpreter=/usr/bin/python3"] while retries: retries -= 1 time.sleep(sleep) From c5dbf590c4ee4da781df98175bafabc7309a09a7 Mon Sep 17 00:00:00 2001 From: Ekaterina Chernova Date: Tue, 18 Sep 2018 18:16:03 +0300 Subject: [PATCH 2/2] Fix creating kubernetes client for OS-provisioner * Also add some improvements to deprovision * Move docker bip setting to config (redefine it only at Mirantis demo config) --- kqueen/config/demo_mirantis.py | 1 + kqueen/engines/openstack_kubespray.py | 37 ++++++++++++++++----------- kqueen/kubeapi.py | 4 ++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/kqueen/config/demo_mirantis.py b/kqueen/config/demo_mirantis.py index c5be7967..f9a1f956 100644 --- a/kqueen/config/demo_mirantis.py +++ b/kqueen/config/demo_mirantis.py @@ -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" diff --git a/kqueen/engines/openstack_kubespray.py b/kqueen/engines/openstack_kubespray.py index 875c0c0e..b4955ad0 100644 --- a/kqueen/engines/openstack_kubespray.py +++ b/kqueen/engines/openstack_kubespray.py @@ -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, @@ -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: @@ -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: @@ -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) @@ -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"]) @@ -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: @@ -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, @@ -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 diff --git a/kqueen/kubeapi.py b/kqueen/kubeapi.py index 8bb4f22f..a9c6fc21 100644 --- a/kqueen/kubeapi.py +++ b/kqueen/kubeapi.py @@ -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):