Пример #1
0
    def set_upgrade_images(self):
        """
        Set images for upgrade

        """
        ocs_catalog = CatalogSource(
            resource_name=constants.OPERATOR_CATALOG_SOURCE_NAME,
            namespace=constants.MARKETPLACE_NAMESPACE,
        )

        if not self.upgrade_in_current_source:
            disable_specific_source(constants.OPERATOR_CATALOG_SOURCE_NAME)
            if not ocs_catalog.is_exist():
                log.info("OCS catalog source doesn't exist. Creating new one.")
                create_catalog_source(self.ocs_registry_image,
                                      ignore_upgrade=True)
                # We can return here as new CatalogSource contains right images
                return
            image_url = ocs_catalog.get_image_url()
            image_tag = ocs_catalog.get_image_name()
            log.info(f"Current image is: {image_url}, tag: {image_tag}")
            version_change = (self.get_parsed_versions()[1] >
                              self.get_parsed_versions()[0])
            if self.ocs_registry_image:
                image_url, new_image_tag = self.ocs_registry_image.rsplit(
                    ":", 1)
            elif config.UPGRADE.get("upgrade_to_latest",
                                    True) or version_change:
                new_image_tag = get_latest_ds_olm_tag()
            else:
                new_image_tag = get_next_version_available_for_upgrade(
                    image_tag)
            cs_data = deepcopy(ocs_catalog.data)
            image_for_upgrade = ":".join([image_url, new_image_tag])
            log.info(f"Image: {image_for_upgrade} will be used for upgrade.")
            cs_data["spec"]["image"] = image_for_upgrade

            with NamedTemporaryFile() as cs_yaml:
                dump_data_to_temp_yaml(cs_data, cs_yaml.name)
                ocs_catalog.apply(cs_yaml.name)
Пример #2
0
def update_non_ga_version():
    """
    Update pull secret, catalog source, subscription and operators to consume
    ODF and deployer versions provided in configuration.

    """
    deployer_version = config.UPGRADE["deployer_version"]
    upgrade_ocs_version = config.UPGRADE["upgrade_ocs_version"]
    logger.info(
        f"Starting update to next version of deployer: {deployer_version}")
    logger.info("Update catalogsource")
    disable_specific_source(constants.OPERATOR_CATALOG_SOURCE_NAME)
    catalog_source_data = templating.load_yaml(constants.CATALOG_SOURCE_YAML)
    catalog_source_data["spec"]["image"] = config.DEPLOYMENT[
        "ocs_registry_image"]
    catalog_source_manifest = tempfile.NamedTemporaryFile(
        mode="w+", prefix="catalog_source_manifest", delete=False)
    templating.dump_data_to_temp_yaml(catalog_source_data,
                                      catalog_source_manifest.name)
    run_cmd(f"oc apply -f {catalog_source_manifest.name}", timeout=2400)
    catalog_source = CatalogSource(
        resource_name=constants.OPERATOR_CATALOG_SOURCE_NAME,
        namespace=constants.MARKETPLACE_NAMESPACE,
    )
    logger.info("Edit annotation on the deployer CSV")
    run_cmd(
        f"oc annotate csv --overwrite ocs-osd-deployer.v{deployer_version} "
        'operatorframework.io/properties=\'{"properties":[{"type":"olm.package",'
        '"value":{"packageName":"ocs-osd-deployer","version":'
        f'"{deployer_version}"'
        '}},{"type":"olm.gvk","value":{"group":"ocs.openshift.io","kind":'
        '"ManagedOCS","version":"v1alpha1"}},{"type":"olm.package.required",'
        '"value":{"packageName":"ose-prometheus-operator","versionRange":"4.10.0"}},'
        '{"type":"olm.package.required","value":{"packageName":"odf-operator",'
        f'"versionRange":"{upgrade_ocs_version}"'
        "}}]}' -n openshift-storage")
    # Wait for catalog source is ready
    catalog_source.wait_for_state("READY")
    ocs_channel = config.UPGRADE["ocs_channel"]
    odf_operator_u = f"odf-operator.v{upgrade_ocs_version}"
    mplace = constants.MARKETPLACE_NAMESPACE

    logger.info("Edit subscriptions")
    oc = ocp.OCP(
        kind=constants.SUBSCRIPTION,
        namespace=config.ENV_DATA["cluster_namespace"],
    )
    subscriptions = oc.get()["items"]
    if config.ENV_DATA.get("cluster_type").lower() == "provider":
        subscriptions_to_edit = {"odf-operator"}
        patch_changes = [
            f'[{{"op": "replace", "path": "/spec/channel", "value" : "{ocs_channel}"}}]',
            f'[{{"op": "replace", "path": "/spec/startingCSV", "value" : "{odf_operator_u}"}}]',
        ]
    elif config.ENV_DATA.get("cluster_type").lower() == "consumer":
        subscriptions_to_edit = {
            "ocs-operator",
            "odf-operator",
            "mcg-operator",
            "odf-csi-addons-operator",
        }
        patch_changes = [
            f'[{{"op": "replace", "path": "/spec/channel", "value" : "{ocs_channel}"}}]',
            f'[{{"op": "replace", "path": "/spec/sourceNamespace", "value" : "{mplace}"}}]',
            f'[{{"op": "replace", "path": "/spec/startingCSV", "value" : "{odf_operator_u}"}}]',
        ]
    for subscription in subscriptions:
        for to_edit in subscriptions_to_edit:
            sub = (subscription.get("metadata").get("name") if
                   subscription.get("metadata").get("name").startswith(to_edit)
                   else "")
            if sub:
                for change in patch_changes:
                    oc.patch(
                        resource_name=sub,
                        params=change,
                        format_type="json",
                    )
