Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation: add installation_priority parameter #2182

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: "--version 7.17.3 --set replicaCount=1"
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=300")
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
svteb marked this conversation as resolved.
Show resolved Hide resolved

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
Loading