Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.17] Move awscli pod CA setup related commands to container startup #10984

Open
wants to merge 1 commit into
base: release-4.17
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions ocs_ci/ocs/awscli_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def create_awscli_pod(scope_name=None, namespace=None, service_account=None):
awscli_sts_dict["metadata"]["namespace"] = namespace
update_container_with_mirrored_image(awscli_sts_dict)
update_container_with_proxy_env(awscli_sts_dict)
_add_startup_commands_to_set_ca(awscli_sts_dict)

s3cli_sts_obj = create_resource(**awscli_sts_dict)

log.info("Verifying the AWS CLI StatefulSet is running")
Expand All @@ -73,16 +75,6 @@ def create_awscli_pod(scope_name=None, namespace=None, service_account=None):
)()
wait_for_resource_state(awscli_pod_obj, constants.STATUS_RUNNING, timeout=180)

awscli_pod_obj.exec_cmd_on_pod(
f"cp {constants.SERVICE_CA_CRT_AWSCLI_PATH} {constants.AWSCLI_CA_BUNDLE_PATH}"
)

if storagecluster_independent_check() and config.EXTERNAL_MODE.get("rgw_secure"):
log.info("Concatenating the RGW CA to the AWS CLI pod's CA bundle")
awscli_pod_obj.exec_cmd_on_pod(
f"bash -c 'wget -O - {config.EXTERNAL_MODE['rgw_cert_ca']} >> {constants.AWSCLI_CA_BUNDLE_PATH}'"
)

return awscli_pod_obj


Expand Down Expand Up @@ -118,3 +110,34 @@ def awscli_pod_cleanup(namespace=None):
)
if awscli_service_ca_query:
ocp_cm.delete(resource_name=awscli_service_ca_query[0]["metadata"]["name"])


def _add_startup_commands_to_set_ca(awscli_sts_dict):
"""
Add container startup commands to ensure the CA is at the expected location

Args:
awscli_sts_dict (dict): The AWS CLI StatefulSet dict to modify
"""
startup_cmds = []

# Copy the CA cert to the expected location
startup_cmds.append(
f"cp {constants.SERVICE_CA_CRT_AWSCLI_PATH} {constants.AWSCLI_CA_BUNDLE_PATH}"
)

# Download and concatenate an additional CA cert if needed
if storagecluster_independent_check() and config.EXTERNAL_MODE.get("rgw_secure"):
startup_cmds.append(
f"wget -O - {config.EXTERNAL_MODE['rgw_cert_ca']} >> {constants.AWSCLI_CA_BUNDLE_PATH}"
)

# Keep the pod running after the commands
startup_cmds.append("sleep infinity")

# Set the commands to run on pod startup
awscli_sts_dict["spec"]["template"]["spec"]["containers"][0]["command"] = [
"/bin/sh",
"-c",
" && ".join(startup_cmds),
]
Loading