Example #1
0
    def source_clone(self):
        '''
        Clone the charts source

        We only support a git source type right now, which can also
        handle git:// local paths as well
        '''

        subpath = self.chart.source.get('subpath', '')

        if not self.chart.source.type:
            LOG.exception("Unknown source type %s for chart %s",
                          self.chart.name,
                          self.chart.source.type)
            return

        if self.parent:
            LOG.info("Cloning %s/%s as dependency for %s",
                     self.chart.source.location,
                     subpath, self.parent)
        else:
            LOG.info("Cloning %s/%s for release %s",
                     self.chart.source.location,
                     subpath, self.chart.name)

        if self.chart.source.type == 'git':
            self._source_tmp_dir = repo.git_clone(self.chart.source.location,
                                                  self.chart.source.reference)

        if self.chart.source.type == 'repo':
            self._source_tmp_dir = repo.from_repo(self.chart.source.location,
                                                  self.chart.name,
                                                  self.chart.version)

        return os.path.join(self._source_tmp_dir, subpath)
Example #2
0
def chart_download(data):
    """Sample asynchronous task. Download a helm chart to the cache"""
    chart = data.copy()
    chart["chart_location"] = from_repo(data["source_location"], data["name"])
    chart_path = os.path.join(chart["chart_location"], "Chart.yaml")
    if os.path.exists(chart_path):
        with open(chart_path, "r") as fh:
            chart["yaml"] = fh.read()
    return chart
Example #3
0
    def source_clone(self):
        '''
        Clone the charts source

        We only support a git source type right now, which can also
        handle git:// local paths as well
        '''

        subpath = self.chart.source.get('subpath', '')

        if 'name' not in self.chart:
            self._logger.exception("Please specify name for the chart")
            return

        if 'type' not in self.chart.source:
            self._logger.exception("Need source type for chart %s",
                                   self.chart.name)
            return

        if self.parent:
            self._logger.info("Cloning %s/%s as dependency for %s",
                              self.chart.source.location, subpath, self.parent)
        else:
            self._logger.info("Cloning %s/%s for release %s",
                              self.chart.source.location, subpath,
                              self.chart.name)

        if self.chart.source.type == 'git':
            if 'reference' not in self.chart.source:
                self.chart.source.reference = 'master'
            if 'path' not in self.chart.source:
                self.chart.source.path = ''
            self._source_tmp_dir = repo.git_clone(self.chart.source.location,
                                                  self.chart.source.reference,
                                                  self.chart.source.path)

        elif self.chart.source.type == 'repo':
            if 'version' not in self.chart:
                self.chart.version = None
            if 'headers' not in self.chart.source:
                self.chart.source.headers = None
            self._source_tmp_dir = repo.from_repo(self.chart.source.location,
                                                  self.chart.name,
                                                  self.chart.version,
                                                  self.chart.source.headers)
        elif self.chart.source.type == 'directory':
            self._source_tmp_dir = self.chart.source.location

        else:
            self._logger.exception("Unknown source type %s for chart %s",
                                   self.chart.name, self.chart.source.type)
            return

        return os.path.join(self._source_tmp_dir, subpath)
Example #4
0
    def source_clone(self):
        '''
        Clone the charts source

        We only support a git source type right now, which can also
        handle git:// local paths as well
        '''

        subpath = self.chart.source.get('subpath', '')

        if not 'type' in self.chart.source:
            self._logger.exception("Need source type for chart %s",
                                   self.chart.name)
            return

        if self.parent:
            self._logger.info("Cloning %s/%s as dependency for %s",
                              self.chart.source.location,
                              subpath, self.parent)
        else:
            self._logger.info("Cloning %s/%s for release %s",
                              self.chart.source.location,
                              subpath, self.chart.name)

        if self.chart.source.type == 'git':
            if 'reference' not in self.chart.source:
                self.chart.source.reference = 'master'
            if 'path' not in self.chart.source:
                self.chart.source.path = ''
            self._source_tmp_dir = repo.git_clone(self.chart.source.location,
                                                  self.chart.source.reference,
                                                  self.chart.source.path)

        elif self.chart.source.type == 'repo':
            if 'version' not in self.chart:
                self.chart.version = None
            if 'headers' not in self.chart.source:
                self.chart.source.headers = None
            self._source_tmp_dir = repo.from_repo(self.chart.source.location,
                                                  self.chart.name,
                                                  self.chart.version,
                                                  self.chart.source.headers)
        elif self.chart.source.type == 'directory':
            self._source_tmp_dir = self.chart.source.location

        else:
            self._logger.exception("Unknown source type %s for chart %s",
                                   self.chart.name,
                                   self.chart.source.type)
            return

        return os.path.join(self._source_tmp_dir, subpath)
