Skip to content

Commit

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

Signed-off-by: Konstantin Yarovoy <[email protected]>
  • Loading branch information
Konstantin Yarovoy authored and svteb committed Dec 18, 2024
1 parent d9575ef commit 9043c91
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 11 deletions.
15 changes: 15 additions & 0 deletions CNF_TESTSUITE_YML_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ deployments:
...
```

##### Deployment priority

To ensure deployments are executed in a specific order, you can use the `priority` parameter. Deployments are processed in ascending order of their `priority` values, starting with the lowest. During uninstallation, the order is reversed, processing from the highest `priority` value to the lowest. If the `priority` parameter is not specified, it defaults to 0.

```yaml
deployments:
helm_dirs:
- name: envoy # deploys second
helm_directory: ../example-cnfs/envoy/envoy
priority: 1
manifests:
- name: nginx # implicit priority = 0, deploys first
manifest_directory: manifests
```

##### helm_charts

Deployment, defined by helm chart and helm repository.
Expand Down
4 changes: 3 additions & 1 deletion sample-cnfs/sample-elk-stack/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ deployments:
helm_chart_name: elasticsearch
helm_values: "--set replicas=1"
- name: logstash
priority: 1
helm_repo_name: elastic
helm_repo_url: https://helm.elastic.co
helm_chart_name: logstash
helm_values: "--set replicaCount=1"
- name: kibana
priority: 2
helm_repo_name: elastic
helm_repo_url: https://helm.elastic.co
helm_chart_name: kibana
helm_values: "--set replicaCount=1"
helm_values: "--set replicaCount=1 --set elasticsearchHosts=http://elasticsearch-master:9200"
52 changes: 52 additions & 0 deletions spec/setup_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,56 @@ describe "Setup" do
ShellCmd.cnf_cleanup(expect_failure: true)
end
end

it "'cnf_setup' should correctly handle deployment priority", tags: ["setup"] do
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

lines = result[:output].split('\n')

installation_order = [
/All "elasticsearch" deployment resources are up/,
/All "logstash" deployment resources are up/,
/All "kibana" deployment resources are up/
]

# Find line indices for each installation regex
install_line_indices = installation_order.map do |regex|
idx = lines.index { |line| regex =~ line }
idx.should_not be_nil
idx.not_nil! # Ensures idx is Int32, not Int32|Nil
end

# Verify installation order
install_line_indices.each_cons(2) do |pair|
pair[1].should be > pair[0]
end
ensure
result = ShellCmd.cnf_cleanup()
result[:status].success?.should be_true
(/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil

lines = result[:output].split('\n')

uninstallation_order = [
/Successfully uninstalled helm deployment "kibana"/,
/Successfully uninstalled helm deployment "logstash"/,
/Successfully uninstalled helm deployment "elasticsearch"/
]

# Find line indices for each uninstallation regex
uninstall_line_indices = uninstallation_order.map do |regex|
idx = lines.index { |line| regex =~ line }
idx.should_not be_nil
idx.not_nil!
end

# Verify uninstallation order
uninstall_line_indices.each_cons(2) do |pair|
pair[1].should be > pair[0]
end
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,
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,
deployment_priority : Int32

abstract def install
abstract def uninstall
abstract def generate_manifest

def initialize(deployment_name)
def initialize(deployment_name, deployment_priority)
@deployment_name = deployment_name
@deployment_priority = deployment_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, deployment_priority)
super(deployment_name, deployment_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.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.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.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 @@ -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.deployment_priority <=> b.deployment_priority }
end

def self.install_deployments(parsed_args, deployment_managers)
Expand Down Expand Up @@ -136,7 +136,7 @@ module CNFInstall
end
config = Config.parse_cnf_config_from_file(cnf_config_path)

deployment_managers = create_deployment_manager_list(config)
deployment_managers = create_deployment_manager_list(config).reverse
uninstall_deployments(deployment_managers)

FileUtils.rm_rf(CNF_DIR)
Expand Down

0 comments on commit 9043c91

Please sign in to comment.