Skip to content

Commit

Permalink
Add Custom Delete Logic for Partners (#54)
Browse files Browse the repository at this point in the history
* Add custom delete logic

* Fix failing unit tests
  • Loading branch information
jonathan-innis authored Jun 22, 2021
1 parent b0af598 commit c355ad5
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 36 deletions.
11 changes: 11 additions & 0 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ def delete_k8s_extension(client, resource_group_name, cluster_name, name, cluste
"""
# Determine ClusterRP
cluster_rp = __get_cluster_rp(cluster_type)
extension = None
try:
extension = client.get(resource_group_name, cluster_rp, cluster_type, cluster_name, name)
except ErrorResponseException:
logger.warning("No extension with name '%s' found on cluster '%s', so nothing to delete", cluster_name, name)
return None
extension_class = ExtensionFactory(extension.extension_type.lower())

# If there is any custom delete logic, this will call the logic
extension_class.Delete(client, resource_group_name, cluster_name, name, cluster_type)

return client.delete(resource_group_name, cluster_rp, cluster_type, cluster_name, name)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ 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 @@ -162,6 +162,9 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version):
version=version
)

def Delete(self, client, resource_group_name, cluster_name, name, cluster_type):
pass

def __validate_config(self, configuration_settings, configuration_protected_settings):
# perform basic validation of the input config
config_keys = configuration_settings.keys()
Expand Down Expand Up @@ -226,7 +229,7 @@ def __validate_scoring_fe_settings(self, configuration_settings, configuration_p
if feIsNodePort and feIsInternalLoadBalancer:
raise MutuallyExclusiveArgumentError(
"Specify either privateEndpointNodeport=true or privateEndpointILB=true, but not both.")
elif feIsNodePort:
if feIsNodePort:
configuration_settings['scoringFe.serviceType.nodePort'] = feIsNodePort
elif feIsInternalLoadBalancer:
configuration_settings['scoringFe.serviceType.internalLoadBalancer'] = feIsInternalLoadBalancer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ 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 @@ -82,6 +82,9 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version):
version=version
)

def Delete(self, client, resource_group_name, cluster_name, name, cluster_type):
pass


# Custom Validation Logic for Container Insights

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ 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 @@ -4,6 +4,8 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument
# pylint: disable=redefined-outer-name
# pylint: disable=no-member

from knack.log import get_logger

Expand Down Expand Up @@ -101,6 +103,9 @@ def Update(self, extension, auto_upgrade_minor_version, release_train, version):
version=version
)

def Delete(self, client, resource_group_name, cluster_name, name, cluster_type):
pass


def _validate_tested_distro(cmd, cluster_resource_group_name, cluster_name, extension_version):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ def Create(self, cmd, client, resource_group_name: str, cluster_name: str, name:
def Update(self, extension: ExtensionInstance, auto_upgrade_minor_version: bool,
release_train: str, version: str) -> ExtensionInstanceUpdate:
pass

@abstractmethod
def Delete(self, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str):
pass

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
# pylint: disable=line-too-long

import os
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, record_only)
from azure.cli.testsdk import (ScenarioTest, record_only)


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


class K8sExtensionScenarioTest(ScenarioTest):
@record_only()
@ResourceGroupPreparer(name_prefix='cli_test_k8s_extension')
def test_k8s_extension(self):
resource_type = 'microsoft.openservicemesh'
self.kwargs.update({
'name': 'openservice-mesh',
'name': 'openservicemesh',
'rg': 'nanthirg0923',
'cluster_name': 'nanthicluster0923',
'cluster_type': 'connectedClusters',
'extension_type': resource_type,
'release_train': 'staging',
'version': '0.1.0'
'release_train': 'pilot',
'version': '0.8.3'
})

self.cmd('k8s-extension create -g {rg} -n {name} -c {cluster_name} --cluster-type {cluster_type} '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import os
import unittest

from azext_k8s_extension.partner_extensions.OpenServiceMesh import _get_tested_distros
from azure.cli.core.azclierror import InvalidArgumentValueError
from azext_k8s_extension.partner_extensions.OpenServiceMesh import _get_tested_distros

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))

Expand Down

0 comments on commit c355ad5

Please sign in to comment.