-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
installation: Create new installation process
Create new CNF installation process, that will support multiple deployments, be more comprehensible and easier to maintain. Don't replace the old one yet, both installation methods should exist simultaneously Refs: #2161 Signed-off-by: Konstantin Yarovoy <[email protected]>
- Loading branch information
Konstantin Yarovoy
committed
Oct 21, 2024
1 parent
7ee8aa8
commit e432397
Showing
7 changed files
with
322 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/tasks/utils/cnf_installation/deployment_management/deployment_manager_common.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module CNFInstall | ||
abstract class DeploymentManager | ||
property deployment_name : String | ||
|
||
abstract def install | ||
abstract def uninstall | ||
abstract def generate_manifest | ||
|
||
def initialize(deployment_name) | ||
@deployment_name = deployment_name | ||
end | ||
end | ||
|
||
|
||
end |
103 changes: 103 additions & 0 deletions
103
src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require "../config_versions/config_versions.cr" | ||
require "./deployment_manager_common.cr" | ||
|
||
module CNFInstall | ||
abstract class HelmDeploymentManager < DeploymentManager | ||
def initialize(deployment_name) | ||
super(deployment_name) | ||
end | ||
|
||
abstract def get_deployment_name() | ||
abstract def get_deployment_namespace() | ||
|
||
def install_from_folder(chart_path, helm_namespace, helm_values) | ||
begin | ||
#TODO (kosstennbl) fix Helm install to add -n to namespace and remove it there | ||
response = Helm.install(release_name: @deployment_name, helm_chart: chart_path, namespace: "-n #{helm_namespace}", values: helm_values) | ||
if !response[:status].success? | ||
stdout_failure "Helm installation failed, stderr:" | ||
stdout_failure "\t#{response[:error]}" | ||
exit 1 | ||
end | ||
rescue e : Helm::InstallationFailed | ||
stdout_failure "Helm installation failed with message:" | ||
stdout_failure "\t#{e.message}" | ||
exit 1 | ||
rescue e : Helm::CannotReuseReleaseNameError | ||
stdout_failure "Helm deployment \"#{@deployment_name}\" already exists in \"#{helm_namespace}\" namespace." | ||
stdout_failure "Change deployment name in CNF configuration or uninstall existing deployment." | ||
exit 1 | ||
end | ||
end | ||
|
||
def uninstall() | ||
deployment_name = get_deployment_name() | ||
helm_uninstall_cmd = "#{deployment_name} -n #{get_deployment_namespace()}" | ||
result = Helm.uninstall(helm_uninstall_cmd) | ||
if result[:status].success? | ||
stdout_success "Successfully uninstalled helm deployment \"#{deployment_name}\"." | ||
end | ||
end | ||
|
||
def generate_manifest() | ||
namespace = get_deployment_namespace() | ||
generated_manifest = Helm.generate_manifest(get_deployment_name(), namespace) | ||
generated_manifest_with_namespaces = Manifest.add_namespace_to_resources(generated_manifest, namespace) | ||
end | ||
end | ||
|
||
class HelmChartDeploymentManager < HelmDeploymentManager | ||
@helm_chart_config : ConfigV2::HelmChartConfig | ||
def initialize(helm_chart_config) | ||
super(helm_chart_config.name) | ||
@helm_chart_config = helm_chart_config | ||
end | ||
|
||
def install() | ||
helm_repo_url = @helm_chart_config.helm_repo_url | ||
helm_repo_name = @helm_chart_config.helm_repo_name | ||
helm_chart_name = @helm_chart_config.helm_chart_name | ||
|
||
if !helm_repo_url.empty? | ||
Helm.helm_repo_add(helm_repo_name, helm_repo_url) | ||
end | ||
helm_pull_destination = File.join(DEPLOYMENTS_DIR, @deployment_name) | ||
helm_pull_cmd = "#{helm_repo_name}/#{helm_chart_name} --untar --destination #{helm_pull_destination}" | ||
pull_response = Helm.pull(helm_pull_cmd) | ||
if !pull_response[:status].success? | ||
raise Helm::InstallationFailed.new("Helm pull failed: #{pull_response[:error]}") | ||
end | ||
chart_path = File.join(helm_pull_destination, helm_chart_name) | ||
install_from_folder(chart_path, get_deployment_namespace(), @helm_chart_config.helm_values) | ||
end | ||
|
||
def get_deployment_name() | ||
@helm_chart_config.name | ||
end | ||
|
||
def get_deployment_namespace() | ||
@helm_chart_config.namespace.empty? ? DEFAULT_CNF_NAMESPACE : @helm_chart_config.namespace | ||
end | ||
end | ||
|
||
class HelmDirectoryDeploymentManager < HelmDeploymentManager | ||
@helm_directory_config : ConfigV2::HelmDirectoryConfig | ||
def initialize(helm_directory_config) | ||
super(helm_directory_config.name) | ||
@helm_directory_config = helm_directory_config | ||
end | ||
|
||
def install() | ||
chart_path = File.join(DEPLOYMENTS_DIR, @deployment_name, @helm_directory_config.helm_directory) | ||
install_from_folder(chart_path, get_deployment_namespace(), @helm_directory_config.helm_values) | ||
end | ||
|
||
def get_deployment_name() | ||
@helm_directory_config.name | ||
end | ||
|
||
def get_deployment_namespace() | ||
@helm_directory_config.namespace.empty? ? DEFAULT_CNF_NAMESPACE : @helm_directory_config.namespace | ||
end | ||
end | ||
end |
37 changes: 37 additions & 0 deletions
37
src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "../config_versions/config_versions.cr" | ||
require "./deployment_manager_common.cr" | ||
|
||
|
||
module CNFInstall | ||
class ManifestDeploymentManager < DeploymentManager | ||
@manifest_config : ConfigV2::ManifestDirectoryConfig | ||
@manifest_directory_path : String | ||
|
||
def initialize(manifest_config) | ||
super(manifest_config.name) | ||
@manifest_config = manifest_config | ||
@manifest_directory_path = File.join(DEPLOYMENTS_DIR, @deployment_name, @manifest_config.manifest_directory) | ||
end | ||
|
||
def install() | ||
KubectlClient::Apply.file(@manifest_directory_path) | ||
end | ||
|
||
def uninstall() | ||
result = KubectlClient::Delete.file(@manifest_directory_path, wait: true) | ||
if result[:status].success? | ||
stdout_success "Successfully uninstalled manifest deployment \"#{@manifest_config.name}\"" | ||
end | ||
end | ||
|
||
def generate_manifest() | ||
deployment_manifest = "" | ||
list_of_manifests = Manifest.manifest_file_list(@manifest_directory_path) | ||
list_of_manifests.each do |manifest_path| | ||
manifest = File.read(manifest_path) | ||
deployment_manifest = deployment_manifest + manifest + "\n" | ||
end | ||
deployment_manifest | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters