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 742fae1
Show file tree
Hide file tree
Showing 8 changed files with 75 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"
44 changes: 44 additions & 0 deletions spec/setup_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,48 @@ describe "Setup" do
ShellCmd.cnf_cleanup(expect_failure: true)
end
end

it "should correctly handle deployment priority" do
begin
result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-elk-stack/cnf-testsuite.yml timeout=600")
expect(result[:status].success?).to eq(true)

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (zombie)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_memory_hog)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (oran)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_latency)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_duplication)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (disk_fill)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_corruption)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_io_stress)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_delete)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_delete)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (zombie)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_io_stress)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (disk_fill)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_memory_hog)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_corruption)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_duplication)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (oran)

undefined method 'expect' for top-level

Check failure on line 161 in spec/setup_spec.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_latency)

undefined method 'expect' for top-level
expect(/CNF installation complete/ =~ result[:output]).not_to be_nil

# Verify installation order
installation_order = [
/All "elasticsearch" deployment resources are up/,
/All "logstash" deployment resources are up/,
/All "kibana" deployment resources are up/
]

last_match = -1
installation_order.each do |pattern|
current_match = pattern =~ result[:output]
expect(current_match).not_to be_nil
expect(current_match).to be > last_match
last_match = current_match
end

ensure
# Clean up and check uninstall order
cleanup_result = ShellCmd.cnf_cleanup()
expect(cleanup_result[:status].success?).to eq(true)
expect(/All CNF deployments were uninstalled/ =~ cleanup_result[:output]).not_to be_nil

# Verify uninstallation order
uninstallation_order = [
/Successfully uninstalled helm deployment "kibana"/,
/Successfully uninstalled helm deployment "logstash"/,
/Successfully uninstalled helm deployment "elasticsearch"/
]

last_uninstall_match = -1
uninstallation_order.each do |pattern|
current_match = pattern =~ cleanup_result[:output]
expect(current_match).not_to be_nil
expect(current_match).to be > last_uninstall_match
last_uninstall_match = current_match
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 742fae1

Please sign in to comment.