From 2435c8fc640b50c3af6a6a9aaaa6acec65a2b1b3 Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Sat, 4 Dec 2021 20:31:09 -0800 Subject: [PATCH] [k8s-configuration] Release v1.3.0 with deployed-object support (#4163) * Create pull.yml * Update pull.yml * Update azure-pipelines.yml * Initial commit of k8s-extension * Update CODEOWNERS * Update azure-pipelines.yml * Create pull.yml * Update pull.yml * Update pull.yml * Update pipelines file * Update k8s-configuration name * Update test script params * Update pipeline file * Remove codeowners * Update pipelines file * Update CODEOWNERS * Update private preview pipelines * Remove open service mesh from public release * Update pipeline files * Update custom pipelines files * Add publish step to k8s-configuration * Update pipeline to publish extension * Update public extension pipeline * Change condition variable * Update pipeline naming * Add version to public preview/private preview * Update pipelines * Add different testing based on private branch * Add annotations to extension model * Update k8s-custom-pipelines.yml * Update SDKs with Updated Swagger Spec for 2020-07-01-preview (#13) * Update sdks with updated swagger spec * Update version and history rst * Reorder release history timeline * Fix ExtensionInstanceForCreate for import * remove py2 bdist support * Add custom table formatting * Remove unnecessary files * Fix style issues * Fix branch based on comments * Update identity piece manually * Don't handle defaults at the CLI level * Remove defaults from CLI client * Check null target namespace with namespace scope * Update style * Add cassandra operator and location to model * Stage Public Version of k8s-extension 0.2.0 for official release (#15) * Create pull.yml * Update pull.yml * Update azure-pipelines.yml * Initial commit of k8s-extension * Update pipelines file * Update CODEOWNERS * Update private preview pipelines * Remove open service mesh from public release * Update pipeline files * Update public extension pipeline * Change condition variable * Add version to public preview/private preview * Update pipelines * Add different testing based on private branch * Add annotations to extension model * Update k8s-custom-pipelines.yml * Update SDKs with Updated Swagger Spec for 2020-07-01-preview (#13) * Update sdks with updated swagger spec * Update version and history rst * Reorder release history timeline * Fix ExtensionInstanceForCreate for import * remove py2 bdist support * Add custom table formatting * Remove unnecessary files * Fix style issues * Fix branch based on comments * Update identity piece manually * Don't handle defaults at the CLI level * Remove defaults from CLI client * Check null target namespace with namespace scope * Update style * Add cassandra operator and location to model Co-authored-by: action@github.com * Remove custom pipelines file * Update extension description, remove private const * Update pipeline file * Disable check ref docs * Disable refs docs * Update to include better create warning logs and remove update context (#20) * Update to include better create warning logs and remove update context * Remove help text for update * Fix spelling error * Update message * Fix k8s-extension conflict with private version * Fix style errors * Fix filename * add customization for microsoft.azureml.kubernetes (#23) * add customization for microsoft.azureml.kubernetes * Update release history Co-authored-by: Yue Yu Co-authored-by: jonathan-innis * Add E2E Testing from Separate branch into internal code (#26) * Add internal e2e testing * Change to testing folder * Inference CLI validation for Scoring FE (#24) * cli validation starter * added the call to the fe validation function * nodeport validation not required * test fix Co-authored-by: Jonathan Innis * legal warning added (#27) * Remove deprecated method logger.warn * Update k8s-custom-pipelines.yml for Azure Pipelines * Update k8s-custom-pipelines.yml for Azure Pipelines * Add Azure Defender to E2E testing (#28) * Add azure defender testing to e2e * Remove the debug flag * Add configuration testing * Fix pipeline failures * Make test script more intuitive * Remove parameter from testing * Add some debug * Fix wrong location for k8s config whl * Fix pip install upgrade issue * Fix pip install upgrade issue * Add Check for Provider Registration and Refactor (#19) * Add check for provider registration and refactor * Fix bug in checking registration * Add license header to utils * Update private key check and error messaging * Update based on refactoring * Fix failing tests * Add provider registration check * Create a test for uppercase url, address comments * Add blank line to fix style check * Testing increase to ubuntu-latest * Update k8s-configuration Models to Track2 (#63) * Update models to track2 * Increase k8s-configuration version number * Update kind version * Change error to warning because of DSA failure * Upgrade helm operator chart version (#75) * Pin helm version * Bump version * Migrate pipeline (#90) * Disable updates on configuration tests (#89) * Release k8s-configuration v1.2.0 for Flux v2 Public Preview (#86) * Scaffold out the k8s-config package * Base implementation of CLI commands * Add create scenario and cleanup in consts * Add help text to commands, params * Add other clients to client factory * Automatically installing the flux extension * Move flux and extension into modules * Updated the versioned sdks * Push working command for testing * Update to multi api versioned sdk * Support other extension methods * Fix nullity check * Add source control provider * Add scc commands * Add defer logic for create with cache * Use default extension with identity * Fix identity creation * Add kustomization caching * Add formatters * Add scc provider * Add help text for k8s-config fluxv1 * Add help text for extension * Allow force delete of extension and fluxconfiguration * Add location to the extension model * Update with latest from k8s-extension * Add k8s-config testing * Add license header * Fix all style issues * Update codeowners file * Validate data before checking cluster compliance * No kustomizations warning * Fix identity issue in 2020-07-01 * Fix k8s regex * Fix configuration name regex validation * Fix name length validation * Adding some validation warnings * Add protected settings to request * Exclude private test path * Add suspend functionality * Add correct values to build Kustomization * Add no_wait * Fix style issues * Use base64 encoded httpsUser * Fix formatting error and base64 encoding error * Fix style issues * Fix force * Updated help text * Style fixes * Increase namespace maximum len * Add managed cluster support to k8s-config * Custom confirmation when prune is enabled * Add flux commands to existing k8s-configuration * Remove extension provider from CLI * Fix style issues * Override extension variables * Strip newlines from known_hosts file * Update help text and validators * Strip newlines from known hosts * Add provisioning state check for flux extension * Pin helm version * Remove validation from create command * Add patch support with new SDK * Add implementation for CRUD of source and kustomization * Fix errors on patch * Fix some bugs in patching properties * Add fixes for patch in k8s-configuraiton * Change duration formatting in table output * Add validation and conversion for durations * Bump verison and fix typo * Fix bug with dependencies * Fix linter and style issues * Fix delete prune check * Add flux testing * Create separate jobs for scenarios * Update error text * Fix filepath suggestion from CLI team * Fix unneeded file edit * Add a Deployed Object List to the Flux CLI (#91) * Enable a deployed object list on the CLI * Show detail when extension install fails * Bump version * Remove unneeded files * Update deployed object format (#93) * Fix help text for consistency Co-authored-by: action@github.com Co-authored-by: yuyue9284 <15863499+yuyue9284@users.noreply.github.com> Co-authored-by: Yue Yu Co-authored-by: Lia Kazakova <58274127+liakaz@users.noreply.github.com> --- src/k8s-configuration/HISTORY.rst | 5 + .../azext_k8s_configuration/_help.py | 140 +++++++++++++----- .../azext_k8s_configuration/_params.py | 9 ++ .../azext_k8s_configuration/commands.py | 6 + .../azext_k8s_configuration/consts.py | 3 + .../azext_k8s_configuration/custom.py | 14 ++ .../azext_k8s_configuration/format.py | 91 ++++++++---- .../providers/FluxConfigurationProvider.py | 23 +++ src/k8s-configuration/setup.py | 2 +- 9 files changed, 226 insertions(+), 67 deletions(-) diff --git a/src/k8s-configuration/HISTORY.rst b/src/k8s-configuration/HISTORY.rst index 830db4ca2e2..82acdf8253f 100644 --- a/src/k8s-configuration/HISTORY.rst +++ b/src/k8s-configuration/HISTORY.rst @@ -3,6 +3,11 @@ Release History =============== +1.3.0 +++++++++++++++++++ +* Add `deployed-object` command group for showing deployed Flux objects from configuration +* Show extension error when `microsoft.flux` extension is in a failed state + 1.2.0 ++++++++++++++++++ * Add Flux v2 support with command subgroups diff --git a/src/k8s-configuration/azext_k8s_configuration/_help.py b/src/k8s-configuration/azext_k8s_configuration/_help.py index 91c50291288..062309ce3b1 100644 --- a/src/k8s-configuration/azext_k8s_configuration/_help.py +++ b/src/k8s-configuration/azext_k8s_configuration/_help.py @@ -6,12 +6,16 @@ from knack.help_files import helps # pylint: disable=unused-import -helps['k8s-configuration'] = """ +helps[ + "k8s-configuration" +] = """ type: group short-summary: Commands to manage resources from Microsoft.KubernetesConfiguration. """ -helps['k8s-configuration create'] = """ +helps[ + "k8s-configuration create" +] = """ type: command short-summary: Create a Flux v1 Kubernetes configuration (This command is for Flux v1, to use the newer Flux v2, run "az k8s-configuration flux create"). examples: @@ -26,7 +30,9 @@ --ssh-known-hosts '' --ssh-known-hosts-file '' """ -helps['k8s-configuration list'] = """ +helps[ + "k8s-configuration list" +] = """ type: command short-summary: List Flux v1 Kubernetes configurations (This command is for Flux v1, to use the newer Flux v2, run "az k8s-configuration flux list"). examples: @@ -36,7 +42,9 @@ --cluster-type connectedClusters """ -helps['k8s-configuration delete'] = """ +helps[ + "k8s-configuration delete" +] = """ type: command short-summary: Delete a Flux v1 Kubernetes configuration (This command is for Flux v1, to use the newer Flux v2, run "az k8s-configuration flux delete"). examples: @@ -46,7 +54,9 @@ --cluster-type connectedClusters --name MyConfigurationName """ -helps['k8s-configuration show'] = """ +helps[ + "k8s-configuration show" +] = """ type: command short-summary: Show details of a Flux v1 Kubernetes configuration (This command is for Flux v1, to use the newer Flux v2, run "az k8s-configuration flux show"). examples: @@ -56,16 +66,20 @@ --cluster-type connectedClusters --name MyConfigurationName """ -helps['k8s-configuration flux'] = """ +helps[ + "k8s-configuration flux" +] = """ type: group short-summary: Commands to manage Flux v2 Kubernetes configurations. """ -helps['k8s-configuration flux create'] = """ +helps[ + "k8s-configuration flux create" +] = """ type: command - short-summary: Create a Kubernetes Flux v2 Configuration. + short-summary: Create a Flux v2 Kubernetes configuration. examples: - - name: Create a Kubernetes v2 Flux Configuration + - name: Create a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux create --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters \\ @@ -74,11 +88,13 @@ --branch main --kustomization name=my-kustomization """ -helps['k8s-configuration flux update'] = """ +helps[ + "k8s-configuration flux update" +] = """ type: command - short-summary: Update a Kubernetes Flux v2 Configuration. + short-summary: Update a Flux v2 Kubernetes configuration. examples: - - name: Update a Kubernetes v2 Flux Configuration + - name: Update a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux update --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig \\ @@ -86,91 +102,141 @@ --kustomization name=my-kustomization path=./my/new-path """ -helps['k8s-configuration flux list'] = """ +helps[ + "k8s-configuration flux list" +] = """ type: command - short-summary: List Kubernetes Flux v2 Configurations. + short-summary: List all Flux v2 Kubernetes configurations. examples: - - name: List all Kubernetes Flux v2 Configurations on a cluster + - name: List Flux v2 Kubernetes configurations on a cluster text: |- az k8s-configuration flux list --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters """ -helps['k8s-configuration flux show'] = """ +helps[ + "k8s-configuration flux show" +] = """ type: command - short-summary: Show a Kubernetes Flux v2 Configuration. + short-summary: Show a Flux v2 Kubernetes configuration. examples: - - name: Show details of a Kubernetes Flux v2 Configuration + - name: Show details of a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux show --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig """ -helps['k8s-configuration flux delete'] = """ +helps[ + "k8s-configuration flux delete" +] = """ type: command - short-summary: Delete a Kubernetes Flux v2 Configuration. + short-summary: Delete a Flux v2 Kubernetes configuration. examples: - - name: Delete an existing Kubernetes Flux v2 Configuration + - name: Delete an existing Flux v2 Kubernetes configuration text: |- az k8s-configuration flux delete --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig """ -helps['k8s-configuration flux kustomization'] = """ +helps[ + "k8s-configuration flux kustomization" +] = """ type: group short-summary: Commands to manage Kustomizations associated with Flux v2 Kubernetes configurations. """ -helps['k8s-configuration flux kustomization create'] = """ +helps[ + "k8s-configuration flux kustomization create" +] = """ type: command - short-summary: Create a Kustomization associated with a Kubernetes Flux v2 Configuration. + short-summary: Create a Kustomization associated with a Flux v2 Kubernetes configuration. examples: - - name: Create a Kustomization associated wiht a Kubernetes v2 Flux Configuration + - name: Create a Kustomization associated with a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux kustomization create --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig \\ --kustomization-name my-kustomization-2 --path ./my/path --prune --force """ -helps['k8s-configuration flux kustomization update'] = """ +helps[ + "k8s-configuration flux kustomization update" +] = """ type: command - short-summary: Update a Kustomization associated with a Kubernetes Flux v2 Configuration. + short-summary: Update a Kustomization associated with a Flux v2 Kubernetes configuration. examples: - - name: Update a Kustomization associated with a Kubernetes v2 Flux Configuration + - name: Update a Kustomization associated with a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux kustomization update --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig \\ --kustomization-name my-kustomization --path ./my/new-path --prune --force """ -helps['k8s-configuration flux kustomization list'] = """ +helps[ + "k8s-configuration flux kustomization list" +] = """ type: command - short-summary: List Kustomizations associated with a Kubernetes Flux v2 Configuration. + short-summary: List Kustomizations associated with a Flux v2 Kubernetes configuration. examples: - - name: List all Kustomizations associated with a Kubernetes Flux v2 Configuration on a cluster + - name: List all Kustomizations associated with a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux kustomization list --resource-group my-resource-group \\ --cluster-name mycluster --name myconfig --cluster-type connectedClusters """ -helps['k8s-configuration flux kustomization show'] = """ +helps[ + "k8s-configuration flux kustomization show" +] = """ type: command - short-summary: Show a Kustomization associated with a Flux v2 Configuration. + short-summary: Show a Kustomization associated with a Flux v2 Kubernetes configuration. examples: - - name: Show details of a Kustomization associated with a Kubernetes Flux v2 Configuration + - name: Show details of a Kustomization associated with a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux kustomization show --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig \\ --kustomization-name my-kustomization """ -helps['k8s-configuration flux kustomization delete'] = """ +helps[ + "k8s-configuration flux kustomization delete" +] = """ type: command - short-summary: Delete a Kustomization associated with a Kubernetes Flux v2 Configuration. + short-summary: Delete a Kustomization associated with a Flux v2 Kubernetes configuration. examples: - - name: Delete an existing Kustomization associated with a Kubernetes Flux v2 Configuration + - name: Delete an existing Kustomization associated with a Flux v2 Kubernetes configuration text: |- az k8s-configuration flux kustomization delete --resource-group my-resource-group \\ --cluster-name mycluster --cluster-type connectedClusters --name myconfig \\ --kustomization-name my-kustomization """ + +helps[ + "k8s-configuration flux deployed-object" +] = """ + type: group + short-summary: Commands to see deployed objects associated with Flux v2 Kubernetes configurations. +""" + +helps[ + "k8s-configuration flux deployed-object list" +] = """ + type: command + short-summary: List deployed objects associated with a Flux v2 Kubernetes configuration. + examples: + - name: List all deployed objects associated with a Flux v2 Kubernetes configuration + text: |- + az k8s-configuration flux deployed-object list --resource-group my-resource-group \\ + --cluster-name mycluster --name myconfig --cluster-type connectedClusters +""" + +helps[ + "k8s-configuration flux deployed-object show" +] = """ + type: command + short-summary: Show a deployed object associated with a Flux v2 Kubernetes configuration. + examples: + - name: Show details of a deployed object associated with a Flux v2 Kubernetes configuration + text: |- + az k8s-configuration flux deployed-object show --resource-group my-resource-group \\ + --cluster-name mycluster --cluster-type connectedClusters --name myconfig \\ + --object-name my-object --object-namespace my-namespace --object-kind GitRepository +""" diff --git a/src/k8s-configuration/azext_k8s_configuration/_params.py b/src/k8s-configuration/azext_k8s_configuration/_params.py index ed96f429ec5..6695f58f441 100644 --- a/src/k8s-configuration/azext_k8s_configuration/_params.py +++ b/src/k8s-configuration/azext_k8s_configuration/_params.py @@ -118,6 +118,15 @@ def load_arguments(self, _): options_list=['--yes', '-y'], help='Do not prompt for confirmation') + with self.argument_context('k8s-configuration flux deployed-object show') as c: + c.argument('object_name', + help='Name of the object deployed by the configuration on the cluster.') + c.argument('object_namespace', + help='Namespace of the object deployed by the configuration on the cluster.') + c.argument('object_kind', + arg_type=get_enum_type(['GitRepository', 'Bucket', 'HelmRepository', 'HelmChart', 'HelmRelease', 'Kustomization']), + help='Kind of the object deployed by the configuration on the cluster.') + with self.argument_context('k8s-configuration') as c: c.argument('name', options_list=['--name', '-n'], diff --git a/src/k8s-configuration/azext_k8s_configuration/commands.py b/src/k8s-configuration/azext_k8s_configuration/commands.py index ad471c24069..c14e162c4bd 100644 --- a/src/k8s-configuration/azext_k8s_configuration/commands.py +++ b/src/k8s-configuration/azext_k8s_configuration/commands.py @@ -10,6 +10,8 @@ k8s_configuration_sourcecontrol_client ) from .format import ( + fluxconfig_deployed_object_list_table_format, + fluxconfig_deployed_object_show_table_format, fluxconfig_list_table_format, fluxconfig_show_table_format, fluxconfig_kustomization_list_table_format, @@ -44,6 +46,10 @@ def load_command_table(self, _): g.custom_command('list', 'flux_config_list_kustomization', table_transformer=fluxconfig_kustomization_list_table_format) g.custom_show_command('show', 'flux_config_show_kustomization', table_transformer=fluxconfig_kustomization_show_table_format) + with self.command_group('k8s-configuration flux deployed-object', k8s_configuration_fluxconfig_sdk, client_factory=k8s_configuration_fluxconfig_client, is_preview=True) as g: + g.custom_command('list', 'flux_config_list_deployed_object', table_transformer=fluxconfig_deployed_object_list_table_format) + g.custom_show_command('show', 'flux_config_show_deployed_object', table_transformer=fluxconfig_deployed_object_show_table_format) + with self.command_group('k8s-configuration', k8s_configuration_sourcecontrol_sdk, client_factory=k8s_configuration_sourcecontrol_client) as g: g.custom_command('create', 'sourcecontrol_create', deprecate_info=self.deprecate(redirect='k8s-configuration flux create')) g.custom_command('list', 'sourcecontrol_list', table_transformer=sourcecontrol_list_table_format, deprecate_info=self.deprecate(redirect='k8s-configuration flux list')) diff --git a/src/k8s-configuration/azext_k8s_configuration/consts.py b/src/k8s-configuration/azext_k8s_configuration/consts.py index f008ba2e21c..606e766a5a2 100644 --- a/src/k8s-configuration/azext_k8s_configuration/consts.py +++ b/src/k8s-configuration/azext_k8s_configuration/consts.py @@ -64,6 +64,9 @@ SHOW_KUSTOMIZATION_NO_EXIST_ERROR = "Error! Kustomization with name '{0}' does not exist on configuration '{1}'." SHOW_KUSTOMIZATION_NO_EXIST_HELP = "You can view all kustomizations on a configuration with 'az k8s-configuration flux kustomization list'" +SHOW_DEPLOYED_OBJECT_NO_EXIST_ERROR = "Error! Deployed object with name '{0}', namespace '{1}', and kind '{2}' does not exist on configuration '{3}'." +SHOW_DEPLOYED_OBJECT_NO_EXIST_HELP = "You can view all deployed objects on a configuration with 'az k8s-configuration flux deployed-object list'" + SSH_PRIVATE_KEY_WITH_HTTP_URL_ERROR = "Error! An --ssh-private-key cannot be used with an http(s) url" SSH_PRIVATE_KEY_WITH_HTTP_URL_HELP = "Verify the url provided is a valid ssh url and not an http(s) url" diff --git a/src/k8s-configuration/azext_k8s_configuration/custom.py b/src/k8s-configuration/azext_k8s_configuration/custom.py index 91145605887..d14836fc077 100644 --- a/src/k8s-configuration/azext_k8s_configuration/custom.py +++ b/src/k8s-configuration/azext_k8s_configuration/custom.py @@ -121,6 +121,20 @@ def flux_config_show_kustomization(cmd, client, resource_group_name, cluster_typ return provider.show_kustomization(resource_group_name, cluster_type, cluster_name, name, kustomization_name) +def flux_config_list_deployed_object(cmd, client, resource_group_name, cluster_type, cluster_name, name): + + provider = FluxConfigurationProvider(cmd) + return provider.list_deployed_object(resource_group_name, cluster_type, cluster_name, name) + + +def flux_config_show_deployed_object(cmd, client, resource_group_name, cluster_type, cluster_name, name, + object_name, object_namespace, object_kind): + + provider = FluxConfigurationProvider(cmd) + return provider.show_deployed_object(resource_group_name, cluster_type, cluster_name, name, + object_name, object_namespace, object_kind) + + def flux_config_delete(cmd, client, resource_group_name, cluster_type, cluster_name, name, force=False, no_wait=False, yes=False): provider = FluxConfigurationProvider(cmd) diff --git a/src/k8s-configuration/azext_k8s_configuration/format.py b/src/k8s-configuration/azext_k8s_configuration/format.py index 2fd2b60bdb2..954a661b5fd 100644 --- a/src/k8s-configuration/azext_k8s_configuration/format.py +++ b/src/k8s-configuration/azext_k8s_configuration/format.py @@ -16,14 +16,16 @@ def sourcecontrol_show_table_format(result): def __get_sourcecontrolconfig_table_row(result): - return OrderedDict([ - ('name', result['name']), - ('repositoryUrl', result['repositoryUrl']), - ('operatorName', result['operatorInstanceName']), - ('operatorNamespace', result['operatorNamespace']), - ('scope', result['operatorScope']), - ('provisioningState', result['provisioningState']) - ]) + return OrderedDict( + [ + ("name", result["name"]), + ("repositoryUrl", result["repositoryUrl"]), + ("operatorName", result["operatorInstanceName"]), + ("operatorNamespace", result["operatorNamespace"]), + ("scope", result["operatorScope"]), + ("provisioningState", result["provisioningState"]), + ] + ) def fluxconfig_list_table_format(results): @@ -35,14 +37,16 @@ def fluxconfig_show_table_format(result): def __get_fluxconfig_table_row(result): - return OrderedDict([ - ('name', result['name']), - ('namespace', result['namespace']), - ('scope', result['scope']), - ('provisioningState', result['provisioningState']), - ('complianceState', result['complianceState']), - ('lastSourceSyncedAt', result['lastSourceSyncedAt']), - ]) + return OrderedDict( + [ + ("namespace", result["namespace"]), + ("name", result["name"]), + ("scope", result["scope"]), + ("provisioningState", result["provisioningState"]), + ("complianceState", result["complianceState"]), + ("lastSourceSyncedAt", result["lastSourceSyncedAt"]), + ] + ) def fluxconfig_kustomization_list_table_format(results): @@ -55,16 +59,45 @@ def fluxconfig_kustomization_show_table_format(results): def __get_fluxconfig_kustomization_table_row(key, value): deps = [] - for dep in value.get('dependsOn') or []: - if dep.get('kustomizationName'): - deps.append(dep['kustomizationName']) - - return OrderedDict([ - ('name', key), - ('path', value['path']), - ('dependsOn', ','.join(deps)), - ('syncInterval', format_duration(value['syncIntervalInSeconds'])), - ('timeout', format_duration(value['timeoutInSeconds'])), - ('prune', value['prune']), - ('force', value['force']) - ]) + for dep in value.get("dependsOn") or []: + if dep.get("kustomizationName"): + deps.append(dep["kustomizationName"]) + + return OrderedDict( + [ + ("name", key), + ("path", value["path"]), + ("dependsOn", ",".join(deps)), + ("syncInterval", format_duration(value["syncIntervalInSeconds"])), + ("timeout", format_duration(value["timeoutInSeconds"])), + ("prune", value["prune"]), + ("force", value["force"]), + ] + ) + + +def fluxconfig_deployed_object_list_table_format(results): + return [__get_fluxconfig_deployed_object_table_row(result) for result in results] + + +def fluxconfig_deployed_object_show_table_format(result): + return __get_fluxconfig_deployed_object_table_row(result) + + +def __get_fluxconfig_deployed_object_table_row(result): + message = "None" + for condition in result.get("statusConditions") or []: + if condition.get("type") == "Ready": + message = condition.get("message") + if len(message) > 60: + message = message[:60] + "..." + break + return OrderedDict( + [ + ("kind", result["kind"]), + ("namespace", result["namespace"]), + ("name", result["name"]), + ("complianceState", result["complianceState"]), + ("message", message), + ] + ) diff --git a/src/k8s-configuration/azext_k8s_configuration/providers/FluxConfigurationProvider.py b/src/k8s-configuration/azext_k8s_configuration/providers/FluxConfigurationProvider.py index 5275679545b..9bc3404c7fa 100644 --- a/src/k8s-configuration/azext_k8s_configuration/providers/FluxConfigurationProvider.py +++ b/src/k8s-configuration/azext_k8s_configuration/providers/FluxConfigurationProvider.py @@ -336,6 +336,26 @@ def show_kustomization(self, resource_group_name, cluster_type, cluster_name, na ) return {kustomization_name: current_config.kustomizations[kustomization_name]} + def list_deployed_object(self, resource_group_name, cluster_type, cluster_name, name): + # Determine ClusterRP + cluster_rp = get_cluster_rp(cluster_type) + current_config = self.client.get(resource_group_name, cluster_rp, cluster_type, cluster_name, name) + return current_config.statuses + + def show_deployed_object(self, resource_group_name, cluster_type, cluster_name, name, + object_name, object_namespace, object_kind): + # Determine ClusterRP + cluster_rp = get_cluster_rp(cluster_type) + current_config = self.client.get(resource_group_name, cluster_rp, cluster_type, cluster_name, name) + + for status in current_config.statuses: + if status.name == object_name and status.namespace == object_namespace and status.kind == object_kind: + return status + raise ValidationError( + consts.SHOW_DEPLOYED_OBJECT_NO_EXIST_ERROR.format(object_name, object_namespace, object_kind, name), + consts.SHOW_DEPLOYED_OBJECT_NO_EXIST_HELP + ) + def delete(self, resource_group_name, cluster_type, cluster_name, name, force, no_wait, yes): # Confirmation message for deletes user_confirmation_factory(self.cmd, yes) @@ -413,6 +433,9 @@ def _validate_extension_install(self, resource_group_name, cluster_rp, cluster_t consts.FLUX_EXTENSION_CREATING_HELP ) elif flux_extension.provisioning_state != consts.SUCCEEDED: + # Print the error detail so the user know how to fix it + if flux_extension.error_detail: + logger.error('%s %s', flux_extension.error_detail.code, flux_extension.error_detail.message) raise DeploymentError( consts.FLUX_EXTENSION_NOT_SUCCEEDED_OR_CREATING_ERROR, consts.FLUX_EXTENSION_NOT_SUCCEEDED_OR_CREATING_HELP diff --git a/src/k8s-configuration/setup.py b/src/k8s-configuration/setup.py index 048614fdd87..a3877af5ffe 100644 --- a/src/k8s-configuration/setup.py +++ b/src/k8s-configuration/setup.py @@ -14,7 +14,7 @@ from distutils import log as logger logger.warn("Wheel is not available, disabling bdist_wheel hook") -VERSION = '1.2.0' +VERSION = '1.3.0' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers