Skip to content

Commit d90dc34

Browse files
authored
[ACR] az acr connected-registry create/update: Add new parameters for enabling and setting interval for garbage collection within a connected registry (#30956)
1 parent f4beaf3 commit d90dc34

File tree

5 files changed

+1929
-1423
lines changed

5 files changed

+1929
-1423
lines changed

src/azure-cli/azure/cli/command_modules/acr/_client_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ def cf_acr_agentpool(cli_ctx, *_):
8282

8383

8484
def cf_acr_connected_registries(cli_ctx, *_):
85-
return get_acr_service_client(cli_ctx, VERSION_2021_08_01_PREVIEW).connected_registries
85+
return get_acr_service_client(cli_ctx, VERSION_2024_11_01_PREVIEW).connected_registries

src/azure-cli/azure/cli/command_modules/acr/_params.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
551551
c.argument('sync_schedule', options_list=['--sync-schedule', '-s'], help='Optional parameter to define the sync schedule. Uses cron expression to determine the schedule. If not specified, the instance is considered always online and attempts to sync every minute.', required=False, default="* * * * *")
552552
c.argument('sync_message_ttl', help='Determine how long the sync messages will be kept in the cloud. Uses ISO 8601 duration format.', required=False, default="P2D")
553553
c.argument('notifications', options_list=['--notifications'], nargs='+', help='List of artifact pattern for which notifications need to be generated. Use the format "--notifications [PATTERN1 PATTERN2 ...]".')
554+
c.argument('garbage_collection_enabled', options_list=['--gc-enabled'],
555+
help='Indicate whether garbage collection is enabled. It is enabled by default.', arg_type=get_three_state_flag(), required=False, default="true")
556+
c.argument('garbage_collection_schedule', options_list=['--gc-schedule'],
557+
help='Used to determine garbage collection schedule. Uses cron expression to determine the schedule. If not specified, garbage collection is set to run once a day.', required=False, default="0 0 * * *")
554558

555559
with self.argument_context('acr connected-registry update') as c:
556560
c.argument('log_level', help='Set the log level for logging on the instance. Accepted log levels are Debug, Information, Warning, Error, and None.')
@@ -565,7 +569,9 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
565569
help='List of artifact pattern to be added to notifications list. Use the format "--add-notifications [PATTERN1 PATTERN2 ...]".')
566570
c.argument('remove_notifications', options_list=['--remove-notifications'], nargs='*',
567571
help='List of artifact pattern to be removed from notifications list. Use the format "--remove-notifications [PATTERN1 PATTERN2 ...]".')
568-
572+
c.argument('garbage_collection_enabled', options_list=['--gc-enabled'],
573+
help='Indicate whether garbage collection is enabled. It is enabled by default.', arg_type=get_three_state_flag())
574+
c.argument('garbage_collection_schedule', options_list=['--gc-schedule'], help='Used to determine garbage collection schedule. Uses cron expression to determine the schedule. If not specified, garbage collection is set to run once a day.')
569575
with self.argument_context('acr connected-registry permissions') as c:
570576
c.argument('add_repos', options_list=['--add'], nargs='*',
571577
help='repository permissions to be added to the targeted connected registry and it\'s ancestors sync scope maps. Use the format "--add [REPO1 REPO2 ...]" per flag. ' + repo_valid_actions)

src/azure-cli/azure/cli/command_modules/acr/connected_registry.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
6060
log_level=None,
6161
sync_audit_logs_enabled=False,
6262
notifications=None,
63+
garbage_collection_enabled=None,
64+
garbage_collection_schedule=None,
6365
yes=False):
6466

6567
if bool(sync_token_name) == bool(repositories):
@@ -71,7 +73,7 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
7173
registry, resource_group_name = get_registry_by_name(cmd.cli_ctx, registry_name, resource_group_name)
7274

7375
if not registry.data_endpoint_enabled:
74-
user_confirmation("Dedicated data enpoints must be enabled to use connected-registry. Enabling might " +
76+
user_confirmation("Dedicated data endpoints must be enabled to use connected-registry. Enabling might " +
7577
"impact your firewall rules. Are you sure you want to enable it for '{}' registry?".format(
7678
registry_name), yes)
7779
acr_update_custom(cmd, registry, resource_group_name, data_endpoint_enabled=True)
@@ -111,8 +113,10 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
111113
notifications_set = set(notifications) \
112114
if notifications else set()
113115

114-
ConnectedRegistry, LoggingProperties, SyncProperties, ParentProperties = cmd.get_models(
115-
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties', 'ParentProperties')
116+
ConnectedRegistry, LoggingProperties, SyncProperties, \
117+
ParentProperties, GarbageCollectionProperties = cmd.get_models(
118+
'ConnectedRegistry', 'LoggingProperties', 'SyncProperties',
119+
'ParentProperties', 'GarbageCollectionProperties')
116120
connected_registry_create_parameters = ConnectedRegistry(
117121
provisioning_state=None,
118122
mode=mode,
@@ -130,6 +134,10 @@ def acr_connected_registry_create(cmd, # pylint: disable=too-many-locals, too-m
130134
log_level=log_level,
131135
audit_log_status='Enabled' if sync_audit_logs_enabled else 'Disabled'
132136
),
137+
garbage_collection=GarbageCollectionProperties(
138+
enabled=garbage_collection_enabled,
139+
schedule=garbage_collection_schedule
140+
),
133141
notifications_list=list(notifications_set) if notifications_set else None
134142
)
135143

@@ -155,7 +163,9 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
155163
sync_message_ttl=None,
156164
sync_audit_logs_enabled=None,
157165
add_notifications=None,
158-
remove_notifications=None):
166+
remove_notifications=None,
167+
garbage_collection_enabled=None,
168+
garbage_collection_schedule=None):
159169
_, resource_group_name = validate_managed_registry(
160170
cmd, registry_name, resource_group_name)
161171
subscription_id = get_subscription_id(cmd.cli_ctx)
@@ -211,8 +221,10 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
211221

212222
notifications_list = list(notifications_set) if notifications_set != current_notifications_set else None
213223

214-
ConnectedRegistryUpdateParameters, SyncUpdateProperties, LoggingProperties = cmd.get_models(
215-
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties', 'LoggingProperties')
224+
ConnectedRegistryUpdateParameters, SyncUpdateProperties, \
225+
LoggingProperties, GarbageCollectionProperties = cmd.get_models(
226+
'ConnectedRegistryUpdateParameters', 'SyncUpdateProperties',
227+
'LoggingProperties', 'GarbageCollectionProperties')
216228
connected_registry_update_parameters = ConnectedRegistryUpdateParameters(
217229
sync_properties=SyncUpdateProperties(
218230
schedule=sync_schedule,
@@ -223,6 +235,10 @@ def acr_connected_registry_update(cmd, # pylint: disable=too-many-locals, too-m
223235
log_level=log_level,
224236
audit_log_status=sync_audit_logs_enabled
225237
),
238+
garbage_collection=GarbageCollectionProperties(
239+
enabled=garbage_collection_enabled,
240+
schedule=garbage_collection_schedule
241+
),
226242
client_token_ids=client_token_list,
227243
notifications_list=notifications_list
228244
)

0 commit comments

Comments
 (0)