Skip to content

Commit

Permalink
Provision for installing submariner downstream unreleased build
Browse files Browse the repository at this point in the history
Signed-off-by: Shylesh Kumar Mohan <[email protected]>
  • Loading branch information
shylesh committed Oct 19, 2023
1 parent 97f7ad2 commit 4c5cbd0
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conf/ocsci/submariner_downstream_unreleased.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ENV_DATA:
submariner_source: "downstream"
submariner_release_type: "unreleased"
submariner_version: "0.16.0"
21 changes: 21 additions & 0 deletions ocs_ci/deployment/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CommandFailed,
DRPrimaryNotFoundException,
)
from ocs_ci.utility import templating
from ocs_ci.ocs.utils import get_non_acm_cluster_config
from ocs_ci.utility.utils import run_cmd, run_cmd_interactive
from ocs_ci.ocs.node import get_typed_worker_nodes, label_nodes
Expand Down Expand Up @@ -62,6 +63,8 @@ class Submariner(object):
def __init__(self):
# whether upstream OR downstream
self.source = config.ENV_DATA["submariner_source"]
# released/unreleased
self.submariner_release_type = config.ENV_DATA.get("submariner_release_type")
# Deployment type:
self.deployment_type = config.ENV_DATA.get("submariner_deployment")
# Designated broker cluster index where broker will be deployed
Expand Down Expand Up @@ -94,9 +97,27 @@ def deploy_downstream(self):

login_to_acm()
acm_obj = AcmAddClusters()
if self.submariner_release_type == "unreleased":
old_ctx = config.cur_index
for cluster in get_non_acm_cluster_config():
config.switch_ctx(cluster.MULTICLUSTER["multicluster_index"])
self.create_acm_brew_icsp()
config.switch_ctx(old_ctx)
acm_obj.install_submariner_ui()
acm_obj.submariner_validation_ui()

def create_acm_brew_icsp(self):
"""
This is a prereq for downstream unreleased submariner
"""
icsp_data = templating.load_yaml(constants.ACM_DOWNSTREAM_BREW_ICSP)
icsp_data_yaml = tempfile.NamedTemporaryFile(
mode="w+", prefix="acm_icsp", delete=False
)
templating.dump_data_to_temp_yaml(icsp_data, icsp_data_yaml.name)
run_cmd(f"oc create -f {icsp_data_yaml.name}", timeout=300)

def download_binary(self):
if self.source == "upstream":
# This script puts the platform specific binary in ~/.local/bin
Expand Down
45 changes: 45 additions & 0 deletions ocs_ci/ocs/acm/acm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import time
import os
import tempfile

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
Expand All @@ -24,6 +25,8 @@
TimeoutSampler,
get_running_acm_version,
string_chunkify,
chained_subprocess_pipes,
run_cmd,
)
from ocs_ci.ocs.ui.acm_ui import AcmPageNavigator
from ocs_ci.ocs.ui.base_ui import login_ui, SeleniumDriver
Expand Down Expand Up @@ -152,6 +155,46 @@ def install_submariner_ui(self, globalnet=True):
for s in get_non_acm_cluster_config()
if s.MULTICLUSTER["multicluster_index"] != primary_index
][0]
# submariner catalogsource creation
if config.ENV_DATA["submariner_release_type"] == "unreleased":
submariner_downstream_unreleased = templating.load_yaml(
constants.SUBMARINER_DOWNSTREAM_UNRELEASED
)
# Update catalog source
submariner_full_url = "".join(
[
constants.SUBMARINER_DOWNSTREAM_UNRELEASED_BUILD_URL,
config.ENV_DATA["submariner_version"],
]
)
curl_cmd = f"curl --retry 3 --retry-delay 5 -Ls {submariner_full_url}"
jq_cmd1 = (
'jq -r \'[.raw_messages[].msg | select(.pipeline.status=="complete") |'
"{{nvr: .artifact.nvr, index_image: .pipeline.index_image}}] | .[0]'"
)

jq_cmd2 = "jq -r '.index_image.\"v4.14\"'"
cut_cmd1 = "cut -d'/' -f3-"
cut_cmd2 = "cut -d':' -f2-"
cmd_exec = chained_subprocess_pipes(
[curl_cmd, jq_cmd1, jq_cmd2, cut_cmd1, cut_cmd2]
)
version_tag = cmd_exec.communicate()[0].decode()

image_url = submariner_downstream_unreleased["spec"]["image"]
image_url = image_url.replace("PLACE_HOLDER", version_tag)
submariner_downstream_unreleased["spec"]["image"] = image_url
submariner_data_yaml = tempfile.NamedTemporaryFile(
mode="w+", prefix="submariner_downstream_unreleased", delete=False
)
templating.dump_data_to_temp_yaml(
submariner_downstream_unreleased, submariner_data_yaml
)
old_ctx = config.cur_index
for cluster in get_non_acm_cluster_config():
config.switch_ctx(cluster.MULTICLUSTER["multicluster_index"])
run_cmd(f"oc create -f {submariner_data_yaml.name}", timeout=300)
config.switch_ctx(old_ctx)