Example #5
0
def deploy():
    chart_path = from_repo('https://kubernetes-charts.storage.googleapis.com/',
                           'mariadb')
    #print(chart_path)
    chart = ChartBuilder({
        'name': 'mongodb',
        'source': {
            'type': 'directory',
            'location': '/tmp/pyhelm-dMLypC/mariadb'
        }
    })
    tiller_ins = Tiller('10.102.187.89', '44134')
    tiller_ins.install_release(chart.get_helm_chart(),
                               dry_run=False,
                               namespace='default')
    return "hello kuber"
    def install(self, tserver=None):
        if not HasPyhelm:
            print(bcolors.FAIL)
            print('*' * 80)
            print('pyhelm is not installed')
            print(bcolors.ENDC)
            return
        if not tserver:
            tserver = self.tserver
        changed = False
        name = self.resource_name
        values = self.values
        chart = self.chart
        namespace = self.namespace

        if chart:
            url, cart_name = chart
            chart_path = chart_versions = from_repo(url, cart_name)
            chart_obj = chartbuilder.ChartBuilder({
                'name': 'mongodb',
                'source': {
                    'type': 'directory',
                    'location': chart_path
                }
            })
            #chartb = chartbuilder.ChartBuilder(chart_path)
            r_matches = (x for x in tserver.list_releases()
                         if x.name == name and x.namespace == namespace)
            installed_release = next(r_matches, None)
            if installed_release:
                if installed_release.chart.metadata.version != chart['version']:
                    tserver.update_release(chartb.get_helm_chart(),
                                           False,
                                           namespace,
                                           name=name,
                                           values=values)
                    changed = True
            else:
                tserver.install_release(chartb.get_helm_chart(),
                                        namespace,
                                        dry_run=False,
                                        name=name,
                                        values=values)
                changed = True

        return changed
def install_release(chart_name, repo, namespace):
    """
    Installs a chart.

    Args:
        chart_name (str)
        repo (str)
        namespace (str)
    Returns:
        {
            'release': Name of the helm release,
            'status': Status of the installation
        }
    """
    try:
        chart_path = from_repo(repo, chart_name)
    except requests.RequestException as e:
        log(e)
        return {
            'Error': 'Helm repository unreachable.',
        }
    chart = ChartBuilder({
        'name': chart_name,
        'source': {
            'type': 'directory',
            'location': chart_path,
        },
    })
    try:
        tiller = get_tiller()
        response = tiller.install_release(chart.get_helm_chart(),
                                          dry_run=False,
                                          namespace=namespace)
        status_code = response.release.info.status.code
        return {
            'release': response.release.name,
            'status': response.release.info.status.Code.Name(status_code),
        }
    except grpc.RpcError as e:
        log(e.details())
        status_code = e.code()
        if grpc.StatusCode.UNAVAILABLE == status_code:
            return {
                'Error': 'Tiller unreachable.',
            }
Example #8
0
 def test_not_found(self, _0, _1):
     with self.assertRaises(repo.HTTPGetError):
         repo.from_repo('http://test', '')
     repo.requests.get.assert_called_once_with(os.path.join(
         'http://test', 'index.yaml'),
                                               headers=None)
Example #9
0
 def test_latest_version(self, _0, _1, _2, _3):
     r = repo.from_repo("http://test", "foo")
     self.assertEqual(r, "/tmp/dir/foo")
Example #10
0
    def source_clone(self):
        """
        Clone the charts source

        We only support a git source type right now, which can also
        handle git:// local paths as well
        """

        subpath = self.chart.source.get("subpath", "")

        if "name" not in self.chart:
            self._logger.exception("Please specify name for the chart")
            return

        if "type" not in self.chart.source:
            self._logger.exception("Need source type for chart %s",
                                   self.chart.name)
            return

        if self.parent:
            self._logger.info(
                "Cloning %s/%s as dependency for %s",
                self.chart.source.location,
                subpath,
                self.parent,
            )
        else:
            self._logger.info(
                "Cloning %s/%s for release %s",
                self.chart.source.location,
                subpath,
                self.chart.name,
            )

        if self.chart.source.type == "git":
            if "reference" not in self.chart.source:
                self.chart.source.reference = "master"
            if "path" not in self.chart.source:
                self.chart.source.path = ""
            self._source_tmp_dir = repo.git_clone(
                self.chart.source.location,
                self.chart.source.reference,
                self.chart.source.path,
            )

        elif self.chart.source.type == "repo":
            if "version" not in self.chart:
                self.chart.version = None
            if "headers" not in self.chart.source:
                self.chart.source.headers = None
            self._source_tmp_dir = repo.from_repo(
                self.chart.source.location,
                self.chart.name,
                self.chart.version,
                self.chart.source.headers,
            )
        elif self.chart.source.type == "directory":
            self._source_tmp_dir = self.chart.source.location

        else:
            self._logger.exception(
                "Unknown source type %s for chart %s",
                self.chart.name,
                self.chart.source.type,
            )
            return

        return os.path.join(self._source_tmp_dir, subpath)
