kubelib.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:kubelib 作者: safarijv 项目源码 文件源码
def from_dict(self, configkey, literal_dict):
        """Turn a dict into a configmap."""
        tdir = tempfile.mkdtemp()
        for key in literal_dict:
            with open(os.path.join(tdir, key), 'w') as h:
                h.write(literal_dict[key])

        max_timeout = 120
        retry_delay = 1
        success = False
        start = time.time()

        now = time.time()
        while success is False and now < start + max_timeout:
            try:
                self.kubectl.create.configmap(
                    configkey,
                    "--from-file={}".format(tdir),
                    '--context={}'.format(self.config.context),
                    '--namespace={}'.format(self.config.namespace)
                )
                success = True
            except sh.ErrorReturnCode_1 as err:
                LOG.error(
                    "Error creating configmap %s (%s remaining)",
                    err, (start + max_timeout) - now
                )
                time.sleep(
                    min(
                        retry_delay,
                        (max_timeout - (time.time() - start))
                    )
                )
                retry_delay = retry_delay * 2
                now = time.time()

        shutil.rmtree(tdir)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号