Skip to content

Commit

Permalink
Accept gatewayArmID and enablegateway flag in connect command and per…
Browse files Browse the repository at this point in the history
…form prelim checks
  • Loading branch information
9lash committed Jul 9, 2024
1 parent 5a93702 commit b4e04db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/connectedk8s/azext_connectedk8s/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
Kubeconfig_Failed_To_Load_Fault_Type = "failed-to-load-kubeconfig-file"
Proxy_Cert_Path_Does_Not_Exist_Fault_Type = 'proxy-cert-path-does-not-exist-error'
Proxy_Cert_Path_Does_Not_Exist_Error = 'Proxy cert path {} does not exist. Please check the path provided'
Gateway_ArmID_Is_Invalid = "The provided Gateway ArmID in --gateway-resourceId {} is invalid. Please provide a valid Gateway ArmID"
Get_Kubernetes_Infra_Fault_Type = 'kubernetes-get-infrastructure-error'
No_Param_Error = 'No parmeters were specified with update command. Please run az connectedk8s update --help to check parameters available for update'
EnableProxy_Conflict_Error = 'Conflict detected: --disable-proxy can not be set with --https-proxy, --http-proxy, --proxy-skip-range and --proxy-cert at the same time. Please run az connectedk8s update --help for more information about the parameters'
Expand Down
7 changes: 4 additions & 3 deletions src/connectedk8s/azext_connectedk8s/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from argcomplete.completers import FilesCompleter
from azure.cli.core.commands.parameters import get_location_type, get_enum_type, file_type, tags_type, get_three_state_flag
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azext_connectedk8s._constants import Distribution_Enum_Values, Infrastructure_Enum_Values, Feature_Values, AHB_Enum_Values, Connection_Type
from azext_connectedk8s._constants import Distribution_Enum_Values, Infrastructure_Enum_Values, Feature_Values, AHB_Enum_Values
from knack.arguments import (CLIArgumentType, CaseInsensitiveList)

from ._validators import validate_private_link_properties
Expand Down Expand Up @@ -51,8 +51,8 @@ def load_arguments(self, _):
c.argument('container_log_path', help='Override the default container log path to enable fluent-bit logging')
c.argument('skip_ssl_verification', action='store_true', help='Skip SSL verification for any cluster connection.')
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('enable_gateway', options_list=['--enable_gateway'], help='pass this value to enable Arc Gateway')
c.argument('disable_gateway', options_list=['--disable_gateway'], help='pass this value to enable Arc Gateway')
c.argument('enable_gateway', options_list=['--enable-gateway'], help='Pass this value to enable Arc Gateway.')
c.argument('gateway_resource_id', options_list=['--gateway-resourceId'], help='ArmID of the Arc Gateway resource.')

with self.argument_context('connectedk8s update') as c:
c.argument('tags', tags_type)
Expand All @@ -71,6 +71,7 @@ def load_arguments(self, _):
c.argument('container_log_path', help='Override the default container log path to enable fluent-bit logging')
c.argument('skip_ssl_verification', action='store_true', help='Skip SSL verification for any cluster connection.')
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('disable_gateway', options_list=['--disable_gateway'], help='pass this value to disable Arc Gateway')

with self.argument_context('connectedk8s upgrade') as c:
c.argument('cluster_name', options_list=['--name', '-n'], id_part='name', help='The name of the connected cluster.')
Expand Down
17 changes: 13 additions & 4 deletions src/connectedk8s/azext_connectedk8s/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import azext_connectedk8s._troubleshootutils as troubleshootutils
import azext_connectedk8s._precheckutils as precheckutils
from glob import glob
from .vendored_sdks.models import ConnectedCluster, ConnectedClusterIdentity, ListClusterUserCredentialProperties
from .vendored_sdks.preview_2024_07_01.models import ConnectedCluster, ConnectedClusterIdentity, ListClusterUserCredentialProperties
from .vendored_sdks.preview_2022_10_01.models import ConnectedCluster as ConnectedClusterPreview
from .vendored_sdks.preview_2022_10_01.models import ConnectedClusterPatch as ConnectedClusterPatchPreview
import sys
Expand All @@ -65,7 +65,7 @@
def create_connectedk8s(cmd, client, resource_group_name, cluster_name, correlation_id=None, https_proxy="", http_proxy="", no_proxy="", proxy_cert="", location=None,
kube_config=None, kube_context=None, no_wait=False, tags=None, distribution='generic', infrastructure='generic',
disable_auto_upgrade=False, cl_oid=None, onboarding_timeout="600", enable_private_link=None, private_link_scope_resource_id=None,
distribution_version=None, azure_hybrid_benefit=None, skip_ssl_verification=False, yes=False, container_log_path=None, connection_type="direct"):
distribution_version=None, azure_hybrid_benefit=None, skip_ssl_verification=False, yes=False, container_log_path=None, enable_gateway=False, gateway_resource_id=""):
logger.warning("This operation might take a while...\n")

# changing cli config to push telemetry in 1 hr interval
Expand Down Expand Up @@ -137,10 +137,19 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, correlat
if enable_private_link is not None or distribution_version is not None or azure_hybrid_benefit is not None:
client = cf_connected_cluster_prev_2023_11_01(cmd.cli_ctx, None)

# Set preview client if the connection-type is provided. (TODO: To test whether overriding the client factory to 2024 will retain the 2023 private link feature as in the line above)
if connection_type is not None and connection_type == "gateway":
# Set preview client to be July 01 2024 if the enable_gateway is enabled.
# (TODO: To test whether overriding the client factory to 2024 will retain the 2023 private link feature as in the line above)
if enable_gateway:
client = cf_connected_cluster_prev_2024_07_01(cmd.cli_ctx, None)

# Check if the provided Gateway ARM ID is valid
if enable_gateway is True:
gateway_armid_pattern = r"^/subscriptions/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/resourceGroups/[a-zA-Z0-9_-]+/providers/Microsoft\.HybridCompute/gateways/[a-zA-Z0-9_-]+$"
if re.match(gateway_armid_pattern, gateway_resource_id):
logger.warning("The provided Gateway ArmID is valid.")
else:
raise InvalidArgumentValueError(str.format(consts.Gateway_ArmID_Is_Invalid, gateway_resource_id))

# Checking whether optional extra values file has been provided.
values_file = utils.get_values_file()
if cmd.cli_ctx.cloud.endpoints.resource_manager == consts.Dogfood_RMEndpoint:
Expand Down

0 comments on commit b4e04db

Please sign in to comment.