Example #11
0
 def test_specific_version(self, _0, _1, _2, _3):
     r = repo.from_repo("http://test", "foo", version="0.1.2")
     self.assertEqual(r, "/tmp/dir/foo")
Example #12
0
 def test_specific_version(self, _0, _1, _2, _3):
     r = repo.from_repo('http://test', 'foo', version='0.1.2')
     self.assertEquals(r, '/tmp/dir/foo')
Example #13
0
 def test_latest_version(self, _0, _1, _2, _3):
     r = repo.from_repo('http://test', 'foo')
     self.assertEquals(r, '/tmp/dir/foo')
Example #14
0
 def test_version_not_found(self, _0, _1):
     with self.assertRaises(repo.VersionError):
         repo.from_repo('http://test', 'bar', version='1.0.0')
Example #15
0
 def test_version_not_found(self, _0, _1):
     with self.assertRaises(repo.VersionError):
         repo.from_repo("http://test", "bar", version="1.0.0")
Example #16
0
# -*- coding:utf-8 -*-
#from pyhelm.repo import RepoUtils
from pyhelm.repo import from_repo
import pdb;pdb.set_trace()
from pyhelm.chartbuilder import ChartBuilder
from pyhelm.tiller import Tiller
import pdb;pdb.set_trace()
tiller_host='127.0.0.1'
tiller_port='44134'
#chart_path = RepoUtils.from_repo('https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart_path = from_repo('https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart = ChartBuilder({'name': 'mariadb', 'source': {'type': 'directory', 'location': chart_path}})
# 构建chart元数据  
#chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})  
#chart = ChartBuilder({'name': 'stable/mongodb', 'version':'0.4.27', 'source': {'type': 'repo', 'version': '0.4.27', 'location': 'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts'}})
# 生成tiller连接实例  
tiller_ins = Tiller(tiller_host, tiller_port)  
import pdb;pdb.set_trace()
# 安装 release  
tiller_ins.install_release(chart.get_helm_chart(), dry_run=False, namespace='default')  
# 列出 release  
tiller_ins.list_releases(limit=0, status_codes=[], namespace=None)  
# 删除 release  
tiller_ins.uninstall_release(release_name)  
# 获得 release 版本历史  
tiller_ins.get_history(name, max=MAX_HISTORY) 
# 回滚 release  
tiller_ins.rollback_release(name, version, timeout=REQUEST_TIMEOUT)
Example #17
0
# -*- coding:utf-8 -*-
#from pyhelm.repo import RepoUtils
from pyhelm.repo import from_repo
import pdb
pdb.set_trace()
from pyhelm.chartbuilder import ChartBuilder
from pyhelm.tiller import Tiller
import pdb
pdb.set_trace()
tiller_host = '127.0.0.1'
tiller_port = '44134'
#chart_path = RepoUtils.from_repo('https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart_path = from_repo(
    'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart = ChartBuilder({
    'name': 'mariadb',
    'source': {
        'type': 'directory',
        'location': chart_path
    }
})
# 构建chart元数据
#chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})
#chart = ChartBuilder({'name': 'stable/mongodb', 'version':'0.4.27', 'source': {'type': 'repo', 'version': '0.4.27', 'location': 'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts'}})
# 生成tiller连接实例
tiller_ins = Tiller(tiller_host, tiller_port)
import pdb
pdb.set_trace()
# 安装 release
tiller_ins.install_release(chart.get_helm_chart(),
                           dry_run=False,
Example #18
0
 def test_chart_not_found(self, _0, _1):
     with self.assertRaises(repo.ChartError):
         repo.from_repo('http://test', 'baz')
Example #19
0
 def test_chart_not_found(self, _0, _1):
     with self.assertRaises(repo.VersionError):
         repo.from_repo("http://test", "baz")