Skip to content

Commit 98f99bb

Browse files
author
Konstantin Yarovoy
committedDec 3, 2024
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 <konstantin.yarovoy@tietoevry.com>
1 parent d9575ef commit 98f99bb

File tree

8 files changed

+35
-10
lines changed

8 files changed

+35
-10
lines changed
 

‎CNF_TESTSUITE_YML_USAGE.md

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ deployments:
134134
...
135135
```
136136

137+
##### Installation priority
138+
139+
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.
140+
137141
##### helm_charts
138142

139143
Deployment, defined by helm chart and helm repository.
@@ -143,6 +147,7 @@ Explanations with example:
143147
```yaml
144148
helm_charts:
145149
- name: coredns # Name of the deployment
150+
installation_priority: 0 # Installation priority of deployment
146151
helm_repo_name: stable # Name of the repository for the helm chart
147152
helm_repo_url: https://cncf.gitlab.io/stable # Repository URL
148153
helm_chart_name: coredns # Name of the helm chart in format repo_name/chart_name
@@ -157,6 +162,7 @@ Explanations with example:
157162
```yaml
158163
helm_dirs:
159164
- name: envoy # Name of the deployment
165+
installation_priority: 0 # Installation priority of deployment
160166
helm_directory: chart # Path to the directory with Chart.yaml, relative to CNF configuration file
161167
helm_values: --set myvalue=42 # Additional values that would be used for helm installation
162168
namespace: cnf-default # Namespace to which deployment would be installed (cnf-default is default)
@@ -169,6 +175,7 @@ Explanations with example:
169175
```yaml
170176
manifests:
171177
- name: nginx # Name of the deployment
178+
installation_priority: 0 # Installation priority of deployment
172179
manifest_directory: manifests # Path to the directory with deployment manifests, relative to CNF configuration file
173180
```
174181

‎sample-cnfs/sample-elk-stack/cnf-testsuite.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ config_version: "v2"
44
deployments:
55
helm_charts:
66
- name: elasticsearch
7+
installation_priority: 2
78
helm_repo_name: elastic
89
helm_repo_url: https://helm.elastic.co
910
helm_chart_name: elasticsearch
1011
helm_values: "--set replicas=1"
1112
- name: logstash
13+
installation_priority: 1
1214
helm_repo_name: elastic
1315
helm_repo_url: https://helm.elastic.co
1416
helm_chart_name: logstash

‎spec/setup_spec.cr

+13
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,17 @@ describe "Setup" do
154154
ShellCmd.cnf_cleanup(expect_failure: true)
155155
end
156156
end
157+
158+
it "'cnf_setup' should correctly handle deployment priority", tags: ["setup"] do
159+
# (kosstennbl) ELK stack requires to be installed with specific order, otherwise it would give errors
160+
begin
161+
result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-elk-stack/cnf-testsuite.yml timeout=600")
162+
result[:status].success?.should be_true
163+
(/CNF installation complete/ =~ result[:output]).should_not be_nil
164+
ensure
165+
result = ShellCmd.cnf_cleanup()
166+
result[:status].success?.should be_true
167+
(/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil
168+
end
169+
end
157170
end

‎src/tasks/utils/cnf_installation/config_versions/config_v2.cr

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ module CNFInstall
5050
end
5151

5252
class DeploymentConfig < CNFInstall::Config::ConfigBase
53-
getter name : String
53+
getter name : String,
54+
installation_priority = 0
5455
end
5556

5657
class HelmDeploymentConfig < DeploymentConfig

‎src/tasks/utils/cnf_installation/deployment_management/deployment_manager_common.cr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module CNFInstall
22
abstract class DeploymentManager
3-
property deployment_name : String
3+
property deployment_name : String,
4+
installation_priority : Int32
45

56
abstract def install
67
abstract def uninstall
78
abstract def generate_manifest
89

9-
def initialize(deployment_name)
10+
def initialize(deployment_name, installation_priority)
1011
@deployment_name = deployment_name
12+
@installation_priority = installation_priority
1113
end
1214
end
1315

‎src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ require "./deployment_manager_common.cr"
33

44
module CNFInstall
55
abstract class HelmDeploymentManager < DeploymentManager
6-
def initialize(deployment_name)
7-
super(deployment_name)
6+
def initialize(deployment_name, installation_priority)
7+
super(deployment_name, installation_priority)
88
end
99

1010
abstract def get_deployment_config() : ConfigV2::HelmDeploymentConfig
@@ -64,7 +64,7 @@ module CNFInstall
6464
@helm_chart_config : ConfigV2::HelmChartConfig
6565

6666
def initialize(helm_chart_config)
67-
super(helm_chart_config.name)
67+
super(helm_chart_config.name, helm_chart_config.installation_priority)
6868
@helm_chart_config = helm_chart_config
6969
end
7070

@@ -98,7 +98,7 @@ module CNFInstall
9898
@helm_directory_config : ConfigV2::HelmDirectoryConfig
9999

100100
def initialize(helm_directory_config)
101-
super(helm_directory_config.name)
101+
super(helm_directory_config.name, helm_directory_config.installation_priority)
102102
@helm_directory_config = helm_directory_config
103103
end
104104

‎src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module CNFInstall
88
@manifest_directory_path : String
99

1010
def initialize(manifest_config)
11-
super(manifest_config.name)
11+
super(manifest_config.name, manifest_config.installation_priority)
1212
@manifest_config = manifest_config
1313
@manifest_directory_path = File.join(DEPLOYMENTS_DIR, @deployment_name, @manifest_config.manifest_directory)
1414
end

‎src/tasks/utils/cnf_installation/install_common.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module CNFInstall
1414

1515
prepare_deployment_directories(config, cnf_config_path)
1616

17-
deployment_managers = create_deployment_manager_list(config)
17+
deployment_managers = create_deployment_manager_list(config).reverse
1818
install_deployments(parsed_args: parsed_args, deployment_managers: deployment_managers)
1919
end
2020

@@ -83,7 +83,7 @@ module CNFInstall
8383
config.deployments.manifests.each do |manifest_config|
8484
deployment_managers << ManifestDeploymentManager.new(manifest_config)
8585
end
86-
deployment_managers
86+
deployment_managers.sort! { |a, b| a.installation_priority <=> b.installation_priority }
8787
end
8888

8989
def self.install_deployments(parsed_args, deployment_managers)

0 commit comments

Comments
 (0)