Skip to content

Commit

Permalink
Add yes to delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Aug 24, 2021
1 parent c046f05 commit d1023b0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 25 deletions.
40 changes: 31 additions & 9 deletions src/k8s-extension/azext_k8s_extension/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,47 @@

helps[f'{consts.EXTENSION_NAME}'] = """
type: group
short-summary: Commands to manage K8s-extensions.
short-summary: Commands to manage Kubernetes Extensions.
"""

helps[f'{consts.EXTENSION_NAME} create'] = """
helps[f'{consts.EXTENSION_NAME} create'] = f"""
type: command
short-summary: Create a K8s-extension.
short-summary: Create a Kubernetes Extension.
examples:
- name: Create a Kubernetes Extension
text: |-
az {consts.EXTENSION_NAME} create --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters \\
--name myextension --extension-type microsoft.openservicemesh \\
--scope cluster --release-train stable
"""

helps[f'{consts.EXTENSION_NAME} list'] = """
helps[f'{consts.EXTENSION_NAME} list'] = f"""
type: command
short-summary: List K8s-extensions.
short-summary: List Kubernetes Extensions.
examples:
- name: List all Kubernetes Extensions on a cluster
text: |-
az {consts.EXTENSION_NAME} list --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters
"""

helps[f'{consts.EXTENSION_NAME} delete'] = """
helps[f'{consts.EXTENSION_NAME} delete'] = f"""
type: command
short-summary: Delete a K8s-extension.
short-summary: Delete a Kubernetes Extension.
examples:
- name: Delete an existing Kubernetes Extension
text: |-
az {consts.EXTENSION_NAME} delete --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myextension
"""

helps[f'{consts.EXTENSION_NAME} show'] = """
helps[f'{consts.EXTENSION_NAME} show'] = f"""
type: command
short-summary: Show details of a K8s-extension.
short-summary: Show a Kubernetes Extension.
examples:
- name: Show details of a Kubernetes Extension
text: |-
az {consts.EXTENSION_NAME} show --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myextension
"""
5 changes: 3 additions & 2 deletions src/k8s-extension/azext_k8s_extension/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def load_arguments(self, _):
c.argument('target_namespace',
help='Specify the target namespace to install to for the extension instance. This'
' parameter is required if extension scope is set to \'namespace\'')

with self.argument_context(f"{consts.EXTENSION_NAME} delete") as c:
c.argument('yes',
options_list=['yes', 'y']
)
options_list=['--yes', '-y'],
help='Ignore confirmation prompts')
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from knack.log import get_logger

from ..vendored_sdks.models import ExtensionInstance
from ..vendored_sdks.models import ExtensionInstanceUpdate
from ..vendored_sdks.models import ScopeCluster
from ..vendored_sdks.models import Scope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
from msrestazure.azure_exceptions import CloudError

from .._client_factory import cf_resources
from .DefaultExtension import DefaultExtension, default_user_confirmation
from .DefaultExtension import DefaultExtension, user_confirmation_factory
from ..vendored_sdks.models import (
ExtensionInstance,
ExtensionInstanceUpdate,
Scope,
ScopeCluster
)
Expand Down Expand Up @@ -164,7 +163,7 @@ def Delete(self, cmd, client, resource_group_name, cluster_name, name, cluster_t
logger.warning("If nvidia.com/gpu or fuse resource is not recognized by kubernetes after this deletion, "
"you probably have installed nvidia-device-plugin or fuse-device-plugin before installing AMLArc extension. "
"Please try to reinstall device plugins to fix this issue.")
default_user_confirmation(cmd, yes)
user_confirmation_factory(cmd, yes)

def __validate_config(self, configuration_settings, configuration_protected_settings):
# perform basic validation of the input config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from msrestazure.tools import parse_resource_id, is_valid_resource_id

from ..vendored_sdks.models import ExtensionInstance
from ..vendored_sdks.models import ExtensionInstanceUpdate
from ..vendored_sdks.models import ScopeCluster
from ..vendored_sdks.models import Scope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version):
)

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


def default_user_confirmation(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):
return
return user_confirmation("Are you sure you want to perform this operation?", yes=yes)
user_confirmation(message, yes=yes)
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from ..vendored_sdks.models import ScopeNamespace
from ..vendored_sdks.models import Scope

from .PartnerExtensionModel import PartnerExtensionModel
from .DefaultExtension import DefaultExtension


class DefaultExtensionWithIdentity(PartnerExtensionModel):
class DefaultExtensionWithIdentity(DefaultExtension):
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,
Expand Down Expand Up @@ -55,6 +55,3 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version):
release_train=release_train,
version=version
)

def Delete(self, client, resource_group_name, cluster_name, name, cluster_type):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def Update(self, extension: ExtensionInstance, auto_upgrade_minor_version: bool,
pass

@abstractmethod
def Delete(self, 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

0 comments on commit d1023b0

Please sign in to comment.