-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create role assignment for MSI when enable_vnet_integration is true #9153
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
Merged
kairu-ms
merged 8 commits into
Azure:main
from
xmuhammad-xali:alimuhammad/fleet/privfleet-err-msg
Sep 22, 2025
+56
−16
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
72e5c3a
update error message
xmuhammad-xali 8eb2b2c
grant vnet perm
xmuhammad-xali 08a7867
address comments
xmuhammad-xali 5d9f635
setup.py
xmuhammad-xali 283ee3e
update
xmuhammad-xali 19456f6
update style
xmuhammad-xali 735393d
release version block
xmuhammad-xali 54307d2
update
xmuhammad-xali 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 |
|---|---|---|
|
|
@@ -11,14 +11,16 @@ | |
| from azure.cli.core.util import sdk_no_wait, get_file_json, shell_safe_json_parse | ||
|
|
||
| from azext_fleet._client_factory import CUSTOM_MGMT_FLEET | ||
| from azext_fleet._helpers import print_or_merge_credentials | ||
| from azext_fleet._helpers import is_rp_registered, print_or_merge_credentials | ||
| from azext_fleet._helpers import assign_network_contributor_role_to_subnet | ||
| from azext_fleet._helpers import get_msi_object_id | ||
| from azext_fleet.constants import UPGRADE_TYPE_CONTROLPLANEONLY | ||
| from azext_fleet.constants import UPGRADE_TYPE_FULL | ||
| from azext_fleet.constants import UPGRADE_TYPE_NODEIMAGEONLY | ||
| from azext_fleet.constants import UPGRADE_TYPE_ERROR_MESSAGES | ||
| from azext_fleet.constants import SUPPORTED_GATE_STATES_FILTERS | ||
| from azext_fleet.constants import SUPPORTED_GATE_STATES_PATCH | ||
| from azext_fleet.constants import FLEET_1P_APP_ID | ||
|
|
||
|
|
||
| # pylint: disable=too-many-locals | ||
|
|
@@ -90,6 +92,7 @@ def create_fleet(cmd, | |
| resource_type=CUSTOM_MGMT_FLEET, | ||
| operation_group="fleets" | ||
| ) | ||
|
|
||
| managed_service_identity = fleet_managed_service_identity_model(type="None") | ||
| if enable_managed_identity: | ||
| managed_service_identity.type = "SystemAssigned" | ||
|
|
@@ -104,6 +107,11 @@ def create_fleet(cmd, | |
| elif assign_identity is not None: | ||
| raise CLIError("Cannot assign identity without enabling managed identity.") | ||
|
|
||
| if enable_vnet_integration: | ||
| if not enable_managed_identity and assign_identity is None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to _validators.py |
||
| raise CLIError("When vnet integration is enabled, either system-assigned or " | ||
| "user-assigned identity must be provided.") | ||
|
|
||
| fleet = fleet_model( | ||
| location=location, | ||
| tags=tags, | ||
|
|
@@ -112,7 +120,17 @@ def create_fleet(cmd, | |
| ) | ||
|
|
||
| if enable_private_cluster: | ||
| assign_network_contributor_role_to_subnet(cmd, agent_subnet_id) | ||
| # provider registration state being is checked to ensure that the Fleet service principal is available | ||
| # to create the role assignment on the subnet | ||
| if not is_rp_registered(cmd): | ||
| raise CLIError("The Microsoft.ContainerService resource provider is not registered." | ||
| "Run `az provider register -n Microsoft.ContainerService --wait`.") | ||
| assign_network_contributor_role_to_subnet(cmd, FLEET_1P_APP_ID, agent_subnet_id) | ||
|
|
||
| if enable_vnet_integration and assign_identity is not None: | ||
| object_id = get_msi_object_id(cmd, assign_identity) | ||
| assign_network_contributor_role_to_subnet(cmd, object_id, apiserver_subnet_id) | ||
| assign_network_contributor_role_to_subnet(cmd, object_id, agent_subnet_id) | ||
|
|
||
| return sdk_no_wait(no_wait, | ||
| client.begin_create_or_update, | ||
|
|
||
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.
Could you provide a more detailed error? Maybe even ideally to the point at which someone could copy/paste an
az role assignment createcommand and ask their admin to run that for them?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.
Added detailed error with command