Skip to content

Commit acd19bb

Browse files
update
1 parent 428bb59 commit acd19bb

File tree

6 files changed

+1653
-4179
lines changed

6 files changed

+1653
-4179
lines changed

src/fleet/azext_fleet/_client_factory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ def cf_auto_upgrade_profiles(cli_ctx, *_):
4444

4545
def cf_auto_upgrade_profile_operations(cli_ctx, *_):
4646
return get_container_service_client(cli_ctx).auto_upgrade_profile_operations
47+
48+
49+
def get_provider_client(cli_ctx):
50+
return get_mgmt_service_client(
51+
cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES)

src/fleet/azext_fleet/_helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
from knack.log import get_logger
1414
from knack.prompting import NoTTYException, prompt_y_n
1515
from knack.util import CLIError
16+
from azure.cli.command_modules.acs._roleassignments import add_role_assignment
17+
18+
from azext_fleet.constants import FLEET_1P_APP_ID
19+
from azext_fleet._client_factory import get_provider_client
1620

1721
logger = get_logger(__name__)
1822

@@ -148,3 +152,15 @@ def _load_kubernetes_configuration(filename):
148152
raise
149153
except (yaml.parser.ParserError, UnicodeDecodeError) as ex:
150154
raise CLIError(f'Error parsing {filename} ({str(ex)})') from ex
155+
156+
157+
def validate_subnet(cmd, subnet_id):
158+
resource_client = get_provider_client(cmd.cli_ctx)
159+
provider = resource_client.providers.get("Microsoft.ContainerService")
160+
161+
if provider.registration_state != 'Registered':
162+
raise CLIError("The Microsoft.ContainerService resource provider is not registered."
163+
"Run `az provider register -n Microsoft.ContainerService --wait`.")
164+
if not add_role_assignment(cmd, 'Network Contributor', FLEET_1P_APP_ID, scope=subnet_id):
165+
raise CLIError("failed to create role assignment for Fleet RP.\n"
166+
f"Do you have owner permissions on the subnet {subnet_id}?\n")

src/fleet/azext_fleet/custom.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
from azure.cli.core.commands.client_factory import get_subscription_id
1212
from azure.cli.core.util import sdk_no_wait
13-
from azure.cli.command_modules.acs._roleassignments import add_role_assignment
1413

1514
from azext_fleet._client_factory import CUSTOM_MGMT_FLEET
16-
from azext_fleet._helpers import print_or_merge_credentials
15+
from azext_fleet._helpers import print_or_merge_credentials, validate_subnet
1716
from azext_fleet.constants import UPGRADE_TYPE_CONTROLPLANEONLY
1817
from azext_fleet.constants import UPGRADE_TYPE_FULL
1918
from azext_fleet.constants import UPGRADE_TYPE_NODEIMAGEONLY
2019
from azext_fleet.constants import UPGRADE_TYPE_ERROR_MESSAGES
21-
from azext_fleet.constants import FLEET_1P_APP_ID
2220

2321

2422
# pylint: disable=too-many-locals
@@ -112,19 +110,9 @@ def create_fleet(cmd,
112110
)
113111

114112
if enable_private_cluster:
115-
if not add_role_assignment(cmd, 'Network Contributor', FLEET_1P_APP_ID, scope=agent_subnet_id):
116-
raise CLIError(
117-
"failed to create role assignment for Fleet RP.\nDo you have owner permissions on the vnet?\n"
118-
"Is the Microsoft.Containerservice namespace registered?\n"
119-
"Please try registering Fleet namespace before retrying: az provider register --namespace 'Microsoft.Containerservice'" # pylint: disable=line-too-long
120-
)
113+
validate_subnet(cmd, resource_group_name, agent_subnet_id)
121114
if enable_vnet_integration:
122-
if not add_role_assignment(cmd, 'Network Contributor', FLEET_1P_APP_ID, scope=apiserver_subnet_id):
123-
raise CLIError(
124-
"failed to create role assignment for Fleet RP.\nDo you have owner permissions on the vnet?\n"
125-
"Is the Microsoft.Containerservice namespace registered?\n"
126-
"Please try registering Fleet namespace before retrying: az provider register --namespace 'Microsoft.Containerservice'" # pylint: disable=line-too-long
127-
)
115+
validate_subnet(cmd, resource_group_name, apiserver_subnet_id)
128116

129117
return sdk_no_wait(no_wait,
130118
client.begin_create_or_update,

0 commit comments

Comments
 (0)