Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/k8s-configuration/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

1.5.2
++++++++++++++++++
* Add support for Microsoft.HybridContainerService ProvisionedClusters

1.5.1
++++++++++++++++++
* Bump pycryptodome to 3.14.1 to support Python 3.10
Expand Down
7 changes: 6 additions & 1 deletion src/k8s-configuration/azext_k8s_configuration/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ def load_arguments(self, _):
c.argument(
"cluster_type",
options_list=["--cluster-type", "-t"],
arg_type=get_enum_type(["connectedClusters", "managedClusters"]),
arg_type=get_enum_type(["connectedClusters", "managedClusters", "provisionedClusters"]),
help="Specify Arc connected clusters or AKS managed clusters.",
)
c.argument(
"cluster_resource_provider",
options_list=['--cluster-resource-provider', '--cluster-rp'],
help='Cluster Resource Provider name for this clusterType (Required for provisionedClusters)'
)

with self.argument_context("k8s-configuration flux") as c:
c.argument(
Expand Down
3 changes: 3 additions & 0 deletions src/k8s-configuration/azext_k8s_configuration/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@
CONNECTED_CLUSTER_TYPE = "connectedclusters"
MANAGED_CLUSTER_TYPE = "managedclusters"
APPLIANCE_TYPE = "appliances"
PROVISIONED_CLUSTER_TYPE = "provisionedclusters"

MANAGED_CLUSTER_RP = "Microsoft.ContainerService"
CONNECTED_CLUSTER_RP = "Microsoft.Kubernetes"
APPLIANCE_RP = "Microsoft.ResourceConnector"
HYBRIDCONTAINERSERVICE_RP = "microsoft.hybridcontainerservice"

CONNECTED_CLUSTER_API_VERSION = "2021-10-01"
MANAGED_CLUSTER_API_VERSION = "2021-10-01"
APPLIANCE_API_VERSION = "2021-10-31-preview"
HYBRIDCONTAINERSERVICE_API_VERSION = "2021-09-01-preview"

KUBERNETES_MAX_NAME_SIZE = 63

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
logger = get_logger(__name__)


def show_config(cmd, client, resource_group_name, cluster_type, cluster_name, name):
def show_config(cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp=None):
"""Get an existing Kubernetes Source Control Configuration."""

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_rp)
validate_cc_registration(cmd)
try:
config = client.get(
Expand Down Expand Up @@ -108,9 +108,9 @@ def show_config(cmd, client, resource_group_name, cluster_type, cluster_name, na
raise ex


def list_configs(cmd, client, resource_group_name, cluster_type, cluster_name):
def list_configs(cmd, client, resource_group_name, cluster_type, cluster_name, cluster_resource_provider=None):
# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

return client.list(resource_group_name, cluster_rp, cluster_type, cluster_name)
Expand All @@ -125,6 +125,7 @@ def create_config(
cluster_name,
name,
url,
cluster_resource_provider=None,
bucket_name=None,
scope="cluster",
namespace="default",
Expand Down Expand Up @@ -153,7 +154,7 @@ def create_config(
):

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

factory = source_kind_generator_factory(
Expand Down Expand Up @@ -238,6 +239,7 @@ def update_config(
cluster_type,
cluster_name,
name,
cluster_resource_provider=None,
kind=None,
url=None,
bucket_name=None,
Expand Down Expand Up @@ -266,11 +268,11 @@ def update_config(
):

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
if not kind:
kind = convert_to_cli_source_kind(config.source_kind)
Expand Down Expand Up @@ -356,6 +358,7 @@ def create_kustomization(
cluster_name,
name,
kustomization_name,
cluster_resource_provider=None,
dependencies=None,
timeout=None,
sync_interval=None,
Expand All @@ -367,7 +370,7 @@ def create_kustomization(
):

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

# Pre-Validation
Expand All @@ -376,7 +379,7 @@ def create_kustomization(
validate_duration("--retry-interval", retry_interval)

current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
if kustomization_name in current_config.kustomizations:
raise ValidationError(
Expand Down Expand Up @@ -424,10 +427,11 @@ def update_kustomization(
prune=None,
force=None,
no_wait=False,
cluster_resource_provider=None,
):

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

# Pre-Validation
Expand All @@ -436,7 +440,7 @@ def update_kustomization(
validate_duration("--retry-interval", retry_interval)

current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
if kustomization_name not in current_config.kustomizations:
raise ValidationError(
Expand Down Expand Up @@ -476,19 +480,20 @@ def delete_kustomization(
cluster_name,
name,
kustomization_name,
cluster_resource_provider=None,
no_wait=False,
yes=False,
):

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

# Confirmation message for deletes
user_confirmation_factory(cmd, yes)

current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
if kustomization_name not in current_config.kustomizations:
raise ValidationError(
Expand Down Expand Up @@ -519,13 +524,14 @@ def delete_kustomization(


def list_kustomization(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_resource_provider=None
):
# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
return current_config.kustomizations

Expand All @@ -538,12 +544,13 @@ def show_kustomization(
cluster_name,
name,
kustomization_name,
cluster_resource_provider=None,
):

cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
if kustomization_name not in current_config.kustomizations:
raise ValidationError(
Expand All @@ -554,11 +561,12 @@ def show_kustomization(


def list_deployed_object(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_resource_provider=None
):
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)
current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
return current_config.statuses

Expand All @@ -573,10 +581,12 @@ def show_deployed_object(
object_name,
object_namespace,
object_kind,
cluster_resource_provider=None,
):
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)
current_config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)

for status in current_config.statuses:
Expand All @@ -601,6 +611,7 @@ def delete_config(
cluster_type,
cluster_name,
name,
cluster_resource_provider=None,
force=False,
no_wait=False,
yes=False,
Expand All @@ -610,13 +621,13 @@ def delete_config(
user_confirmation_factory(cmd, yes)

# Get Resource Provider to call
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
validate_cc_registration(cmd)

config = None
try:
config = show_config(
cmd, client, resource_group_name, cluster_type, cluster_name, name
cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_rp
)
except HttpResponseError:
logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
logger = get_logger(__name__)


def show_config(cmd, client, resource_group_name, cluster_type, cluster_name, name):
def show_config(cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_resource_provider=None):
# Validate that the subscription is registered to Microsoft.KubernetesConfiguration
validate_cc_registration(cmd)

# Determine ClusterRP
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
try:
extension = client.get(
resource_group_name, cluster_rp, cluster_type, cluster_name, name
Expand Down Expand Up @@ -64,19 +64,19 @@ def show_config(cmd, client, resource_group_name, cluster_type, cluster_name, na
raise ex


def list_configs(cmd, client, resource_group_name, cluster_type, cluster_name):
def list_configs(cmd, client, resource_group_name, cluster_type, cluster_name, cluster_resource_provider=None):
# Validate that the subscription is registered to Microsoft.KubernetesConfiguration
validate_cc_registration(cmd)

cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
return client.list(resource_group_name, cluster_rp, cluster_type, cluster_name)


def delete_config(cmd, client, resource_group_name, cluster_type, cluster_name, name):
def delete_config(cmd, client, resource_group_name, cluster_type, cluster_name, name, cluster_resource_provider=None):
# Validate that the subscription is registered to Microsoft.KubernetesConfiguration
validate_cc_registration(cmd)

cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)
return client.begin_delete(
resource_group_name, cluster_rp, cluster_type, cluster_name, name
)
Expand All @@ -92,6 +92,7 @@ def create_config(
repository_url,
scope,
cluster_type,
cluster_resource_provider=None,
operator_instance_name=None,
operator_namespace="default",
helm_operator_chart_version="1.4.0",
Expand All @@ -109,7 +110,7 @@ def create_config(

"""Create a new Kubernetes Source Control Configuration."""
# Determine ClusterRP
cluster_rp, _ = get_cluster_rp_api_version(cluster_type)
cluster_rp, _ = get_cluster_rp_api_version(cluster_type=cluster_type, cluster_rp=cluster_resource_provider)

# Determine operatorInstanceName
if operator_instance_name is None:
Expand Down
16 changes: 15 additions & 1 deletion src/k8s-configuration/azext_k8s_configuration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@
from azure.cli.core.azclierror import (
MutuallyExclusiveArgumentError,
InvalidArgumentValueError,
RequiredArgumentMissingError
)
from . import consts


def get_cluster_rp_api_version(cluster_type) -> Tuple[str, str]:
def get_cluster_rp_api_version(cluster_type, cluster_rp) -> Tuple[str, str]:
if cluster_type.lower() == consts.PROVISIONED_CLUSTER_TYPE:
if cluster_rp is None or cluster_rp.strip() == "":
raise RequiredArgumentMissingError(
"Error! Cluster Resource Provider value is required for Cluster Type '{}'".format(cluster_type)
)
if cluster_rp.lower() == consts.HYBRIDCONTAINERSERVICE_RP:
return (
consts.HYBRIDCONTAINERSERVICE_RP,
consts.HYBRIDCONTAINERSERVICE_API_VERSION,
)
raise InvalidArgumentValueError(
"Error! Cluster type '{}' and Cluster Resource Provider '{}' combination is not supported".format(cluster_type, cluster_rp)
)
if cluster_type.lower() == consts.CONNECTED_CLUSTER_TYPE:
return consts.CONNECTED_CLUSTER_RP, consts.CONNECTED_CLUSTER_API_VERSION
if cluster_type.lower() == consts.APPLIANCE_TYPE:
Expand Down