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

Add zones to ibm cloud ipi #9780

Merged
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions conf/deployment/ibmcloud/ipi_1az_us_east1_rhcos_3m_3w.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
DEPLOYMENT:
openshift_install_timeout: 4800
allow_lower_instance_requirements: false
ENV_DATA:
platform: 'ibm_cloud'
deployment_type: 'ipi'
region: 'us-east'
base_domain: 'ibmcloud2.qe.rh-ocs.com'
worker_instance_type: 'bx2-16x64'
master_instance_type: 'bx2-4x16'
worker_availability_zones:
- 'us-east-1'
master_availability_zones:
- 'us-east-1'
worker_replicas: 3
master_replicas: 3

# The following values need to be set in a separate config and passed to ocs-ci in
# order to deploy OCP/OCS cluster on IBM Cloud using IPI.
#
#AUTH:
# ibmcloud:
# account_id: ACCOUNT ID PLACEHOLDER
# api_key: IBM CLOUD API KEY PLACEHOLDER
25 changes: 25 additions & 0 deletions conf/deployment/ibmcloud/ipi_1az_us_east2_rhcos_3m_3w.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
DEPLOYMENT:
openshift_install_timeout: 4800
allow_lower_instance_requirements: false
ENV_DATA:
platform: 'ibm_cloud'
deployment_type: 'ipi'
region: 'us-east'
base_domain: 'ibmcloud2.qe.rh-ocs.com'
worker_instance_type: 'bx2-16x64'
worker_availability_zones:
- 'us-east-2'
master_instance_type: 'bx2-4x16'
master_availability_zones:
- 'us-east-2'
worker_replicas: 3
master_replicas: 3

# The following values need to be set in a separate config and passed to ocs-ci in
# order to deploy OCP/OCS cluster on IBM Cloud using IPI.
#
#AUTH:
# ibmcloud:
# account_id: ACCOUNT ID PLACEHOLDER
# api_key: IBM CLOUD API KEY PLACEHOLDER
25 changes: 25 additions & 0 deletions conf/deployment/ibmcloud/ipi_1az_us_east3_rhcos_3m_3w.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
DEPLOYMENT:
openshift_install_timeout: 4800
allow_lower_instance_requirements: false
ENV_DATA:
platform: 'ibm_cloud'
deployment_type: 'ipi'
region: 'us-east'
base_domain: 'ibmcloud2.qe.rh-ocs.com'
worker_instance_type: 'bx2-16x64'
worker_availability_zones:
- 'us-east-3'
master_instance_type: 'bx2-4x16'
master_availability_zones:
- 'us-east-3'
worker_replicas: 3
master_replicas: 3

