99from azure .cli .core .azclierror import RequiredArgumentMissingError , InvalidArgumentValueError
1010
1111from .DefaultExtension import DefaultExtension
12- from .._client_factory import cf_storage , cf_managed_clusters
12+ from .._client_factory import cf_managed_clusters
1313from ..vendored_sdks .models import (Extension , PatchExtension , Scope , ScopeCluster )
1414
1515logger = get_logger (__name__ )
@@ -20,13 +20,16 @@ def __init__(self):
2020 """Constants for configuration settings
2121 - Tenant Id (required)
2222 - Backup storage location (required)
23+ - Resource Requests (optional)
2324 - Resource Limits (optional)
2425 """
2526 self .TENANT_ID = "credentials.tenantId"
2627 self .BACKUP_STORAGE_ACCOUNT_CONTAINER = "configuration.backupStorageLocation.bucket"
2728 self .BACKUP_STORAGE_ACCOUNT_NAME = "configuration.backupStorageLocation.config.storageAccount"
2829 self .BACKUP_STORAGE_ACCOUNT_RESOURCE_GROUP = "configuration.backupStorageLocation.config.resourceGroup"
2930 self .BACKUP_STORAGE_ACCOUNT_SUBSCRIPTION = "configuration.backupStorageLocation.config.subscriptionId"
31+ self .RESOURCE_REQUEST_CPU = "resources.requests.cpu"
32+ self .RESOURCE_REQUEST_MEMORY = "resources.requests.memory"
3033 self .RESOURCE_LIMIT_CPU = "resources.limits.cpu"
3134 self .RESOURCE_LIMIT_MEMORY = "resources.limits.memory"
3235 self .BACKUP_STORAGE_ACCOUNT_USE_AAD = "configuration.backupStorageLocation.config.useAAD"
@@ -36,6 +39,8 @@ def __init__(self):
3639 self .storage_account = "storageAccount"
3740 self .storage_account_resource_group = "storageAccountResourceGroup"
3841 self .storage_account_subscription = "storageAccountSubscriptionId"
42+ self .cpu_request = "cpuRequest"
43+ self .memory_request = "memoryRequest"
3944 self .cpu_limit = "cpuLimit"
4045 self .memory_limit = "memoryLimit"
4146 self .use_aad = "useAAD"
@@ -46,6 +51,8 @@ def __init__(self):
4651 self .storage_account .lower (): self .BACKUP_STORAGE_ACCOUNT_NAME ,
4752 self .storage_account_resource_group .lower (): self .BACKUP_STORAGE_ACCOUNT_RESOURCE_GROUP ,
4853 self .storage_account_subscription .lower (): self .BACKUP_STORAGE_ACCOUNT_SUBSCRIPTION ,
54+ self .cpu_request .lower (): self .RESOURCE_REQUEST_CPU ,
55+ self .memory_request .lower (): self .RESOURCE_REQUEST_MEMORY ,
4956 self .cpu_limit .lower (): self .RESOURCE_LIMIT_CPU ,
5057 self .memory_limit .lower (): self .RESOURCE_LIMIT_MEMORY ,
5158 self .use_aad .lower (): self .BACKUP_STORAGE_ACCOUNT_USE_AAD ,
@@ -83,7 +90,7 @@ def Create(
8390 plan_publisher ,
8491 plan_product ,
8592 ):
86- # Current scope of DataProtection Kubernetes Backup extension is 'cluster' #TODO: add TSGs when they are in place
93+ # Current scope of DataProtection extension is 'cluster' #TODO: add TSGs when they are in place
8794 if scope == 'namespace' :
8895 raise InvalidArgumentValueError (f"Invalid scope '{ scope } '. This extension can only be installed at 'cluster' scope." )
8996
@@ -106,7 +113,7 @@ def Create(
106113 configuration_settings [self .TENANT_ID ] = tenant_id
107114
108115 if configuration_settings .get (self .BACKUP_STORAGE_ACCOUNT_USE_AAD ) is None :
109- logger .warning ("useAAD flag is not specified. Setting it to 'true'. Please provide extension MSI Storage Blob Data Contributor role to the storage account." )
116+ logger .warning ("useAAD flag is not specified. Setting it to 'true'. Please provide extension MSI Storage Blob Data Contributor role on the storage account." )
110117 configuration_settings [self .BACKUP_STORAGE_ACCOUNT_USE_AAD ] = "true"
111118
112119 if configuration_settings .get (self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ) is None :
@@ -149,18 +156,20 @@ def Update(
149156 self .__validate_and_map_config (configuration_settings , validate_bsl = bsl_specified )
150157 if bsl_specified :
151158 self .__validate_backup_storage_account (cmd .cli_ctx , resource_group_name , cluster_name , configuration_settings )
152- # this step is for brownfield migrating to AAD
159+
160+ # This step is for brownfield migrating to AAD
153161 if configuration_settings .get (self .BACKUP_STORAGE_ACCOUNT_USE_AAD ) is not None and configuration_settings .get (self .BACKUP_STORAGE_ACCOUNT_USE_AAD ).lower () == "true" :
154- logger .warning ("useAAD flag is set to true. Please provide extension MSI Storage Blob Data Contributor role to the storage account." )
162+ logger .warning ("useAAD flag is set to true. Please provide extension MSI Storage Blob Data Contributor role on the storage account." )
155163
156164 if configuration_settings .get (self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ) is None :
157- # SA details provided in user inputs, but did not provide SA URI.
158- logger .warning ("storageAccountURI is not populated. Setting it to the storage account URI of provided storage account" )
165+ # SA details provided in user input, but did not provide SA URI.
159166 if bsl_specified :
167+ logger .warning ("storageAccountURI is not populated. Setting it to the storage account URI of provided storage account." )
160168 configuration_settings [self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ] = self .__get_storage_account_uri (cmd .cli_ctx , configuration_settings )
161169 logger .warning (f"storageAccountURI: { configuration_settings [self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ]} " )
162170 # SA details not provided in user input, SA Uri not provided in user input, and also not populated in the original extension, we populate it.
163171 elif not bsl_specified and original_extension .configuration_settings .get (self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ) is None :
172+ logger .warning ("storageAccountURI is not populated. Setting it to the storage account URI of the storage account provided during extension installation." )
164173 configuration_settings [self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ] = self .__get_storage_account_uri (cmd .cli_ctx , original_extension .configuration_settings )
165174 logger .warning (f"storageAccountURI: { configuration_settings [self .BACKUP_STORAGE_ACCOUNT_STORAGE_ACCOUNT_URI ]} " )
166175
@@ -177,7 +186,7 @@ def __get_tenant_id(self, cli_ctx):
177186 return cli_ctx .data ['tenant_id' ]
178187
179188 def __validate_and_map_config (self , configuration_settings , validate_bsl = True ):
180- """Validate and set configuration settings for Data Protection K8sBackup extension"""
189+ """Validate and set configuration settings for DataProtection extension"""
181190 input_configuration_settings = dict (configuration_settings .items ())
182191 input_configuration_keys = [key .lower () for key in configuration_settings ]
183192
@@ -189,14 +198,14 @@ def __validate_and_map_config(self, configuration_settings, validate_bsl=True):
189198 for key in input_configuration_settings :
190199 _key = key .lower ()
191200 if _key in self .configuration_mapping :
192- configuration_settings [self .configuration_mapping [_key ]] = configuration_settings .pop (key )
201+ configuration_settings [self .configuration_mapping [_key ]] = configuration_settings .pop (key ). strip ()
193202 else :
194203 configuration_settings .pop (key )
195204 logger .warning (f"Ignoring unrecognized configuration setting: { key } " )
196205
197206 def __validate_backup_storage_account (self , cli_ctx , resource_group_name , cluster_name , configuration_settings ):
198207 """Validations performed on the backup storage account
199- - Existance of the storage account
208+ - Existence of the storage account
200209 - Cluster and storage account are in the same location
201210 """
202211 storage_account = self .__get_storage_account (cli_ctx , configuration_settings )
0 commit comments