cluster_name_a = cluster_env.get(f"cluster_name_{primary_index}")
cluster_name_b = cluster_env.get(f"cluster_name_{secondary_index}")
Expand Down Expand Up @@ -239,6 +282,8 @@ def install_submariner_ui(self, globalnet=True):
check_globalnet == constants.GLOBALNET_STATUS
), "Globalnet was not enabled"
log.info("Globalnet is enabled")
# TODO: Use custom submariner sucscription from UI in case of downstream unreleased submariner

self.take_screenshot()
log.info("Click on 'Install'")
self.do_click(self.page_nav["install-btn"])
Expand Down
13 changes: 13 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@
)
MDR_BACKUP_SCHEDULE_RESOURCE = "schedule-acm"


# DR constants
SUBMARINER_DOWNLOAD_URL = "https://get.submariner.io"
DR_DEFAULT_NAMESPACE = "openshift-dr-systems"
Expand Down Expand Up @@ -2067,6 +2068,15 @@
SUBMARINER_GATEWAY_ACTIVE_LABEL = "gateway.submariner.io/status=active"
SUBMARINER_GATEWAY_NODE_LABEL = "submariner.io/gateway=true"
GLOBALNET_STATUS = "True"
SUBMARINER_DOWNSTREAM_UNRELEASED = os.path.join(
TEMPLATE_MULTICLUSTER_DIR, "submariner_downstream_unreleased_catsrc.yaml"
)
# We need to append version string at the end of this url
SUBMARINER_DOWNSTREAM_UNRELEASED_BUILD_URL = (
"https://datagrepper.engineering.redhat.com/raw?topic=/topic/"
"VirtualTopic.eng.ci.redhat-container-image.pipeline.complete"
"&rows_per_page=25&delta=1296000&contains=submariner-operator-bundle-container-v"
)

# Multicluster related

Expand Down Expand Up @@ -2100,6 +2110,9 @@
ACM_HUB_UNRELEASED_ICSP_YAML = os.path.join(
TEMPLATE_DIR, "acm-deployment", "imagecontentsourcepolicy.yaml"
)
ACM_DOWNSTREAM_BREW_ICSP = os.path.join(
TEMPLATE_DIR, "acm-deployment", "acm_downstream_brew_icsp.yaml"
)
ACM_HUB_UNRELEASED_PULL_SECRET_TEMPLATE = "pull-secret.yaml.j2"
ACM_ODF_MULTICLUSTER_ORCHESTRATOR_RESOURCE = "odf-multicluster-orchestrator"
ACM_ODR_HUB_OPERATOR_RESOURCE = "odr-hub-operator"
Expand Down
18 changes: 18 additions & 0 deletions ocs_ci/templates/acm-deployment/acm_downstream_brew_icsp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: operator.openshift.io/v1alpha1
kind: ImageContentSourcePolicy
metadata:
name: brew-registry
spec:
repositoryDigestMirrors:
- mirrors:
- brew.registry.redhat.io
source: registry.redhat.io
- mirrors:
- brew.registry.redhat.io/rhacm2
source: registry.redhat.io/rhacm2
- mirrors:
- brew.registry.redhat.io
source: registry.stage.redhat.io
- mirrors:
- brew.registry.redhat.io
source: registry-proxy.engineering.redhat.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: submariner-catalogsource
namespace: openshift-marketplace
spec:
icon:
base64data: ""
mediatype: ""
image: brew.registry.redhat.io/rh-osbs/iib:PLACE_HOLDER
publisher: Red Hat
sourceType: grpc
priority: 100
updateStrategy:
registryPoll:
interval: 15m
27 changes: 27 additions & 0 deletions ocs_ci/utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4524,3 +4524,30 @@ def get_oadp_version():
if "oadp-operator" in csv["metadata"]["name"]:
# extract version string
return csv["spec"]["version"]


def chained_subprocess_pipes(cmd_list):
"""
We can use this function wherever we have chain of commands which
need to be piped. Direct shell piping has some parsing issues hence implementing
this using subprocess output redirections which mimics shell pipes.
Commands will be run as per the command ordering inside the list and output of
each command will be fed as input to the next command in the list
Args:
cmd_list (list): list of commands to be run whose output need to be piped
Returns:
Popen object of the last command executed
"""
pipe_buf = None
for cmd in cmd_list:
if not pipe_buf:
pipe_buf = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE)
else:
pipe_buf = subprocess.Popen(
shlex.split(cmd), stdin=pipe_buf.stdout, stdout=subprocess.PIPE
)
return pipe_buf

0 comments on commit 4c5cbd0

Please sign in to comment.