Exemplo n.º 1
0
 def _fix_yaml(self):
     # Replacements are to point container paths and/or versions to the
     # expected ones to test.
     if converter('@bool', settings.SES.BUILD_ROOK_FROM_GIT):
         # Replace image reference if we built it in this run
         with open(os.path.join(self.ceph_dir, 'operator.yaml')) as file:
             docs = yaml.load_all(file, Loader=yaml.FullLoader)
             for doc in docs:
                 try:
                     image = doc['spec']['template']['spec'][
                             'containers'][0]['image']
                     break
                 except KeyError:
                     pass
             logger.info("replacing %s by %s", image, self.rook_image)
             replacements = {image: self.rook_image}
             recursive_replace(self.ceph_dir, replacements)
         with open(os.path.join(self.ceph_dir, 'cluster.yaml')) as file:
             docs = yaml.load_all(file, Loader=yaml.FullLoader)
             for doc in docs:
                 try:
                     image = doc['spec']['cephVersion']['image']
                     break
                 except KeyError:
                     pass
             logger.info("replacing %s by %s", image, settings(
                 f"SES.{settings.SES.TARGET}.ceph_image"))
             replacements = {image: settings(
                 f"SES.{settings.SES.TARGET}.ceph_image")}
             recursive_replace(self.ceph_dir, replacements)
     else:
         replacements = settings(
             f'SES.{settings.SES.TARGET}.yaml_substitutions')
         recursive_replace(self.ceph_dir, replacements)
Exemplo n.º 2
0
    def build(self):
        super().build()
        self.get_rook()
        if not converter('@bool', settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT):
            return

        self.get_golang()
        logger.info("Compiling rook...")
        execute(
            command=f"make --directory {self.build_dir} "
                    f"-j BUILD_REGISTRY='rook-build' IMAGES='ceph'",
            env={"PATH": f"{self.workspace.bin_dir}/go/bin:"
                         f"{os.environ['PATH']}",
                 "TMPDIR": self.workspace.tmp_dir,
                 "GOCACHE": self.workspace.tmp_dir,
                 "GOPATH": self.workspace.build_dir},
            log_stderr=False)

        image = 'rook/ceph'
        tag = f"{settings.UPSTREAM_ROOK.VERSION}-rookcheck"
        self.rook_image = f"{image}:{tag}"
        logger.info(f"Tag image as {image}:{tag}")
        execute(f'docker tag "rook-build/ceph-amd64" {image}:{tag}')

        logger.info("Save image tar")
        # TODO(jhesketh): build arch may differ
        execute(f"docker save {image}:{tag} | gzip > %s"
                % os.path.join(self.build_dir, 'rook-ceph.tar.gz'))
        self._rook_built = True
Exemplo n.º 3
0
def _check_docker_requirement():
    logger.debug("Checking if docker is running...")
    if settings.DISTRO == 'openSUSE_k8s' and \
            converter('@bool', settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT):
        rc, out, err = common.execute('docker ps', log_stdout=False)
        if rc != 0:
            raise Exception("Docker is not running - see manual.")
        logger.debug("... Docker appears to be ready")
Exemplo n.º 4
0
    def build(self):
        if not converter('@bool', settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT):
            return

        image = 'rook/ceph'
        tag = f"{settings.UPSTREAM_ROOK.VERSION}-rookcheck"
        self.rook_image = f"{image}:{tag}"
        super().build()
Exemplo n.º 5
0
    def get_rook(self):
        if not converter('@bool', settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT):
            return

        super().get_rook()
        logger.info(
            "Clone rook version %s from repo %s" %
            (settings.UPSTREAM_ROOK.VERSION, settings.UPSTREAM_ROOK.REPO))
        execute("git clone -b %s %s %s" %
                (settings.UPSTREAM_ROOK.VERSION, settings.UPSTREAM_ROOK.REPO,
                 self.build_dir),
                log_stderr=False)
Exemplo n.º 6
0
 def preinstall(self):
     super().preinstall()
     if converter('@bool', settings.SES.BUILD_ROOK_FROM_GIT):
         self.upload_rook_image()
     repo_vars = {
         'ses_repositories':
             settings(f'SES.{settings.SES.TARGET}.repositories')
     }
     self.kubernetes.hardware.ansible_run_playbook(
         'playbook_rook_ses.yaml', extra_vars=repo_vars)
     self._get_rook_yaml()
     self._fix_yaml()
Exemplo n.º 7
0
 def _get_rook_yaml(self):
     # do not use rpm-package for self-built rook images
     if converter('@bool', settings.SES.BUILD_ROOK_FROM_GIT):
         self.ceph_dir = os.path.join(
             self.build_dir, 'cluster/examples/kubernetes/ceph')
         return
     # TODO (bleon)
     # This is not optima. Need to retrieve RPM directly and extract files
     # out of it. RPM URL should be configurable
     execute(f"rsync -avr -e 'ssh -i {self.workspace.private_key}'"
             f" {settings.NODE_IMAGE_USER}"
             f"@{self.kubernetes.hardware.masters[0].get_ssh_ip()}"
             f":/usr/share/k8s-yaml/rook {self.workspace.working_dir}")
Exemplo n.º 8
0
    def _install_operator(self):
        """
        Install operator using either kubectl of helm
        """
        if (settings.OPERATOR_INSTALLER == "helm" and not
                converter('@bool',
                          settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT)):
            logger.info('Deploying rook operator - using Helm')
            self._install_operator_helm()
        else:
            logger.info('Deploying rook operator - using kubectl apply ...')
            self._install_operator_kubectl()

        logger.info("Wait for rook-ceph-operator running")
        pattern = re.compile(r'.*rook-ceph-operator.*Running')
        common.wait_for_result(
            self.kubernetes.kubectl, "-n rook-ceph get pods",
            matcher=common.regex_count_matcher(pattern, 1),
            attempts=30, interval=10)

        # set operator log level
        self.kubernetes.kubectl(
            "--namespace rook-ceph set env "
            "deployment/rook-ceph-operator ROOK_LOG_LEVEL=DEBUG")
Exemplo n.º 9
0
 def preinstall(self):
     super().preinstall()
     if converter('@bool', settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT):
         self.upload_rook_image()
         self._fix_yaml()
Exemplo n.º 10
0
 def upload_rook_image(self):
     if converter('@bool', settings.UPSTREAM_ROOK.BUILD_ROOK_FROM_GIT):
         pass
     else:
         return