Example #1
0
 def handler_metric(self, ns, cluster_id, spec):
     """绑定metric"""
     client = mesos.MesosClient(self.access_token, self.project_id, cluster_id, env=None)
     result = client.set_metrics(data=spec, cluster_type='k8s')
     if result.get('code') != 0:
         logger.warning('set metric failed, %s, will try rollback.', result)
         raise Rollback(result)
Example #2
0
 def handler_secret(self, ns, cluster_id, spec):
     client = mesos.MesosClient(
         self.access_token, self.project_id, cluster_id, env=None)
     result = client.create_secret(ns, spec)
     if result.get('code') != 0:
         logger.warning(
             'create secret failed, %s, will try rollback.', result)
         raise Rollback(result)
Example #3
0
 def handler_k8shpa(self, ns, cluster_id, spec):
     """下发HPA配置
     """
     client = K8SClient(self.access_token, self.project_id, cluster_id, env=None)
     spec['apiVersion'] = 'autoscaling/v2beta2'
     try:
         result = client.apply_hpa(ns, spec)
     except Exception as error:
         logger.exception('deploy hpa error, %s', error)
         raise Rollback({})
     return result
Example #4
0
    def handler_k8shpa(self, ns, cluster_id, spec):
        """下发HPA配置"""
        cluster_auth = ClusterAuth(self.access_token, self.project_id, cluster_id)
        client = hpa_client.HPA(cluster_auth)

        name = spec["metadata"]["name"]
        spec['apiVersion'] = hpa_client.PREFERRED_API_VERSION

        try:
            result = client.update_or_create(spec, name, ns)
            logger.debug("deploy hpa success, %s", result)
        except Exception as error:
            logger.exception('deploy hpa error, %s', error)
            raise Rollback({})
Example #5
0
    def handler_k8shpa(self, ns, cluster_id, spec):
        """下发HPA配置"""
        ctx_cluster = CtxCluster.create(token=self.access_token, project_id=self.project_id, id=cluster_id)
        client = HPA(ctx_cluster)

        name = spec["metadata"]["name"]
        spec['apiVersion'] = DEFAULT_HPA_API_VERSION

        try:
            result = client.update_or_create(spec, name, ns)
            logger.debug("deploy hpa success, %s", result)
        except Exception as error:
            logger.exception('deploy hpa error, %s', error)
            raise Rollback({})
Example #6
0
 def handler_application(self, ns, cluster_id, spec):
     """
     - 去除空的配置项,非必须
     - container['ports'] 必须是有效值
     - configmap 必须先创建
     - secrets 必须先创建
     """
     # for container in spec['spec']['template']['spec']['containers']:
     #     container['ports'] = self.clean_ports(container['ports'])
     client = mesos.MesosClient(
         self.access_token, self.project_id, cluster_id, env=None)
     result = client.create_application(ns, spec)
     if result.get('code') != 0:
         logger.warning(
             'create application failed, %s, will try rollback.', result)
         raise Rollback(result)