diff options
-rwxr-xr-x | src/flufigut.py | 33 | ||||
-rw-r--r-- | templates/default/kubernetes/flumotion-manager-deploy.yml.j2 | 2 | ||||
-rw-r--r-- | templates/default/kubernetes/flumotion-worker-deploy.yml.j2 | 47 |
3 files changed, 50 insertions, 32 deletions
diff --git a/src/flufigut.py b/src/flufigut.py index 2371fb8..f679f68 100755 --- a/src/flufigut.py +++ b/src/flufigut.py @@ -574,11 +574,30 @@ class K8sDeployment: if e.status == 404: pass - def __gen_object(self, tmpl_env, template_file): + def __generate_object(self, tmpl_env, template_file, worker_name=None, worker_subnames=None): tmpl = tmpl_env.get_template(template_file + '.j2') - object_yaml = tmpl.render(namespace=self._namespace, desc=self._desc, planet=self._planet) + object_yaml = tmpl.render(namespace=self._namespace, desc=self._desc, planet=self._planet, + worker_name=worker_name, worker_subnames=worker_subnames) return yaml.load(object_yaml) + def _deploy_manager(self, template_dir, tmpl_env, v1, appsV1): + svc = self.__generate_object(tmpl_env, 'flumotion-manager-svc.yml') + v1.create_namespaced_service(self._namespace, svc) + + cm = self.__generate_object(tmpl_env, 'flumotion-manager-cm.yml') + cm['data']['planet.xml'] = self._planet.toXML(template_dir) + v1.create_namespaced_config_map(self._namespace, cm) + + deploy = self.__generate_object(tmpl_env, 'flumotion-manager-deploy.yml') + appsV1.create_namespaced_deployment(self._namespace, deploy) + + def _deploy_worker(self, template_dir, tmpl_env, v1, appsV1, name, worker): + subnames = ['default'] + if isinstance(worker, dict): + subnames = worker.keys() + deploy = self.__generate_object(tmpl_env, 'flumotion-worker-deploy.yml', name, subnames) + appsV1.create_namespaced_deployment(self._namespace, deploy) + def deploy(self, template_dir): v1 = kubernetes.client.CoreV1Api() appsV1 = kubernetes.client.AppsV1Api() @@ -587,13 +606,9 @@ class K8sDeployment: loader = jinja2.FileSystemLoader(os.path.join(template_dir, self._desc.globals['templates'], 'kubernetes')) tmpl_env = jinja2.Environment(loader=loader, line_statement_prefix='%%') - v1.create_namespaced_service(self._namespace, self.__gen_object(tmpl_env, 'flumotion-manager-svc.yml')) - cm = self.__gen_object(tmpl_env, 'flumotion-manager-cm.yml') - cm['data']['planet.xml'] = self._planet.toXML(template_dir) - v1.create_namespaced_config_map(self._namespace, cm) - appsV1.create_namespaced_deployment(self._namespace, self.__gen_object(tmpl_env, 'flumotion-manager-deploy.yml')) - - # TODO: add workers + self._deploy_manager(template_dir, tmpl_env, v1, appsV1) + for worker_name, worker_entry in self._planet.workers.items(): + self._deploy_worker(template_dir, tmpl_env, v1, appsV1, worker_name, worker_entry) def wipe(self): v1 = kubernetes.client.CoreV1Api() diff --git a/templates/default/kubernetes/flumotion-manager-deploy.yml.j2 b/templates/default/kubernetes/flumotion-manager-deploy.yml.j2 index 4d86e89..04b36e4 100644 --- a/templates/default/kubernetes/flumotion-manager-deploy.yml.j2 +++ b/templates/default/kubernetes/flumotion-manager-deploy.yml.j2 @@ -21,7 +21,7 @@ spec: app: flumotion type: manager spec: - nodeName: dione + nodeName: {{ desc.globals.manager.machine }} containers: - name: flumotion image: spreadspace/flumotion:manager diff --git a/templates/default/kubernetes/flumotion-worker-deploy.yml.j2 b/templates/default/kubernetes/flumotion-worker-deploy.yml.j2 index ea040d0..8504b34 100644 --- a/templates/default/kubernetes/flumotion-worker-deploy.yml.j2 +++ b/templates/default/kubernetes/flumotion-worker-deploy.yml.j2 @@ -1,4 +1,4 @@ -apiVersion: apps/v1beta2 +apiVersion: apps/v1 kind: Deployment metadata: namespace: {{ namespace }} @@ -21,9 +21,10 @@ spec: app: flumotion type: worker spec: - nodeName: dione + nodeName: {{ worker_name }} containers: - - name: flumotion +{% for subname in worker_subnames %} + - name: {{ subname }} image: spreadspace/flumotion:worker imagePullPolicy: Always args: @@ -31,31 +32,33 @@ spec: - -H flumotion-manager - -P 8642 - -T tcp - - -n {{ worker_name }} + - -n {{ worker_name }}:{{ subname }} - -u user - -p test - securityContext: - privileged: true + - -F {{ 8000 + loop.index0 * 10 }}-{{ 8001 + loop.index0 * 10 }} +# securityContext: +# privileged: true volumeMounts: - name: home mountPath: /srv - - name: decklink-devices - mountPath: /dev/blackmagic - - name: decklink-libs - subPath: libDeckLinkAPI.so - mountPath: /usr/lib/libDeckLinkAPI.so - - name: decklink-libs - subPath: libDeckLinkPreviewAPI.so - mountPath: /usr/lib/libDeckLinkPreviewAPI.so +# - name: decklink-devices +# mountPath: /dev/blackmagic +# - name: decklink-libs +# subPath: libDeckLinkAPI.so +# mountPath: /usr/lib/libDeckLinkAPI.so +# - name: decklink-libs +# subPath: libDeckLinkPreviewAPI.so +# mountPath: /usr/lib/libDeckLinkPreviewAPI.so +{% endfor %} volumes: - name: home emptyDir: medium: Memory - - name: decklink-devices - hostPath: - type: Directory - path: /dev/blackmagic - - name: decklink-libs - hostPath: - type: Directory - path: /usr/lib/ +# - name: decklink-devices +# hostPath: +# type: Directory +# path: /dev/blackmagic +# - name: decklink-libs +# hostPath: +# type: Directory +# path: /usr/lib/ |