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 Microsoft.PolicyInsights extension for public preview #83

Merged
Show file tree
Hide file tree
Changes from 2 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-extension/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

1.0.1
++++++++++++++++++
* Enable Microsoft.PolicyInsights extension type

1.0.0
++++++++++++++++++
* Switch to GA api-version of Extensions (2021-09-01)
Expand Down
2 changes: 2 additions & 0 deletions src/k8s-extension/azext_k8s_extension/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .partner_extensions.OpenServiceMesh import OpenServiceMesh
from .partner_extensions.AzureMLKubernetes import AzureMLKubernetes
from .partner_extensions.Dapr import Dapr
from .partner_extensions.AzurePolicy import AzurePolicy
from .partner_extensions.DefaultExtension import DefaultExtension, user_confirmation_factory
from . import consts

Expand All @@ -38,6 +39,7 @@ def ExtensionFactory(extension_name):
'microsoft.openservicemesh': OpenServiceMesh,
'microsoft.azureml.kubernetes': AzureMLKubernetes,
'microsoft.dapr': Dapr,
'microsoft.policyinsights': AzurePolicy,
}

# Return the extension if we find it in the map, else return the default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument

from knack.util import CLIError
from knack.log import get_logger

from ..vendored_sdks.models import Extension
from ..vendored_sdks.models import ScopeCluster
from ..vendored_sdks.models import Scope

from .DefaultExtension import DefaultExtension

logger = get_logger(__name__)

valid_release_trains = ['dev', 'staging', 'preview', 'stable']
nreisch marked this conversation as resolved.
Show resolved Hide resolved

class AzurePolicy(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,
configuration_settings_file, configuration_protected_settings_file):

"""ExtensionType 'Microsoft.PolicyInsights' specific validations & defaults for Create
Must create and return a valid 'ExtensionInstance' object.

"""

# Hardcode scope to cluster
ext_scope = None
scope_cluster = ScopeCluster(release_namespace=release_namespace)
ext_scope = Scope(cluster=scope_cluster, namespace=None)
logger.warning('Ignoring scope parameters since %s '
'only supports cluster scope', extension_type)

# If release-train is not provided, set it to 'stable'
if release_train is None:
release_train = 'stable'

# If release-train is other than valid_release_trains raise error
if release_train.lower() not in valid_release_trains:
raise CLIError("Invalid release-train '{}'. Valid values are 'stable', 'preview'.".format(release_train))

# Create Managed Identity for extension
create_identity = True

extension_instance = Extension(
extension_type=extension_type,
auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version,
scope=ext_scope,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings,
)
return extension_instance, name, create_identity

def Update(self, extension, auto_upgrade_minor_version, release_train, version):
"""ExtensionType 'Microsoft.PolicyInsights' specific validations & defaults for Update
Must create and return a valid 'Extension' object.

"""
# If release-train is not provided, set it to 'stable'
if release_train is None:
release_train = 'stable'

# If release-train is other than valid_release_trains raise error
if release_train.lower() not in valid_release_trains:
raise CLIError("Invalid release-train '{}'. Valid values are 'stable', 'preview'.".format(release_train))

return Extension(
auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version
)
2 changes: 1 addition & 1 deletion src/k8s-extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# TODO: Add any additional SDK dependencies here
DEPENDENCIES = []

VERSION = "1.0.0"
VERSION = "1.0.1"

with open('README.rst', 'r', encoding='utf-8') as f:
README = f.read()
Expand Down