Example #1
0
    def update_release(self,
                       chart,
                       release,
                       namespace,
                       pre_actions=None,
                       post_actions=None,
                       disable_hooks=False,
                       values=None,
                       wait=False,
                       timeout=None,
                       force=False,
                       recreate_pods=False):
        '''
        Update a Helm Release
        '''
        timeout = self._check_timeout(wait, timeout)

        LOG.info(
            'Helm update release%s: wait=%s, timeout=%s, force=%s, '
            'recreate_pods=%s', (' (dry run)' if self.dry_run else ''), wait,
            timeout, force, recreate_pods)

        if values is None:
            values = Config(raw='')
        else:
            values = Config(raw=values)

        self._pre_update_actions(pre_actions, release, namespace, chart,
                                 disable_hooks, values, timeout)

        update_msg = None
        # build release install request
        try:
            stub = ReleaseServiceStub(self.channel)
            release_request = UpdateReleaseRequest(chart=chart,
                                                   dry_run=self.dry_run,
                                                   disable_hooks=disable_hooks,
                                                   values=values,
                                                   name=release,
                                                   wait=wait,
                                                   timeout=timeout,
                                                   force=force,
                                                   recreate=recreate_pods)

            update_msg = stub.UpdateRelease(release_request,
                                            timeout + GRPC_EPSILON,
                                            metadata=self.metadata)

        except Exception:
            LOG.exception('Error while updating release %s', release)
            status = self.get_release_status(release)
            raise ex.ReleaseException(release, status, 'Upgrade')

        tiller_result = TillerResult(
            update_msg.release.name, update_msg.release.namespace,
            update_msg.release.info.status.Code.Name(
                update_msg.release.info.status.code),
            update_msg.release.info.Description, update_msg.release.version)

        return tiller_result
Example #2
0
    def update_release(self,
                       chart,
                       namespace,
                       dry_run=False,
                       name=None,
                       values=None,
                       wait=False,
                       disable_hooks=False,
                       recreate=False,
                       reset_values=False,
                       reuse_values=False,
                       force=False,
                       description="",
                       install=False):
        """
        Update a Helm Release
        """
        stub = ReleaseServiceStub(self._channel)

        if install:
            if not namespace:
                namespace = DEFAULT_NAMESPACE

            try:
                release_status = self.get_release_status(name)
            except grpc.RpcError as rpc_error_call:
                if not rpc_error_call.details(
                ) == "getting deployed release \"{}\": release: \"{}\" not found".format(
                        name, name):
                    raise rpc_error_call

                # The release doesn't exist - it's time to install
                self._logger.info(
                    "Release %s does not exist. Installing it now.", name)

                return self.install_release(chart, namespace, dry_run, name,
                                            values, wait)

            if release_status.namespace != namespace:
                self._logger.warn(
                    "Namespace %s doesn't match with previous. Release will be deployed to %s",
                    release_status.namespace, namespace)

        values = Config(raw=yaml.safe_dump(values or {}))

        release_request = UpdateReleaseRequest(chart=chart,
                                               dry_run=dry_run,
                                               disable_hooks=disable_hooks,
                                               values=values,
                                               name=name or '',
                                               wait=wait,
                                               recreate=recreate,
                                               reset_values=reset_values,
                                               reuse_values=reuse_values,
                                               force=force,
                                               description=description)

        return stub.UpdateRelease(release_request,
                                  self._timeout,
                                  metadata=self.metadata)