Пример #3
0
def create_catalog_source(image=None, ignore_upgrade=False):
    """
    This prepare catalog source manifest for deploy OCS operator from
    quay registry.

    Args:
        image (str): Image of ocs registry.
        ignore_upgrade (bool): Ignore upgrade parameter.

    """
    # Because custom catalog source will be called: redhat-operators, we need to disable
    # default sources. This should not be an issue as OCS internal registry images
    # are now based on OCP registry image
    disable_specific_source(constants.OPERATOR_CATALOG_SOURCE_NAME)
    logger.info("Adding CatalogSource")
    if not image:
        image = config.DEPLOYMENT.get("ocs_registry_image", "")
    if config.DEPLOYMENT.get("stage_rh_osbs"):
        image = config.DEPLOYMENT.get("stage_index_image", constants.OSBS_BOUNDLE_IMAGE)
        ocp_version = version.get_semantic_ocp_version_from_config()
        osbs_image_tag = config.DEPLOYMENT.get(
            "stage_index_image_tag", f"v{ocp_version}"
        )
        image += f":{osbs_image_tag}"
        run_cmd(
            "oc patch image.config.openshift.io/cluster --type merge -p '"
            '{"spec": {"registrySources": {"insecureRegistries": '
            '["registry-proxy.engineering.redhat.com", "registry.stage.redhat.io"]'
            "}}}'"
        )
        run_cmd(f"oc apply -f {constants.STAGE_IMAGE_CONTENT_SOURCE_POLICY_YAML}")
        logger.info("Sleeping for 60 sec to start update machineconfigpool status")
        time.sleep(60)
        wait_for_machineconfigpool_status("all", timeout=1800)
    if not ignore_upgrade:
        upgrade = config.UPGRADE.get("upgrade", False)
    else:
        upgrade = False
    image_and_tag = image.rsplit(":", 1)
    image = image_and_tag[0]
    image_tag = image_and_tag[1] if len(image_and_tag) == 2 else None
    if not image_tag and config.REPORTING.get("us_ds") == "DS":
        image_tag = get_latest_ds_olm_tag(
            upgrade, latest_tag=config.DEPLOYMENT.get("default_latest_tag", "latest")
        )

    catalog_source_data = templating.load_yaml(constants.CATALOG_SOURCE_YAML)
    if config.ENV_DATA["platform"] == constants.IBMCLOUD_PLATFORM:
        create_ocs_secret(constants.MARKETPLACE_NAMESPACE)
        catalog_source_data["spec"]["secrets"] = [constants.OCS_SECRET]
    cs_name = constants.OPERATOR_CATALOG_SOURCE_NAME
    change_cs_condition = (
        (image or image_tag)
        and catalog_source_data["kind"] == "CatalogSource"
        and catalog_source_data["metadata"]["name"] == cs_name
    )
    if change_cs_condition:
        default_image = config.DEPLOYMENT["default_ocs_registry_image"]
        image = image if image else default_image.rsplit(":", 1)[0]
        catalog_source_data["spec"][
            "image"
        ] = f"{image}:{image_tag if image_tag else 'latest'}"
    catalog_source_manifest = tempfile.NamedTemporaryFile(
        mode="w+", prefix="catalog_source_manifest", delete=False
    )
    templating.dump_data_to_temp_yaml(catalog_source_data, catalog_source_manifest.name)
    run_cmd(f"oc apply -f {catalog_source_manifest.name}", timeout=2400)
    catalog_source = CatalogSource(
        resource_name=constants.OPERATOR_CATALOG_SOURCE_NAME,
        namespace=constants.MARKETPLACE_NAMESPACE,
    )
    # Wait for catalog source is ready
    catalog_source.wait_for_state("READY")