Skip to content

Commit

Permalink
Set default timeout to 60m and restructure code (#145)
Browse files Browse the repository at this point in the history
* arrange code

* arrange code

* arrange code
  • Loading branch information
rnetser authored Sep 6, 2023
1 parent d7f6138 commit cd4c0f5
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 190 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Every call to the openshift installer cli must have at least one `--cluster` opt
* region: The region to deploy the cluster
* Optional parameters:
* Parameter names should be separated by semicolons (`;`)
* To set cluster create / destroy timeout, pass `--cluster ...timeout=1h'`; default is 30 minutes.
* To set cluster create / destroy timeout (not applicable for AWS IPI clusters), pass `--cluster ...timeout=1h'`; default is 60 minutes.
* `timeout` and `expiration-time` format examples: `1h`, `30m`, `3600s`
* `ocm-env`: OCM environment to deploy the cluster; available options: `stage` or `production` (defaults to `stage`). AWS-IPI clusters only use `production`.
* AWS IPI:
Expand Down
30 changes: 16 additions & 14 deletions openshift_cli_installer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@
import rosa.cli
from clouds.aws.aws_utils import set_and_verify_aws_credentials

from openshift_cli_installer.libs.aws_ipi_clusters import (
create_install_config_file,
create_or_destroy_aws_ipi_cluster,
download_openshift_install_binary,
update_aws_clusters_versions,
)
from openshift_cli_installer.libs.destroy_clusters import destroy_clusters
from openshift_cli_installer.libs.osd_clusters import (
from openshift_cli_installer.libs.managed_clusters.helpers import (
prepare_managed_clusters_data,
)
from openshift_cli_installer.libs.managed_clusters.osd_clusters import (
osd_create_cluster,
osd_delete_cluster,
)
from openshift_cli_installer.libs.rosa_clusters import (
prepare_managed_clusters_data,
from openshift_cli_installer.libs.managed_clusters.rosa_clusters import (
rosa_create_cluster,
rosa_delete_cluster,
)
from openshift_cli_installer.libs.unmanaged_clusters.aws_ipi_clusters import (
create_install_config_file,
create_or_destroy_aws_ipi_cluster,
download_openshift_install_binary,
update_aws_clusters_versions,
)
from openshift_cli_installer.utils.click_dict_type import DictParamType
from openshift_cli_installer.utils.clusters import (
add_ocm_client_to_cluster_dict,
check_existing_clusters,
update_rosa_osd_clusters_versions,
)
from openshift_cli_installer.utils.const import (
AWS_OSD_STR,
AWS_STR,
Expand All @@ -34,11 +41,6 @@
ROSA_STR,
STAGE_STR,
)
from openshift_cli_installer.utils.helpers import (
add_ocm_client_to_cluster_dict,
check_existing_clusters,
update_rosa_osd_clusters_versions,
)


def get_clusters_by_type(clusters):
Expand Down
6 changes: 4 additions & 2 deletions openshift_cli_installer/libs/destroy_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import yaml
from clouds.aws.session_clients import s3_client

from openshift_cli_installer.libs.aws_ipi_clusters import (
from openshift_cli_installer.libs.managed_clusters.rosa_clusters import (
rosa_delete_cluster,
)
from openshift_cli_installer.libs.unmanaged_clusters.aws_ipi_clusters import (
create_or_destroy_aws_ipi_cluster,
download_openshift_install_binary,
)
from openshift_cli_installer.libs.rosa_clusters import rosa_delete_cluster
from openshift_cli_installer.utils.const import (
AWS_STR,
CLUSTER_DATA_YAML_FILENAME,
Expand Down
Empty file.
33 changes: 33 additions & 0 deletions openshift_cli_installer/libs/managed_clusters/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from datetime import datetime, timedelta

from openshift_cli_installer.utils.const import HYPERSHIFT_STR, TIMEOUT_60MIN
from openshift_cli_installer.utils.general import tts


def prepare_managed_clusters_data(
clusters,
aws_account_id,
aws_secret_access_key,
aws_access_key_id,
):
for _cluster in clusters:
_cluster["cluster-name"] = _cluster["name"]
_cluster["timeout"] = tts(ts=_cluster.get("timeout", TIMEOUT_60MIN))
_cluster["channel-group"] = _cluster.get("channel-group", "stable")
_cluster["aws-access-key-id"] = aws_access_key_id
_cluster["aws-secret-access-key"] = aws_secret_access_key
_cluster["aws-account-id"] = aws_account_id
_cluster["multi-az"] = _cluster.get("multi-az", False)
if _cluster["platform"] == HYPERSHIFT_STR:
_cluster["hosted-cp"] = "true"
_cluster["tags"] = "dns:external"
_cluster["machine-cidr"] = _cluster.get("cidr", "10.0.0.0/16")

expiration_time = _cluster.get("expiration-time")
if expiration_time:
_expiration_time = tts(ts=expiration_time)
_cluster["expiration-time"] = (
f"{(datetime.now() + timedelta(seconds=_expiration_time)).isoformat()}Z"
)

return clusters
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
from ocm_python_wrapper.cluster import Cluster

from openshift_cli_installer.utils.helpers import (
from openshift_cli_installer.utils.clusters import (
add_cluster_info_to_cluster_data,
dump_cluster_data_to_file,
set_cluster_auth,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import os
import re
import shutil
from datetime import datetime, timedelta

import click
import rosa.cli
import yaml
from ocm_python_wrapper.cluster import Cluster
from python_terraform import IsNotFlagged, Terraform, TerraformCommandError

from openshift_cli_installer.utils.clusters import (
add_cluster_info_to_cluster_data,
cluster_shortuuid,
dump_cluster_data_to_file,
set_cluster_auth,
)
from openshift_cli_installer.utils.const import (
CLUSTER_DATA_YAML_FILENAME,
HYPERSHIFT_STR,
)
from openshift_cli_installer.utils.helpers import (
add_cluster_info_to_cluster_data,
from openshift_cli_installer.utils.general import (
bucket_object_name,
cluster_shortuuid,
dump_cluster_data_to_file,
get_manifests_path,
set_cluster_auth,
tts,
zip_and_upload_to_s3,
)

Expand Down Expand Up @@ -138,35 +138,6 @@ def prepare_hypershift_vpc(cluster_data):
raise


def prepare_managed_clusters_data(
clusters,
aws_account_id,
aws_secret_access_key,
aws_access_key_id,
):
for _cluster in clusters:
_cluster["cluster-name"] = _cluster["name"]
_cluster["timeout"] = tts(ts=_cluster.get("timeout", "30m"))
_cluster["channel-group"] = _cluster.get("channel-group", "stable")
_cluster["aws-access-key-id"] = aws_access_key_id
_cluster["aws-secret-access-key"] = aws_secret_access_key
_cluster["aws-account-id"] = aws_account_id
_cluster["multi-az"] = _cluster.get("multi-az", False)
if _cluster["platform"] == HYPERSHIFT_STR:
_cluster["hosted-cp"] = "true"
_cluster["tags"] = "dns:external"
_cluster["machine-cidr"] = _cluster.get("cidr", "10.0.0.0/16")

expiration_time = _cluster.get("expiration-time")
if expiration_time:
_expiration_time = tts(ts=expiration_time)
_cluster["expiration-time"] = (
f"{(datetime.now() + timedelta(seconds=_expiration_time)).isoformat()}Z"
)

return clusters


def rosa_create_cluster(cluster_data, s3_bucket_name=None, s3_bucket_path=None):
hosted_cp_arg = "--hosted-cp"
_platform = cluster_data["platform"]
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from ocp_utilities.utils import run_command

from openshift_cli_installer.utils.cluster_versions import set_clusters_versions
from openshift_cli_installer.utils.const import CREATE_STR, DESTROY_STR
from openshift_cli_installer.utils.helpers import (
from openshift_cli_installer.utils.clusters import (
add_cluster_info_to_cluster_data,
bucket_object_name,
cluster_shortuuid,
dump_cluster_data_to_file,
)
from openshift_cli_installer.utils.const import CREATE_STR, DESTROY_STR
from openshift_cli_installer.utils.general import (
bucket_object_name,
get_manifests_path,
get_ocm_client,
zip_and_upload_to_s3,
)

Expand Down Expand Up @@ -229,12 +230,3 @@ def get_all_versions(_test=None):
base_available_versions = get_aws_versions()

return base_available_versions


def prepare_base_aws_cluster_data(aws_ipi_clusters, ocm_token):
for _cluster in aws_ipi_clusters:
_cluster["ocm-client"] = get_ocm_client(
ocm_token=ocm_token, ocm_env=_cluster["ocm_env"]
)

return aws_ipi_clusters
6 changes: 4 additions & 2 deletions openshift_cli_installer/tests/test_cluster_version.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import click
import pytest

from openshift_cli_installer.libs.aws_ipi_clusters import update_aws_clusters_versions
from openshift_cli_installer.libs.unmanaged_clusters.aws_ipi_clusters import (
update_aws_clusters_versions,
)
from openshift_cli_installer.tests.all_osd_versions import (
BASE_AVAILABLE_OSD_VERSIONS_DICT,
)
from openshift_cli_installer.tests.all_rosa_versions import (
BASE_AVAILABLE_ROSA_VERSIONS_DICT,
)
from openshift_cli_installer.utils.helpers import update_rosa_osd_clusters_versions
from openshift_cli_installer.utils.clusters import update_rosa_osd_clusters_versions


@pytest.mark.parametrize(
Expand Down
Loading

0 comments on commit cd4c0f5

Please sign in to comment.