Skip to content

Commit

Permalink
Fix style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Dec 8, 2021
1 parent 2555aaf commit da679f8
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 39 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore =
F401, # imported but unused, too many violations, to be removed in the future
F811, # redefinition of unused, to be removed in the future
C901 # code flow is too complex, too many violations, to be removed in the future
W503 # line break before binary operator effect on readability is subjective
W504 # line break after binary operator effect on readability is subjective
exclude =
*/vendored_sdks
Expand Down
4 changes: 2 additions & 2 deletions src/k8s-extension/azext_k8s_extension/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
MANAGED_CLUSTER_TYPE = "managedclusters"
APPLIANCE_TYPE = "appliances"

CONNECTED_CLUSTER_API_VERSION = "2020-01-01-preview"
MANAGED_CLUSTER_API_VERSION = "2021-05-01"
CONNECTED_CLUSTER_API_VERSION = "2021-10-01"
MANAGED_CLUSTER_API_VERSION = "2021-10-01"
APPLIANCE_API_VERSION = "2021-10-31-preview"
9 changes: 5 additions & 4 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from azext_k8s_extension.utils import (
get_cluster_rp_api_version,
is_dogfood_cluster,
read_config_settings_file,
)
from knack.log import get_logger
Expand Down Expand Up @@ -130,7 +131,7 @@ def create_k8s_extension(
config_protected_settings = {}
# Get Configuration Settings from file
if configuration_settings_file is not None:
config_settings = __read_config_settings_file(configuration_settings_file)
config_settings = read_config_settings_file(configuration_settings_file)

if configuration_settings is not None:
for dicts in configuration_settings:
Expand All @@ -139,7 +140,7 @@ def create_k8s_extension(

# Get Configuration Protected Settings from file
if configuration_protected_settings_file is not None:
config_protected_settings = __read_config_settings_file(
config_protected_settings = read_config_settings_file(
configuration_protected_settings_file
)

Expand Down Expand Up @@ -192,7 +193,7 @@ def create_k8s_extension(
# We don't create the identity if we are in DF
if create_identity and not is_dogfood_cluster(cmd):
identity_object, location = __create_identity(
cmd, resource_group_name, cluster_name, cluster_type, cluster_rp
cmd, resource_group_name, cluster_name, cluster_type
)
if identity_object is not None and location is not None:
extension_instance.identity, extension_instance.location = (
Expand Down Expand Up @@ -294,7 +295,7 @@ def update_k8s_extension(
version,
config_settings,
config_protected_settings,
yes
yes,
)

return sdk_no_wait(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,35 @@


class DefaultExtension(PartnerExtensionModel):
def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type,
scope, auto_upgrade_minor_version, release_train, version, target_namespace,
release_namespace, configuration_settings, configuration_protected_settings,
configuration_settings_file, configuration_protected_settings_file):
def Create(
self,
cmd,
client,
resource_group_name,
cluster_name,
name,
cluster_type,
extension_type,
scope,
auto_upgrade_minor_version,
release_train,
version,
target_namespace,
release_namespace,
configuration_settings,
configuration_protected_settings,
configuration_settings_file,
configuration_protected_settings_file,
):
"""Default validations & defaults for Create
Must create and return a valid 'Extension' object.
Must create and return a valid 'Extension' object.
"""
ext_scope = None
if scope is not None:
if scope.lower() == 'cluster':
if scope.lower() == "cluster":
scope_cluster = ScopeCluster(release_namespace=release_namespace)
ext_scope = Scope(cluster=scope_cluster, namespace=None)
elif scope.lower() == 'namespace':
elif scope.lower() == "namespace":
scope_namespace = ScopeNamespace(target_namespace=target_namespace)
ext_scope = Scope(namespace=scope_namespace, cluster=None)

Expand All @@ -41,27 +57,43 @@ def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_t
version=version,
scope=ext_scope,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings
configuration_protected_settings=configuration_protected_settings,
)
return extension, name, create_identity

def Update(self, cmd, resource_group_name, cluster_name, auto_upgrade_minor_version, release_train, version, configuration_settings,
configuration_protected_settings, yes=False):
def Update(
self,
cmd,
resource_group_name,
cluster_name,
auto_upgrade_minor_version,
release_train,
version,
configuration_settings,
configuration_protected_settings,
yes=False,
):
"""Default validations & defaults for Update
Must create and return a valid 'PatchExtension' object.
Must create and return a valid 'PatchExtension' object.
"""

return PatchExtension(auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings)
return PatchExtension(
auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings,
)

def Delete(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, yes):
def Delete(
self, cmd, client, resource_group_name, cluster_name, name, cluster_type, yes
):
user_confirmation_factory(cmd, yes)


def user_confirmation_factory(cmd, yes, message="Are you sure you want to perform this operation?"):
if cmd.cli_ctx.config.getboolean('core', 'disable_confirm_prompt', fallback=False):
def user_confirmation_factory(
cmd, yes, message="Are you sure you want to perform this operation?"
):
if cmd.cli_ctx.config.getboolean("core", "disable_confirm_prompt", fallback=False):
return
user_confirmation(message, yes=yes)
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,52 @@

class PartnerExtensionModel(ABC):
@abstractmethod
def Create(self, cmd, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str,
extension_type: str, scope: str, auto_upgrade_minor_version: bool, release_train: str, version: str,
target_namespace: str, release_namespace: str, configuration_settings: dict,
configuration_protected_settings: dict, configuration_settings_file: str,
configuration_protected_settings_file: str) -> Extension:
def Create(
self,
cmd,
client,
resource_group_name: str,
cluster_name: str,
name: str,
cluster_type: str,
extension_type: str,
scope: str,
auto_upgrade_minor_version: bool,
release_train: str,
version: str,
target_namespace: str,
release_namespace: str,
configuration_settings: dict,
configuration_protected_settings: dict,
configuration_settings_file: str,
configuration_protected_settings_file: str,
) -> Extension:
pass

@abstractmethod
def Update(self, cmd, resource_group_name: str, cluster_name: str, auto_upgrade_minor_version: bool, release_train: str, version: str,
configuration_settings: dict, configuration_protected_settings: dict, yes: bool) -> PatchExtension:
def Update(
self,
cmd,
resource_group_name: str,
cluster_name: str,
auto_upgrade_minor_version: bool,
release_train: str,
version: str,
configuration_settings: dict,
configuration_protected_settings: dict,
yes: bool,
) -> PatchExtension:
pass

@abstractmethod
def Delete(self, cmd, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str, yes: bool):
def Delete(
self,
cmd,
client,
resource_group_name: str,
cluster_name: str,
name: str,
cluster_type: str,
yes: bool,
):
pass
11 changes: 5 additions & 6 deletions src/k8s-extension/azext_k8s_extension/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
def get_cluster_rp_api_version(cluster_type) -> Tuple[str, str]:
if cluster_type.lower() == consts.CONNECTED_CLUSTER_TYPE:
return consts.CONNECTED_CLUSTER_RP, consts.CONNECTED_CLUSTER_API_VERSION
elif cluster_type.lower() == consts.APPLIANCE_TYPE:
if cluster_type.lower() == consts.APPLIANCE_TYPE:
return consts.APPLIANCE_RP, consts.APPLIANCE_API_VERSION
elif (
if (
cluster_type.lower() == ""
or cluster_type.lower() == consts.MANAGED_CLUSTER_TYPE
):
return consts.MANAGED_CLUSTER_RP, consts.MANAGED_CLUSTER_API_VERSION
else:
raise InvalidArgumentValueError(
"Error! Cluster type '{}' is not supported".format(cluster_type)
)
raise InvalidArgumentValueError(
"Error! Cluster type '{}' is not supported".format(cluster_type)
)


def read_config_settings_file(file_path):
Expand Down

0 comments on commit da679f8

Please sign in to comment.