# Set the working directory to /app
WORKDIR /app/LCM
-RUN apt-get update && apt-get install -y curl \
+RUN apt-get update && apt-get install -y curl xz-utils \
&& apt-get update && apt-get install -y apt-transport-https \
&& curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \
&& echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list \
&& mv linux-amd64/helm /usr/local/bin/helm \
&& rm -r linux-amd64/
+RUN curl -L https://launchpad.net/juju/2.7/2.7.0/+download/juju-2.7.0-k8s.tar.xz --output juju-2.7.0-k8s.tar.xz \
+ && tar -xvf juju-2.7.0-k8s.tar.xz \
+ && mv juju /usr/local/bin/juju
+
RUN apt-get update && apt-get install -y git tox python3 \
python3-pip python3-aiohttp python3-jinja2 \
&& python3 -m pip install pip --upgrade \
# k8s
ENV OSMLCM_VCA_HELMPATH /usr/local/bin/helm
ENV OSMLCM_VCA_KUBECTLPATH /usr/bin/kubectl
+ENV OSMLCM_VCA_JUJUPATH /usr/local/bin/juju
# logs
# ENV OSMLCM_GLOBAL_LOGFILE /app/log/lcm.log
from osm_lcm import ROclient
from osm_lcm.lcm_utils import LcmException, LcmExceptionNoMgmtIP, LcmBase, deep_get
from n2vc.k8s_helm_conn import K8sHelmConnector
+from n2vc.k8s_juju_conn import K8sJujuConnector
from osm_common.dbbase import DbException
from osm_common.fsbase import FsException
on_update_db=None,
)
+ self.k8sclusterjuju = K8sJujuConnector(
+ kubectl_command=self.vca_config.get("kubectlpath"),
+ juju_command=self.vca_config.get("jujupath"),
+ fs=self.fs,
+ log=self.logger,
+ db=self.db,
+ on_update_db=None,
+ )
+
# create RO client
self.RO = ROclient.ROClient(self.loop, **self.ro_config)
params=desc_params, db_dict=db_dict, timeout=3600)
)
else:
- # TODO juju-bundle connector in place
- pass
+ task = self.k8sclusterjuju.install(cluster_uuid=cluster_uuid, kdu_model=kdumodel,
+ atomic=True, params=desc_params,
+ db_dict=db_dict, timeout=600)
+
pending_tasks[task] = "_admin.deployed.K8s.{}.".format(index)
index += 1
if not pending_tasks:
self.k8sclusterhelm.uninstall(cluster_uuid=kdu.get("k8scluster-uuid"),
kdu_instance=kdu_instance))
elif kdu.get("k8scluster-type") == "juju":
- # TODO Juju connector needed
- continue
+ task_delete_kdu_instance = asyncio.ensure_future(
+ self.k8sclusterjuju.uninstall(cluster_uuid=kdu.get("k8scluster-uuid"),
+ kdu_instance=kdu_instance))
else:
self.error(logging_text + "Unknown k8s deployment type {}".
format(kdu.get("k8scluster-type")))
params=desc_params, db_dict=db_dict,
timeout=300)
elif kdu.get("k8scluster-type") == "juju":
- # TODO Juju connector needed
- pass
+ output = await self.k8sclusterjuju.upgrade(cluster_uuid=kdu.get("k8scluster-uuid"),
+ kdu_instance=kdu.get("kdu-instance"),
+ atomic=True, kdu_model=kdu_model,
+ params=desc_params, db_dict=db_dict,
+ timeout=300)
+
else:
msg = "k8scluster-type not defined"
raise LcmException(msg)
kdu_instance=kdu.get("kdu-instance"),
db_dict=db_dict)
elif kdu.get("k8scluster-type") == "juju":
- # TODO Juju connector needed
- pass
+ output = await self.k8sclusterjuju.rollback(cluster_uuid=kdu.get("k8scluster-uuid"),
+ kdu_instance=kdu.get("kdu-instance"),
+ db_dict=db_dict)
else:
msg = "k8scluster-type not defined"
raise LcmException(msg)
output = await self.k8sclusterhelm.status_kdu(cluster_uuid=kdu.get("k8scluster-uuid"),
kdu_instance=kdu.get("kdu-instance"))
elif kdu.get("k8scluster-type") == "juju":
- # TODO Juju connector needed
- pass
+ output = await self.k8sclusterjuju.status_kdu(cluster_uuid=kdu.get("k8scluster-uuid"),
+ kdu_instance=kdu.get("kdu-instance"))
else:
msg = "k8scluster-type not defined"
raise LcmException(msg)
from osm_lcm import ROclient
from osm_lcm.lcm_utils import LcmException, LcmBase, deep_get
from n2vc.k8s_helm_conn import K8sHelmConnector
+from n2vc.k8s_juju_conn import K8sJujuConnector
from osm_common.dbbase import DbException
from copy import deepcopy
self.fs = fs
self.db = db
- self.k8scluster = K8sHelmConnector(
+ self.helm_k8scluster = K8sHelmConnector(
kubectl_command=self.vca_config.get("kubectlpath"),
helm_command=self.vca_config.get("helmpath"),
fs=self.fs,
on_update_db=None
)
+ self.juju_k8scluster = K8sJujuConnector(
+ kubectl_command=self.vca_config.get("kubectlpath"),
+ juju_command=self.vca_config.get("jujupath"),
+ fs=self.fs,
+ log=self.logger,
+ db=self.db,
+ on_update_db=None
+ )
+
super().__init__(db, msg, fs, self.logger)
async def create(self, k8scluster_content, order_id):
db_k8scluster = None
db_k8scluster_update = {}
+ db_juju_k8scluster_update = {}
exc = None
operationState_HA = ''
db_k8scluster = self.db.get_one("k8sclusters", {"_id": k8scluster_id})
self.db.encrypt_decrypt_fields(db_k8scluster.get("credentials"), 'decrypt', ['password', 'secret'],
schema_version=db_k8scluster["schema_version"], salt=db_k8scluster["_id"])
- # print(db_k8scluster.get("credentials"))
- # print("\n\n\n FIN CREDENTIALS")
- # print(yaml.safe_dump(db_k8scluster.get("credentials")))
- # print("\n\n\n FIN OUTPUT")
- k8s_hc_id, uninstall_sw = await self.k8scluster.init_env(yaml.safe_dump(db_k8scluster.get("credentials")))
+
+ k8s_hc_id, uninstall_sw = await self.helm_k8scluster.init_env(
+ yaml.safe_dump(db_k8scluster.get("credentials"))
+ )
db_k8scluster_update["_admin.helm-chart.id"] = k8s_hc_id
db_k8scluster_update["_admin.helm-chart.created"] = uninstall_sw
+
+ # Juju/k8s cluster
+ k8s_jb_id, uninstall_sw = await self.juju_k8scluster.init_env(
+ yaml.safe_dump(db_k8scluster.get("credentials"))
+ )
+ db_k8scluster_update["_admin.juju-bundle.id"] = k8s_jb_id
+ db_k8scluster_update["_admin.juju-bundle.created"] = uninstall_sw
+
step = "Getting the list of repos"
self.logger.debug(logging_text + step)
task_list = []
for repo in db_k8srepo_list:
step = "Adding repo {} to cluster: {}".format(repo["name"], k8s_hc_id)
self.logger.debug(logging_text + step)
- task = asyncio.ensure_future(self.k8scluster.repo_add(cluster_uuid=k8s_hc_id,
- name=repo["name"], url=repo["url"],
- repo_type="chart"))
+ task = asyncio.ensure_future(self.helm_k8scluster.repo_add(cluster_uuid=k8s_hc_id,
+ name=repo["name"], url=repo["url"],
+ repo_type="chart"))
task_list.append(task)
if not repo["_admin"].get("cluster-inserted"):
repo["_admin"]["cluster-inserted"] = []
if exc and db_k8scluster:
db_k8scluster_update["_admin.operationalState"] = "ERROR"
db_k8scluster_update["_admin.detailed-status"] = "ERROR {}: {}".format(step, exc)
+
+ if db_juju_k8scluster_update:
+ db_juju_k8scluster_update["_admin.operationalState"] = "ERROR"
+ db_juju_k8scluster_update["_admin.detailed-status"] = "ERROR {}: {}".format(step, exc)
+
# Mark the k8scluster 'create' HA task as erroneous
operationState_HA = 'FAILED'
detailed_status_HA = "ERROR {}: {}".format(step, exc)
try:
if db_k8scluster_update:
self.update_db_2("k8sclusters", k8scluster_id, db_k8scluster_update)
+
+ if db_juju_k8scluster_update:
+ self.update_db_2("k8sclusters", k8scluster_id, db_juju_k8scluster_update)
+
# Register the K8scluster 'create' HA task either
# succesful or erroneous, or do nothing (if legacy NBI)
self.lcm_tasks.register_HA('k8scluster', 'create', op_id,
self.logger.debug(logging_text + step)
db_k8scluster = self.db.get_one("k8sclusters", {"_id": k8scluster_id})
k8s_hc_id = deep_get(db_k8scluster, ("_admin", "helm-chart", "id"))
+ k8s_jb_id = deep_get(db_k8scluster, ("_admin", "juju-bundle", "id"))
+
uninstall_sw = deep_get(db_k8scluster, ("_admin", "helm-chart", "created"))
cluster_removed = True
if k8s_hc_id:
uninstall_sw = uninstall_sw or False
- cluster_removed = await self.k8scluster.reset(cluster_uuid=k8s_hc_id, uninstall_sw=uninstall_sw)
+ cluster_removed = await self.helm_k8scluster.reset(cluster_uuid=k8s_hc_id, uninstall_sw=uninstall_sw)
+
+ if k8s_jb_id:
+ uninstall_sw = uninstall_sw or False
+ cluster_removed = await self.juju_k8scluster.reset(cluster_uuid=k8s_jb_id, uninstall_sw=uninstall_sw)
if cluster_removed:
step = "Removing k8scluster='{}' from db".format(k8scluster_id)