Skip to content

Commit

Permalink
installation: Add possibility to specify installation order
Browse files Browse the repository at this point in the history
Add installation_priority parameter for specification of order
for installation of deployments.

Refs: #2176
Signed-off-by: Konstantin Yarovoy <[email protected]>
  • Loading branch information
Konstantin Yarovoy committed Dec 3, 2024
1 parent d9575ef commit 98f99bb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CNF_TESTSUITE_YML_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
```

Expand Down
2 changes: 2 additions & 0 deletions sample-cnfs/sample-elk-stack/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/setup_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/utils/cnf_installation/install_common.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 98f99bb

Please sign in to comment.