-
Notifications
You must be signed in to change notification settings - Fork 171
Refactor determination of storageclass for deployments #12042
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
Open
clacroix12
wants to merge
2
commits into
red-hat-storage:master
Choose a base branch
from
clacroix12:storage-class-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import logging | ||
import yaml | ||
|
||
from ocs_ci.framework import config | ||
from ocs_ci.framework.logger_helper import log_step | ||
from ocs_ci.ocs import constants | ||
from ocs_ci.utility.utils import run_cmd | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
DEFAULT_STORAGE_CLASS_MAP = { | ||
constants.AWS_PLATFORM: "gp2-csi", | ||
constants.IBMCLOUD_PLATFORM: "ibmc-vpc-block-10iops-tier", | ||
constants.VSPHERE_PLATFORM: "thin-csi", | ||
constants.AZURE_PLATFORM: "managed-csi", | ||
constants.GCP_PLATFORM: None, | ||
constants.ROSA_HCP_PLATFORM: None, | ||
constants.RHV_PLATFORM: "ovirt-csi-sc", | ||
} | ||
|
||
|
||
def get_storageclass() -> str: | ||
""" | ||
Retrieve the storageclass to use from the config or based on platform | ||
|
||
Returns: | ||
str: Name of the storageclass | ||
|
||
""" | ||
logger.info("Getting storageclass") | ||
platform = config.ENV_DATA.get("platform") | ||
customized_deployment_storage_class = config.DEPLOYMENT.get( | ||
"customized_deployment_storage_class" | ||
) | ||
|
||
if customized_deployment_storage_class: | ||
storage_class = customized_deployment_storage_class | ||
else: | ||
storage_class = DEFAULT_STORAGE_CLASS_MAP[platform] | ||
|
||
logger.info(f"Using storage class: {storage_class}") | ||
return storage_class | ||
|
||
|
||
def create_custom_storageclass(storage_class_path: str) -> str: | ||
""" | ||
Create a custom storageclass using the yaml file defined at the storage_class_path | ||
|
||
Args: | ||
storage_class_path (str): Filepath to storageclass yaml definition | ||
|
||
Returns: | ||
str: Name of the storageclass | ||
|
||
""" | ||
with open(storage_class_path, "r") as custom_sc_fo: | ||
custom_sc = yaml.load(custom_sc_fo, Loader=yaml.SafeLoader) | ||
|
||
storage_class_name = custom_sc["metadata"]["name"] | ||
log_step(f"Creating custom storage class {storage_class_name}") | ||
run_cmd(f"oc create -f {storage_class_path}") | ||
|
||
return storage_class_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
thin-csi
value is also available asconstants.THIN_CSI_STORAGECLASS
, but I'm not sure, if it is worth to change all the values and get them from constants, so maybe as it is now is ok.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that as well and came to the same conclusion. I didn't think it was necessary to convert them each to their own constant. If you think it's worth it to move the map to the constants module I can do that, but for now I will leave it as is.