# The following values need to be set in a separate config and passed to ocs-ci in
# order to deploy OCP/OCS cluster on IBM Cloud using IPI.
#
#AUTH:
# ibmcloud:
# account_id: ACCOUNT ID PLACEHOLDER
# api_key: IBM CLOUD API KEY PLACEHOLDER
1 change: 1 addition & 0 deletions conf/deployment/ibmcloud/ipi_3az_rhcos_3m_3w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ENV_DATA:
region: 'us-east'
base_domain: 'ibmcloud2.qe.rh-ocs.com'
worker_instance_type: 'bx2-16x64'
master_instance_type: 'bx2-4x16'
worker_availability_zones:
- 'us-east-1'
- 'us-east-2'
Expand Down
1 change: 1 addition & 0 deletions conf/deployment/ibmcloud/ipi_3az_rhcos_3m_6w.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ENV_DATA:
- 'us-south-1'
- 'us-south-2'
- 'us-south-3'
master_instance_type: 'bx2-4x16'
master_availability_zones:
- 'us-south-1'
- 'us-south-2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ENV_DATA:
deployment_type: 'ipi'
region: 'us-south'
base_domain: 'ibmcloud2.qe.rh-ocs.com'
master_instance_type: 'bx2-4x16'
worker_instance_type: 'bx2-8x32'
worker_availability_zones:
- 'us-south-1'
Expand Down
22 changes: 14 additions & 8 deletions ocs_ci/deployment/ibmcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ocs_ci.deployment.ocp import OCPDeployment as BaseOCPDeployment
from ocs_ci.framework import config
from ocs_ci.ocs import constants
from ocs_ci.ocs.defaults import IBM_CLOUD_LOAD_BALANCER_QUOTA
from ocs_ci.ocs.defaults import IBM_CLOUD_REGIONS
from ocs_ci.ocs.exceptions import (
CommandFailed,
UnsupportedPlatformVersionError,
Expand Down Expand Up @@ -162,14 +162,17 @@ def deploy_ocp(self, log_cli_level="DEBUG"):
# switch to us-south, if current load balancers are more than 45.
# https://cloud.ibm.com/docs/vpc?topic=vpc-quotas
ibmcloud.login()
current_region = config.ENV_DATA["region"]
other_region = list(IBM_CLOUD_REGIONS - {current_region})[0]
if config.ENV_DATA.get("enable_region_dynamic_switching"):
lb_count = self.get_load_balancers_count()
if lb_count > (IBM_CLOUD_LOAD_BALANCER_QUOTA - 5):
current_region_lb_count = self.get_load_balancers_count()
ibmcloud.login(region=other_region)
other_region_lb_count = self.get_load_balancers_count(other_region)
if current_region_lb_count > other_region_lb_count:
logger.info(
"Switching region to us-south due to lack of load balancers"
f"Switching region to {other_region} due to lack of load balancers"
)
config.ENV_DATA["region"] = "us-south"
ibmcloud.login()
ibmcloud.set_region(other_region)
self.ocp_deployment = self.OCPDeployment()
self.ocp_deployment.deploy_prereq()

Expand Down Expand Up @@ -479,16 +482,19 @@ def get_load_balancers(self):
logger.debug(f"load balancers: {load_balancers}")
return load_balancers

def get_load_balancers_count(self):
def get_load_balancers_count(self, region=None):
"""
Gets the number of load balancers

Args:
region (str): region (e.g. us-south), if not defined it will take from config.
Return:
int: number of load balancers

"""
load_balancers_count = len(self.get_load_balancers())
region = config.ENV_DATA.get("region")
if not region:
region = config.ENV_DATA.get("region")
logger.info(
f"Current load balancers count in region {region} is {load_balancers_count}"
)
Expand Down
1 change: 1 addition & 0 deletions ocs_ci/ocs/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@

# IBM Cloud
IBM_CLOUD_LOAD_BALANCER_QUOTA = 50
IBM_CLOUD_REGIONS = {"us-south", "us-east"}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ compute:
platform:
ibmcloud:
type: {{ worker_instance_type | default('bx2-16x64') }}
{% if worker_availability_zones %}
zones:
{% for zone in worker_availability_zones %}
- {{ zone }}
{% endfor %}
{% endif %}
replicas: {{ worker_replicas | default(3) }}
controlPlane:
architecture: amd64
hyperthreading: Enabled
name: master
platform:
ibmcloud: {}
ibmcloud:
type: {{ master_instance_type | default('bx2-4x16') }}
{% if master_availability_zones %}
zones:
{% for zone in master_availability_zones %}
- {{ zone }}
{% endfor %}
{% endif %}
replicas: {{ master_replicas | default(3) }}
metadata:
creationTimestamp: null
Expand Down
29 changes: 25 additions & 4 deletions ocs_ci/utility/ibmcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import re
import requests
import time
from copy import copy
from json import JSONDecodeError
from ocs_ci.framework import config
from ocs_ci.ocs import constants
from ocs_ci.ocs.defaults import IBM_CLOUD_REGIONS
from ocs_ci.ocs.exceptions import (
APIRequestError,
CommandFailed,
Expand All @@ -30,9 +32,12 @@
ibm_config = config.AUTH.get("ibmcloud", {})


def login():
def login(region=None):
"""
Login to IBM Cloud cluster

Args:
region (str): region to log in, if not specified it will use one from config
"""
api_key = ibm_config["api_key"]
login_cmd = f"ibmcloud login --apikey {api_key}"
Expand All @@ -42,7 +47,8 @@ def login():
api_endpoint = ibm_config.get("api_endpoint")
if api_endpoint:
login_cmd += f" -a {api_endpoint}"
region = config.ENV_DATA.get("region")
if not region:
region = config.ENV_DATA.get("region")
if region:
login_cmd += f" -r {region}"
logger.info("Logging to IBM cloud")
Expand All @@ -51,17 +57,32 @@ def login():
config.RUN["ibmcloud_last_login"] = time.time()


def set_region():
def set_region(region=None):
"""
Sets the cluster region to ENV_DATA when enable_region_dynamic_switching is
enabled.

Args:
region (str): region to set, if not defined it will try to get from metadata.json

"""
if not config.ENV_DATA.get("enable_region_dynamic_switching"):
return
region = get_region(config.ENV_DATA["cluster_path"])
if not region:
region = get_region(config.ENV_DATA["cluster_path"])
logger.info(f"cluster region is {region}")
logger.info(f"updating region {region} to ENV_DATA ")
config.ENV_DATA["region"] = region
other_region = list(IBM_CLOUD_REGIONS - {region})[0]
for node_type in ["master", "worker"]:
for idx, zone in enumerate(
copy(config.ENV_DATA.get(f"{node_type}_availability_zones", []))
):
config.ENV_DATA[f"{node_type}_availability_zones"][idx] = zone.replace(
other_region, region
)
# Make sure we are logged in proper region from config, once region changed!
login()


def get_region(cluster_path):
Expand Down
Loading