Merge "Use API apps/v1 to create deployment"

changes/00/735500/1
Zuul 3 years ago committed by Gerrit Code Review
commit 4237fe5204

@ -67,6 +67,10 @@ class KubernetesHTTPAPI(object):
k8s_client = self.get_k8s_client(auth_plugin=auth)
return client.AutoscalingV1Api(api_client=k8s_client)
def get_app_v1_api_client(self, auth):
k8s_client = self.get_k8s_client(auth_plugin=auth)
return client.AppsV1Api(api_client=k8s_client)
@staticmethod
def create_ca_cert_tmp_file(ca_cert):
file_descriptor, file_path = tempfile.mkstemp()

@ -33,10 +33,10 @@ DASH_CHARACTER = '_'
class Transformer(object):
"""Transform TOSCA template to Kubernetes resources"""
def __init__(self, core_v1_api_client, extension_api_client,
def __init__(self, core_v1_api_client, app_v1_api_client,
scaling_api_client):
self.core_v1_api_client = core_v1_api_client
self.extension_api_client = extension_api_client
self.app_v1_api_client = app_v1_api_client
self.scaling_api_client = scaling_api_client
def transform(self, tosca_kube_objects):
@ -101,7 +101,7 @@ class Transformer(object):
LOG.debug('Successfully created ConfigMap %s',
k8s_object.metadata.name)
elif object_type == 'Deployment':
self.extension_api_client.create_namespaced_deployment(
self.app_v1_api_client.create_namespaced_deployment(
namespace=namespace,
body=k8s_object)
LOG.debug('Successfully created Deployment %s',
@ -221,15 +221,15 @@ class Transformer(object):
metadata=client.V1ObjectMeta(
labels=labels, annotations=tosca_kube_obj.annotations),
spec=client.V1PodSpec(containers=containers))
# Create the specification of deployment
deployment_spec = client.ExtensionsV1beta1DeploymentSpec(
template=pod_template)
metadata = client.V1ObjectMeta(name=deployment_name)
label_selector = client.V1LabelSelector(match_labels=labels)
deployment_spec = client.V1DeploymentSpec(
template=pod_template, selector=label_selector)
metadata = client.V1ObjectMeta(name=deployment_name, labels=labels)
# Instantiate the deployment object
deployment = client.ExtensionsV1beta1Deployment(
api_version="extensions/v1beta1",
deployment = client.V1Deployment(
api_version="apps/v1",
kind="Deployment",
metadata=metadata,
spec=deployment_spec)
@ -247,7 +247,7 @@ class Transformer(object):
# Create target Deployment object
target = client.V1CrossVersionObjectReference(
api_version="extensions/v1beta1",
api_version="apps/v1",
kind="Deployment",
name=deployment_name)
# Create the specification of horizon pod auto-scaling

@ -92,14 +92,14 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
try:
core_v1_api_client = self.kubernetes.get_core_v1_api_client(
auth=auth_cred)
extension_api_client = self.kubernetes.get_extension_api_client(
app_v1_api_client = self.kubernetes.get_app_v1_api_client(
auth=auth_cred)
scaling_api_client = self.kubernetes.get_scaling_api_client(
auth=auth_cred)
tosca_to_kubernetes = translate_template.TOSCAToKubernetes(
vnf=vnf,
core_v1_api_client=core_v1_api_client,
extension_api_client=extension_api_client,
app_v1_api_client=app_v1_api_client,
scaling_api_client=scaling_api_client)
deployment_names = tosca_to_kubernetes.deploy_kubernetes_objects()
except Exception as e:
@ -272,7 +272,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
try:
core_v1_api_client = self.kubernetes.get_core_v1_api_client(
auth=auth_cred)
extension_api_client = self.kubernetes.get_extension_api_client(
app_v1_api_client = self.kubernetes.get_app_v1_api_client(
auth=auth_cred)
scaling_api_client = self.kubernetes.get_scaling_api_client(
auth=auth_cred)
@ -321,7 +321,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
body = client.V1DeleteOptions(
propagation_policy='Foreground',
grace_period_seconds=5)
extension_api_client.delete_namespaced_deployment(
app_v1_api_client.delete_namespaced_deployment(
namespace=namespace,
name=deployment_name,
body=body)
@ -350,7 +350,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
try:
core_v1_api_client = self.kubernetes.get_core_v1_api_client(
auth=auth_cred)
extension_api_client = self.kubernetes.get_extension_api_client(
app_v1_api_client = self.kubernetes.get_app_v1_api_client(
auth=auth_cred)
scaling_api_client = self.kubernetes.get_scaling_api_client(
auth=auth_cred)
@ -386,7 +386,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
except Exception:
pass
try:
extension_api_client.read_namespaced_deployment(
app_v1_api_client.read_namespaced_deployment(
namespace=namespace,
name=deployment_name)
count = count + 1
@ -416,7 +416,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
# initialize Kubernetes APIs
auth_cred, file_descriptor = self._get_auth_creds(auth_attr)
try:
extension_api_client = self.kubernetes.get_extension_api_client(
app_v1_api_client = self.kubernetes.get_app_v1_api_client(
auth=auth_cred)
scaling_api_client = self.kubernetes.get_scaling_api_client(
auth=auth_cred)
@ -427,7 +427,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
for i in range(0, len(deployment_names), 2):
namespace = deployment_names[i]
deployment_name = deployment_names[i + 1]
deployment_info = extension_api_client.\
deployment_info = app_v1_api_client.\
read_namespaced_deployment(namespace=namespace,
name=deployment_name)
scaling_info = scaling_api_client.\
@ -454,7 +454,7 @@ class Kubernetes(abstract_driver.VnfAbstractDriver,
{'number': replicas})
scale_replicas = replicas
deployment_info.spec.replicas = scale_replicas
extension_api_client.patch_namespaced_deployment_scale(
app_v1_api_client.patch_namespaced_deployment_scale(
namespace=namespace,
name=deployment_name,
body=deployment_info)

@ -33,10 +33,10 @@ CONF = cfg.CONF
class TOSCAToKubernetes(object):
def __init__(self, vnf, core_v1_api_client,
extension_api_client, scaling_api_client):
app_v1_api_client, scaling_api_client):
self.vnf = vnf
self.core_v1_api_client = core_v1_api_client
self.extension_api_client = extension_api_client
self.app_v1_api_client = app_v1_api_client
self.scaling_api_client = scaling_api_client
self.attributes = {}
self.vnfd_yaml = None
@ -57,7 +57,7 @@ class TOSCAToKubernetes(object):
tosca_kube_objects = self.generate_tosca_kube_objects()
transformer = translate_outputs.Transformer(
core_v1_api_client=self.core_v1_api_client,
extension_api_client=self.extension_api_client,
app_v1_api_client=self.app_v1_api_client,
scaling_api_client=self.scaling_api_client)
kubernetes_objects = transformer.transform(tosca_kube_objects)
deployment_names = transformer.deploy(

Loading…
Cancel
Save