From 98f99bb7ef5a4bccae8b6047c33eab4d6353074e Mon Sep 17 00:00:00 2001 From: Konstantin Yarovoy Date: Fri, 22 Nov 2024 09:38:37 +0000 Subject: [PATCH] installation: Add possibility to specify installation order Add installation_priority parameter for specification of order for installation of deployments. Refs: #2176 Signed-off-by: Konstantin Yarovoy --- CNF_TESTSUITE_YML_USAGE.md | 7 +++++++ sample-cnfs/sample-elk-stack/cnf-testsuite.yml | 2 ++ spec/setup_spec.cr | 13 +++++++++++++ .../cnf_installation/config_versions/config_v2.cr | 3 ++- .../deployment_manager_common.cr | 6 ++++-- .../helm_deployment_manager.cr | 8 ++++---- .../manifest_deployment_manager.cr | 2 +- src/tasks/utils/cnf_installation/install_common.cr | 4 ++-- 8 files changed, 35 insertions(+), 10 deletions(-) diff --git a/CNF_TESTSUITE_YML_USAGE.md b/CNF_TESTSUITE_YML_USAGE.md index 0da43acae..e79195fb6 100644 --- a/CNF_TESTSUITE_YML_USAGE.md +++ b/CNF_TESTSUITE_YML_USAGE.md @@ -134,6 +134,10 @@ deployments: ... ``` +##### Installation priority + +If deployments needed to be installed in specific order, installation_priority parameter should be used. All of the deployments would be installed in order from highest installation priority to lowest. This parameter also affects uninstallation order, it would be reversed: from lowest installation_priority to highest. If not specified, installation priority for deployment is 0. + ##### helm_charts Deployment, defined by helm chart and helm repository. @@ -143,6 +147,7 @@ Explanations with example: ```yaml helm_charts: - name: coredns # Name of the deployment + installation_priority: 0 # Installation priority of deployment helm_repo_name: stable # Name of the repository for the helm chart helm_repo_url: https://cncf.gitlab.io/stable # Repository URL helm_chart_name: coredns # Name of the helm chart in format repo_name/chart_name @@ -157,6 +162,7 @@ Explanations with example: ```yaml helm_dirs: - name: envoy # Name of the deployment + installation_priority: 0 # Installation priority of deployment helm_directory: chart # Path to the directory with Chart.yaml, relative to CNF configuration file helm_values: --set myvalue=42 # Additional values that would be used for helm installation namespace: cnf-default # Namespace to which deployment would be installed (cnf-default is default) @@ -169,6 +175,7 @@ Explanations with example: ```yaml manifests: - name: nginx # Name of the deployment + installation_priority: 0 # Installation priority of deployment manifest_directory: manifests # Path to the directory with deployment manifests, relative to CNF configuration file ``` diff --git a/sample-cnfs/sample-elk-stack/cnf-testsuite.yml b/sample-cnfs/sample-elk-stack/cnf-testsuite.yml index a41b30f51..c5c9e8e3d 100644 --- a/sample-cnfs/sample-elk-stack/cnf-testsuite.yml +++ b/sample-cnfs/sample-elk-stack/cnf-testsuite.yml @@ -4,11 +4,13 @@ config_version: "v2" deployments: helm_charts: - name: elasticsearch + installation_priority: 2 helm_repo_name: elastic helm_repo_url: https://helm.elastic.co helm_chart_name: elasticsearch helm_values: "--set replicas=1" - name: logstash + installation_priority: 1 helm_repo_name: elastic helm_repo_url: https://helm.elastic.co helm_chart_name: logstash diff --git a/spec/setup_spec.cr b/spec/setup_spec.cr index 639e24523..1952892eb 100644 --- a/spec/setup_spec.cr +++ b/spec/setup_spec.cr @@ -154,4 +154,17 @@ describe "Setup" do ShellCmd.cnf_cleanup(expect_failure: true) end end + + it "'cnf_setup' should correctly handle deployment priority", tags: ["setup"] do + # (kosstennbl) ELK stack requires to be installed with specific order, otherwise it would give errors + begin + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-elk-stack/cnf-testsuite.yml timeout=600") + result[:status].success?.should be_true + (/CNF installation complete/ =~ result[:output]).should_not be_nil + ensure + result = ShellCmd.cnf_cleanup() + result[:status].success?.should be_true + (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil + end + end end diff --git a/src/tasks/utils/cnf_installation/config_versions/config_v2.cr b/src/tasks/utils/cnf_installation/config_versions/config_v2.cr index 9c71c76f9..6f474e1f2 100644 --- a/src/tasks/utils/cnf_installation/config_versions/config_v2.cr +++ b/src/tasks/utils/cnf_installation/config_versions/config_v2.cr @@ -50,7 +50,8 @@ module CNFInstall end class DeploymentConfig < CNFInstall::Config::ConfigBase - getter name : String + getter name : String, + installation_priority = 0 end class HelmDeploymentConfig < DeploymentConfig diff --git a/src/tasks/utils/cnf_installation/deployment_management/deployment_manager_common.cr b/src/tasks/utils/cnf_installation/deployment_management/deployment_manager_common.cr index aa5ba4124..d77c1aaab 100644 --- a/src/tasks/utils/cnf_installation/deployment_management/deployment_manager_common.cr +++ b/src/tasks/utils/cnf_installation/deployment_management/deployment_manager_common.cr @@ -1,13 +1,15 @@ module CNFInstall abstract class DeploymentManager - property deployment_name : String + property deployment_name : String, + installation_priority : Int32 abstract def install abstract def uninstall abstract def generate_manifest - def initialize(deployment_name) + def initialize(deployment_name, installation_priority) @deployment_name = deployment_name + @installation_priority = installation_priority end end diff --git a/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr b/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr index 58e36714b..2931798a6 100644 --- a/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr +++ b/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr @@ -3,8 +3,8 @@ require "./deployment_manager_common.cr" module CNFInstall abstract class HelmDeploymentManager < DeploymentManager - def initialize(deployment_name) - super(deployment_name) + def initialize(deployment_name, installation_priority) + super(deployment_name, installation_priority) end abstract def get_deployment_config() : ConfigV2::HelmDeploymentConfig @@ -64,7 +64,7 @@ module CNFInstall @helm_chart_config : ConfigV2::HelmChartConfig def initialize(helm_chart_config) - super(helm_chart_config.name) + super(helm_chart_config.name, helm_chart_config.installation_priority) @helm_chart_config = helm_chart_config end @@ -98,7 +98,7 @@ module CNFInstall @helm_directory_config : ConfigV2::HelmDirectoryConfig def initialize(helm_directory_config) - super(helm_directory_config.name) + super(helm_directory_config.name, helm_directory_config.installation_priority) @helm_directory_config = helm_directory_config end diff --git a/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr b/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr index 787f2d845..a8c80d8ec 100644 --- a/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr +++ b/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr @@ -8,7 +8,7 @@ module CNFInstall @manifest_directory_path : String def initialize(manifest_config) - super(manifest_config.name) + super(manifest_config.name, manifest_config.installation_priority) @manifest_config = manifest_config @manifest_directory_path = File.join(DEPLOYMENTS_DIR, @deployment_name, @manifest_config.manifest_directory) end diff --git a/src/tasks/utils/cnf_installation/install_common.cr b/src/tasks/utils/cnf_installation/install_common.cr index b57df2614..f454d2df8 100644 --- a/src/tasks/utils/cnf_installation/install_common.cr +++ b/src/tasks/utils/cnf_installation/install_common.cr @@ -14,7 +14,7 @@ module CNFInstall prepare_deployment_directories(config, cnf_config_path) - deployment_managers = create_deployment_manager_list(config) + deployment_managers = create_deployment_manager_list(config).reverse install_deployments(parsed_args: parsed_args, deployment_managers: deployment_managers) end @@ -83,7 +83,7 @@ module CNFInstall config.deployments.manifests.each do |manifest_config| deployment_managers << ManifestDeploymentManager.new(manifest_config) end - deployment_managers + deployment_managers.sort! { |a, b| a.installation_priority <=> b.installation_priority } end def self.install_deployments(parsed_args, deployment_managers)