-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
For supporting multiple deployments in one cnf and improving overall config usability and structure - new config format has to be introduced. Some existing parameters usage need to be changed for easier adaptation. This change does not replace the old config format. Refs: cnti-testcatalog#2121 Signed-off-by: Konstantin Yarovoy <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
config_version: "v2" | ||
common: | ||
container_names: | ||
- name: coredns | ||
rolling_update_test_tag: "1.8.0" | ||
rolling_downgrade_test_tag: 1.6.7 | ||
rolling_version_change_test_tag: 1.8.0 | ||
rollback_from_tag: 1.8.0 | ||
|
||
deployments: | ||
helm_charts: | ||
- name: coredns | ||
helm_repo_name: stable | ||
helm_repo_url: https://cncf.gitlab.io/stable | ||
helm_chart_name: coredns | ||
helm_dirs: | ||
- name: envoy | ||
helm_directory: ../example-cnfs/envoy/envoy/ | ||
manifests: | ||
- name: nginx | ||
manifest_directory: ../sample_cnfs/ndn-mutable-configmap/manifests | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
require "yaml" | ||
require "../utils.cr" | ||
|
||
module CNFInstall | ||
module Config | ||
@[YAML::Serializable::Options(emit_nulls: true)] | ||
alias AnyDeploymentConfig = HelmChartConfig | HelmDirectoryConfig | ManifestDirectoryConfig | ||
|
||
class ConfigBase | ||
include YAML::Serializable | ||
include YAML::Serializable::Strict | ||
end | ||
|
||
class Config < ConfigBase | ||
# TODO: remove as much parameters as possible | ||
@config_version : String | ||
@common : CommonParameters | Nil | ||
@dynamic : DynamicParameters | Nil | ||
@deployments : DeploymentsConfig | ||
getter config_version, common, deployments | ||
getter! dynamic | ||
|
||
def after_initialize | ||
unless @dynamic | ||
@dynamic = DynamicParameters.new() | ||
end | ||
end | ||
end | ||
|
||
class CommonParameters < ConfigBase | ||
@service_name : String | Nil | ||
@rolling_update_tag : String | Nil | ||
@container_names : Array(Hash(String, String)) | Nil | ||
@white_list_container_names : Array(String) | Nil | ||
@docker_insecure_registries : Array(String) | Nil | ||
@image_registry_fqdns : Hash(String, String) | Nil | ||
@five_g_parameters : FiveGParameters | Nil | ||
getter service_name, rolling_update_tag, container_names, white_list_container_names | ||
getter docker_insecure_registries, image_registry_fqdns, five_g_parameters | ||
end | ||
|
||
class DynamicParameters < ConfigBase | ||
@source_cnf_dir : String | Nil | ||
@destination_cnf_dir : String | Nil | ||
@install_method : Tuple(CNFInstall::InstallMethod, String) | Nil | ||
property source_cnf_dir, destination_cnf_dir | ||
property install_method | ||
|
||
def initialize() | ||
end | ||
end | ||
|
||
class DeploymentsConfig < ConfigBase | ||
@helm_charts : Array(HelmChartConfig) = [] of HelmChartConfig | ||
@helm_dirs : Array(HelmDirectoryConfig) = [] of HelmDirectoryConfig | ||
@manifests : Array(ManifestDirectoryConfig) = [] of ManifestDirectoryConfig | ||
# deployments.current and all related functionality should be removed with new installation process. | ||
@@current : AnyDeploymentConfig | ||
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (pod_io_stress)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (pod_network_latency)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (zombie)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (pod_delete)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (pod_memory_hog)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (pod_network_duplication)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (disk_fill)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (oran)
Check failure on line 58 in src/tasks/utils/cnf_installation/config.cr GitHub Actions / Chaos & Oran Tests (pod_network_corruption)
|
||
getter helm_charts, helm_dirs, manifests | ||
|
||
def after_initialize | ||
if @helm_charts.empty? && @helm_dirs.empty? && @manifests.empty? | ||
raise YAML::Error.new("At least one deployment should be configured") | ||
end | ||
|
||
deployment_names = Set(String).new | ||
deployment_found = false | ||
{@helm_charts, @helm_dirs, @manifests}.each do |deployment_array| | ||
if deployment_array | ||
|
||
# To be removed with new installation process. | ||
if deployment_found | ||
raise YAML::Error.new("Multiple deployments are not supported yet") | ||
else | ||
deployment_found = true | ||
end | ||
@@current = deployment_array[0] | ||
# | ||
|
||
deployment_array.each do |deployment| | ||
if deployment_names.includes?(deployment.name) | ||
raise YAML::Error.new("Deployment names should be unique: \"#{deployment.name}\"") | ||
else | ||
deployment_names.add(deployment.name) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
def get_deployment_param(param : Symbol) : String? | ||
case @@current | ||
when HelmChartConfig | ||
case param | ||
when :name then @@current.name | ||
when :helm_repo_name then @@current.helm_repo_name | ||
when :helm_repo_url then @@current.helm_repo_url | ||
when :helm_chart_name then @@current.helm_chart_name | ||
when :helm_values then @@current.helm_values | ||
when :namespace then @@current.namespace | ||
else nil | ||
end | ||
when HelmDirectoryConfig | ||
case param | ||
when :name then @@current.name | ||
when :helm_directory then @@current.helm_directory | ||
when :helm_values then @@current.helm_values | ||
when :namespace then @@current.namespace | ||
else nil | ||
end | ||
when ManifestDirectoryConfig | ||
case param | ||
when :name then @@current.name | ||
when :manifest_directory then @@current.manifest_directory | ||
else nil | ||
end | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
|
||
class DeploymentConfig < ConfigBase | ||
@name : String | ||
getter name | ||
end | ||
|
||
class HelmDeploymentConfig < DeploymentConfig | ||
@helm_values : String | Nil | ||
@namespace : String | Nil | ||
getter helm_values, namespace | ||
end | ||
|
||
class HelmChartConfig < HelmDeploymentConfig | ||
@helm_repo_name : String | ||
@helm_repo_url : String | ||
@helm_chart_name : String | ||
|
||
getter helm_repo_name, helm_repo_url, helm_chart_name | ||
end | ||
|
||
class HelmDirectoryConfig < HelmDeploymentConfig | ||
@helm_directory : String | ||
getter helm_directory | ||
end | ||
|
||
class ManifestDirectoryConfig < DeploymentConfig | ||
@manifest_directory : String | ||
getter manifest_directory | ||
end | ||
|
||
class FiveGParameters < ConfigBase | ||
@amf_label : String | Nil | ||
@smf_label : String | Nil | ||
@upf_label : String | Nil | ||
@ric_label : String | Nil | ||
@amf_service_name : String | Nil | ||
@mmc : String | Nil | ||
@mnc : String | Nil | ||
@sst : String | Nil | ||
@sd : String | Nil | ||
@tac : String | Nil | ||
@protectionScheme : String | Nil | ||
@publicKey : String | Nil | ||
@publicKeyId : String | Nil | ||
@routingIndicator : String | Nil | ||
@enabled : String | Nil | ||
@count : String | Nil | ||
@initialMSISDN : String | Nil | ||
@key : String | Nil | ||
@op : String | Nil | ||
@opType : String | Nil | ||
@type : String | Nil | ||
@apn : String | Nil | ||
@emergency : String | Nil | ||
end | ||
|
||
def self.parse_cnf_config_from_file(path_to_config) | ||
yaml_content = File.read(path_to_config) | ||
config_dir = CNFManager.ensure_cnf_testsuite_dir(path_to_config) | ||
begin | ||
parse_cnf_config_from_yaml(yaml_content, config_dir) | ||
rescue exception | ||
stdout_failure "Error during parsing CNF config on #{path_to_config}" | ||
stdout_failure exception.message | ||
stdout_failure "Please check your config according to the config template." | ||
exit 1 | ||
end | ||
end | ||
|
||
def self.parse_cnf_config_from_yaml(yaml_content, config_dir) | ||
config = Config.from_yaml(yaml_content) | ||
|
||
unless config.dynamic.source_cnf_dir | ||
config.dynamic.source_cnf_dir = config_dir | ||
end | ||
|
||
unless config.dynamic.install_method | ||
config.dynamic.install_method = get_install_method_from_deployments(config.deployments) | ||
end | ||
|
||
unless config.dynamic.destination_cnf_dir | ||
install_method = config.dynamic.install_method.not_nil![0] | ||
case install_method | ||
when CNFInstall::InstallMethod::HelmChart | ||
deployment_name = config.deployments.helm_charts[0].name | ||
when CNFInstall::InstallMethod::HelmDirectory | ||
deployment_name = config.deployments.helm_dirs[0].name | ||
when CNFInstall::InstallMethod::ManifestDirectory | ||
deployment_name = config.deployments.manifests[0].name | ||
else | ||
raise "Unknown install method: #{install_method}" | ||
end | ||
current_dir = FileUtils.pwd | ||
config.dynamic.destination_cnf_dir = "#{current_dir}/#{CNF_DIR}/#{deployment_name}" | ||
end | ||
|
||
config | ||
end | ||
|
||
def self.get_install_method_from_deployments(deployments_config) | ||
if !deployments_config.helm_charts.empty? | ||
helm_chart_name = deployments_config.helm_charts[0].helm_chart_name | ||
{CNFInstall::InstallMethod::HelmChart, helm_chart_name} | ||
|
||
elsif !deployments_config.helm_dirs.empty? | ||
helm_directory = deployments_config.helm_dirs[0].helm_directory | ||
deployment_name = deployments_config.helm_dirs[0].name | ||
full_helm_directory = Path[CNF_DIR + "/" + deployment_name + "/" + CNFManager.sandbox_helm_directory(helm_directory)].expand.to_s | ||
{CNFInstall::InstallMethod::HelmDirectory, full_helm_directory} | ||
|
||
elsif !deployments_config.manifests.empty? | ||
manifest_directory = deployments_config.manifests[0].manifest_directory | ||
deployment_name = deployments_config.manifests[0].name | ||
full_manifest_directory = Path[CNF_DIR + "/" + deployment_name + "/" + CNFManager.sandbox_helm_directory(manifest_directory)].expand.to_s | ||
{CNFInstall::InstallMethod::ManifestDirectory, full_manifest_directory} | ||
|
||
else | ||
raise YAML::Error.new("At least one deployment should be configured") | ||
end | ||
end | ||
end | ||
end |