k8s: refactor functions into KubernetesDriver

We currently have a lot of duplicate functions across our drivers
which use Kubernetes.  This takes them and brings them into a
common class called KubernetesDriver and cleans up the subclasses.

Change-Id: I6f880cb03ed43ec3bc9d3d9e5a7b87eaceda40e9
This commit is contained in:
Mohammed Naser 2019-06-20 15:43:03 -04:00
parent 85bd42474b
commit b5d50ddd89
4 changed files with 31 additions and 51 deletions

View File

@ -27,11 +27,14 @@ from heatclient import exc as heatexc
from magnum.common import clients
from magnum.common import context as mag_ctx
from magnum.common import exception
from magnum.common import keystone
from magnum.common import octavia
from magnum.common import short_id
from magnum.conductor.handlers.common import cert_manager
from magnum.conductor.handlers.common import trust_manager
from magnum.conductor import utils as conductor_utils
from magnum.drivers.common import driver
from magnum.drivers.common import k8s_monitor
from magnum.i18n import _
from magnum.objects import fields
@ -238,6 +241,31 @@ class HeatDriver(driver.Driver):
osc.heat().stacks.delete(cluster.stack_id)
class KubernetesDriver(HeatDriver):
"""Base driver for Kubernetes clusters."""
def get_monitor(self, context, cluster):
return k8s_monitor.K8sMonitor(context, cluster)
def get_scale_manager(self, context, osclient, cluster):
# FIXME: Until the kubernetes client is fixed, remove
# the scale_manager.
# https://bugs.launchpad.net/magnum/+bug/1746510
return None
def pre_delete_cluster(self, context, cluster):
"""Delete cloud resources before deleting the cluster."""
if keystone.is_octavia_enabled():
LOG.info("Starting to delete loadbalancers for cluster %s",
cluster.uuid)
octavia.delete_loadbalancers(context, cluster)
def upgrade_cluster(self, context, cluster, cluster_template,
max_batch_size, nodegroup, scale_manager=None,
rollback=False):
raise NotImplementedError("Must implement 'upgrade_cluster'")
class HeatPoller(object):
def __init__(self, openstack_client, context, cluster, cluster_driver):

View File

@ -12,12 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from magnum.drivers.common import k8s_monitor
from magnum.drivers.heat import driver
from magnum.drivers.k8s_coreos_v1 import template_def
class Driver(driver.HeatDriver):
class Driver(driver.KubernetesDriver):
@property
def provides(self):
@ -29,17 +28,3 @@ class Driver(driver.HeatDriver):
def get_template_definition(self):
return template_def.CoreOSK8sTemplateDefinition()
def get_monitor(self, context, cluster):
return k8s_monitor.K8sMonitor(context, cluster)
def get_scale_manager(self, context, osclient, cluster):
# FIXME: Until the kubernetes client is fixed, remove
# the scale_manager.
# https://bugs.launchpad.net/magnum/+bug/1746510
return None
def upgrade_cluster(self, context, cluster, cluster_template,
max_batch_size, nodegroup, scale_manager=None,
rollback=False):
raise NotImplementedError("Must implement 'upgrade_cluster'")

View File

@ -17,16 +17,13 @@ from pbr.version import SemanticVersion as SV
from magnum.common import clients
from magnum.common import exception
from magnum.common import keystone
from magnum.common import octavia
from magnum.drivers.common import k8s_monitor
from magnum.drivers.heat import driver
from magnum.drivers.k8s_fedora_atomic_v1 import template_def
LOG = logging.getLogger(__name__)
class Driver(driver.HeatDriver):
class Driver(driver.KubernetesDriver):
@property
def provides(self):
@ -39,22 +36,6 @@ class Driver(driver.HeatDriver):
def get_template_definition(self):
return template_def.AtomicK8sTemplateDefinition()
def get_monitor(self, context, cluster):
return k8s_monitor.K8sMonitor(context, cluster)
def get_scale_manager(self, context, osclient, cluster):
# FIXME: Until the kubernetes client is fixed, remove
# the scale_manager.
# https://bugs.launchpad.net/magnum/+bug/1746510
return None
def pre_delete_cluster(self, context, cluster):
"""Delete cloud resources before deleting the cluster."""
if keystone.is_octavia_enabled():
LOG.info("Starting to delete loadbalancers for cluster %s",
cluster.uuid)
octavia.delete_loadbalancers(context, cluster)
def upgrade_cluster(self, context, cluster, cluster_template,
max_batch_size, nodegroup, scale_manager=None,
rollback=False):

View File

@ -12,12 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from magnum.drivers.common import k8s_monitor
from magnum.drivers.heat import driver
from magnum.drivers.k8s_fedora_ironic_v1 import template_def
class Driver(driver.HeatDriver):
class Driver(driver.KubernetesDriver):
@property
def provides(self):
@ -29,16 +28,3 @@ class Driver(driver.HeatDriver):
def get_template_definition(self):
return template_def.FedoraK8sIronicTemplateDefinition()
def get_monitor(self, context, cluster):
return k8s_monitor.K8sMonitor(context, cluster)
def get_scale_manager(self, context, osclient, cluster):
# FIXME: Until the kubernetes client is fixed, remove
# the scale_manager.
# https://bugs.launchpad.net/magnum/+bug/1746510
return None
def upgrade_cluster(self, context, cluster, scale_manager=None,
rollback=False):
raise NotImplementedError("Must implement 'upgrade_cluster'")