Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Custom Delete Logic for Partners #54

Merged
merged 2 commits into from
Jun 22, 2021
Merged
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
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