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 'ExtensionInstance' object. """ ext_scope = None if scope is not None: if scope.lower() == 'cluster': scope_cluster = ScopeCluster(release_namespace=release_namespace) ext_scope = Scope(cluster=scope_cluster, namespace=None) elif scope.lower() == 'namespace': scope_namespace = ScopeNamespace(target_namespace=target_namespace) ext_scope = Scope(namespace=scope_namespace, cluster=None) create_identity = False extension_instance = ExtensionInstance( 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 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.azuredefender.kubernetes' specific validations & defaults for Create Must create and return a valid 'ExtensionInstance' object. """ # NOTE-1: Replace default scope creation with your customization! ext_scope = None # Hardcoding name, release_namespace and scope since ci only supports one instance and cluster scope # and platform doesnt have support yet extension specific constraints like this name = extension_type.lower() release_namespace = "azuredefender" # Scope is always cluster scope_cluster = ScopeCluster(release_namespace=release_namespace) ext_scope = Scope(cluster=scope_cluster, namespace=None) is_ci_extension_type = False logger.warning( 'Ignoring name, release-namespace and scope parameters since %s ' 'only supports cluster scope and single instance of this extension.', extension_type) logger.warning( "Defaulting to extension name '%s' and release-namespace '%s'", name, release_namespace) _get_container_insights_settings(cmd, resource_group_name, cluster_name, configuration_settings, configuration_protected_settings, is_ci_extension_type) # NOTE-2: Return a valid ExtensionInstance object, Instance name and flag for Identity create_identity = True extension_instance = ExtensionInstance( 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 create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, scope='cluster', auto_upgrade_minor_version=None, release_train=None, version=None, target_namespace=None, release_namespace=None, configuration_settings=None, configuration_protected_settings=None, configuration_settings_file=None, configuration_protected_settings_file=None, location=None, tags=None): """Create a new Extension Instance. """ # Determine ClusterRP cluster_rp = __get_cluster_type(cluster_type) # Validate scope and namespace __validate_scope_and_namespace(scope, release_namespace, target_namespace, name) # Validate version, release_train __validate_version_and_release_train(version, release_train, auto_upgrade_minor_version) # Configuration Settings & Configuration Protected Settings if configuration_settings is not None and configuration_settings_file is not None: raise CLIError( 'Error! Both configuration_settings and configuration_settings_file cannot be provided.' ) if configuration_protected_settings is not None and configuration_protected_settings_file is not None: raise CLIError( 'Error! Both configuration_protected_settings and configuration_protected_settings_file ' 'cannot be provided.') config_settings = {} config_protected_settings = {} # Get Configuration Settings from file if configuration_settings_file is not None: config_settings = __get_config_settings_from_file( configuration_settings_file) if configuration_settings is not None: for dicts in configuration_settings: for key, value in dicts.items(): config_settings[key] = value # Get Configuration Protected Settings from file if configuration_protected_settings_file is not None: config_protected_settings = __get_config_settings_from_file( configuration_protected_settings_file) if configuration_protected_settings is not None: for dicts in configuration_protected_settings: for key, value in dicts.items(): config_protected_settings[key] = value # ExtensionType specific conditions if extension_type.lower() == 'azuremonitor-containers': # hardcoding name, release_namespace and scope since ci only supports one instance and cluster scope # and platform doesnt have support yet extension specific constraints like this logger.warning( 'Ignoring name, release_namespace and scope parameters since azuremonitor-containers ' 'only supports cluster scope and single instance of this extension' ) name = 'azuremonitor-containers' release_namespace = 'azuremonitor-containers' scope = 'cluster' if not config_settings: config_settings = {} if not config_protected_settings: config_protected_settings = {} _get_container_insights_settings(cmd, resource_group_name, cluster_name, config_settings, config_protected_settings) # Determine namespace name if scope == 'cluster': if release_namespace is None: release_namespace = name scope_cluster = ScopeCluster(release_namespace=release_namespace) ext_scope = Scope(cluster=scope_cluster, namespace=None) else: if target_namespace is None: target_namespace = name scope_namespace = ScopeNamespace(target_namespace=target_namespace) ext_scope = Scope(namespace=scope_namespace, cluster=None) # Create Extension Instance object extension_instance = ExtensionInstanceForCreate( extension_type=extension_type, auto_upgrade_minor_version=auto_upgrade_minor_version, release_train=release_train, version=version, scope=ext_scope, configuration_settings=config_settings, configuration_protected_settings=config_protected_settings) # Try to create the resource return client.create(resource_group_name, cluster_rp, cluster_type, cluster_name, name, extension_instance)