diff --git a/CNF_TESTSUITE_YML_USAGE.md b/CNF_TESTSUITE_YML_USAGE.md index 1de8061b0..a5b80ce58 100644 --- a/CNF_TESTSUITE_YML_USAGE.md +++ b/CNF_TESTSUITE_YML_USAGE.md @@ -29,7 +29,7 @@ helm_repository: # CONFIGURATION OF HELM REPO - ONLY NEEDED WHEN USING helm_char #manifest_directory: coredns # PATH_TO_DIRECTORY_OF_CNFS_MANIFEST_FILES ; or release_name: coredns # DESIRED_HELM_RELEASE_NAME helm_values: --versions 16.2.0 --set persistence.enabled=false -helm_install_namespace: cnfspace # Installs the CNF to it's own namespace and not in the default namespace +helm_install_namespace: cnf-coredns # Installs the CNF to it's own namespace ``` @@ -103,13 +103,15 @@ Example Setting: #### helm_install_namespace -This sets the namespace that helm will use to install the CNF to. This is to conform to the best practice of not installing your CNF to the `default` namespace on your cluster. You can learn more about this practice [here](./docs/TEST_DOCUMENTATION.md#default-namespaces). This is an optional setting but highly recommended as installing your CNF to use the `default` namespace will result with failed tests. +This configuration option specifies the namespace that Helm will use to install the CNF. Following best practices, it is recommended not to install your CNF into the `default` namespace of your cluster. For more information on this best practice, see [here](./docs/LIST_OF_TESTS.md#default-namespaces). -You can learn more about kubernetes namespaces [here](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) +This setting is OPTIONAL. If not specified, the CNF will be installed into the `cnf-default` namespace. + +For more details about Kubernetes namespaces, visit [here](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) Example Setting: -`helm_install_namespace: cnfspace` +`helm_install_namespace: your_custom_namespace` #### manifest_directory diff --git a/example-cnfs/coredns/cnf-testsuite.yml b/example-cnfs/coredns/cnf-testsuite.yml index 7c1f70182..a302ba806 100644 --- a/example-cnfs/coredns/cnf-testsuite.yml +++ b/example-cnfs/coredns/cnf-testsuite.yml @@ -6,7 +6,6 @@ helm_repository: # CONFIGURATION OF HELM REPO - ONLY NEEDED WHEN USING helm_char #helm_directory: coredns # PATH_TO_CNFS_HELM_CHART ; or #manifest_directory: coredns # PATH_TO_DIRECTORY_OF_CNFS_MANIFEST_FILES ; or release_name: coredns # DESIRED_HELM_RELEASE_NAME -helm_install_namespace: cnfspace container_names: - name: coredns rolling_update_test_tag: "1.8.0" diff --git a/example-cnfs/ip-forwarder/cnf-testsuite.yml b/example-cnfs/ip-forwarder/cnf-testsuite.yml index c57f6b760..3ca7a6b3b 100644 --- a/example-cnfs/ip-forwarder/cnf-testsuite.yml +++ b/example-cnfs/ip-forwarder/cnf-testsuite.yml @@ -4,4 +4,3 @@ release_name: vpp service_name: "" rolling_update_test_tag: latest allowlist_helm_chart_container_names: [nginx, calico-node, kube-proxy, nginx-proxy, node-cache, kube-multus] -helm_install_namespace: cnfspace diff --git a/example-cnfs/linkerd2/cnf-testsuite.yml b/example-cnfs/linkerd2/cnf-testsuite.yml index 059012ad5..985498a62 100644 --- a/example-cnfs/linkerd2/cnf-testsuite.yml +++ b/example-cnfs/linkerd2/cnf-testsuite.yml @@ -5,4 +5,3 @@ helm_repository: name: linkerd repo_url: https://helm.linkerd.io/stable helm_chart: linkerd/linkerd-control-plane -helm_install_namespace: linkerd diff --git a/example-cnfs/nsm/cnf-testsuite.yml b/example-cnfs/nsm/cnf-testsuite.yml index 82b260a93..12ceacb22 100644 --- a/example-cnfs/nsm/cnf-testsuite.yml +++ b/example-cnfs/nsm/cnf-testsuite.yml @@ -5,4 +5,3 @@ service_name: nsm-admission-webhook-svc helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable -helm_install_namespace: cnfspace diff --git a/example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml b/example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml index f82415242..0f8fb0ba0 100644 --- a/example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml +++ b/example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml @@ -3,4 +3,3 @@ helm_directory: nat-cnf release_name: cnf-nat service_name: allowlist_helm_chart_container_names: [node-cache, nginx, coredns, calico-node, kube-proxy, nginx-proxy, kube-multus] -helm_install_namespace: cnfspace diff --git a/example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml b/example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml index 5a37d0fc7..6701914e2 100644 --- a/example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml +++ b/example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml @@ -2,4 +2,3 @@ helm_directory: csp release_name: ip-forwarder-csp allowlist_helm_chart_container_names: [nginx, calico-node, kube-proxy, nginx-proxy, node-cache] -helm_install_namespace: cnfspace diff --git a/sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml b/sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml index 7e0976315..5ce210bfd 100644 --- a/sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml +++ b/sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml @@ -1,6 +1,5 @@ --- helm_directory: chart -helm_install_namespace: cnfspace release_name: sidecar-container-demo service_name: helm_repository: diff --git a/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml b/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml index f619a2874..eefd12541 100644 --- a/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml +++ b/sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml @@ -6,4 +6,3 @@ helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable rolling_update_test_tag: 1.6.7 -helm_install_namespace: cnfspace diff --git a/sample-cnfs/k8s-sidecar-container-pattern/cnf-testsuite.yml b/sample-cnfs/k8s-sidecar-container-pattern/cnf-testsuite.yml index 5895f8422..0ec2c4611 100644 --- a/sample-cnfs/k8s-sidecar-container-pattern/cnf-testsuite.yml +++ b/sample-cnfs/k8s-sidecar-container-pattern/cnf-testsuite.yml @@ -1,6 +1,5 @@ --- helm_directory: chart -helm_install_namespace: cnfspace git_clone_url: install_script: release_name: sidecar-container-demo diff --git a/sample-cnfs/ndn-reasonable-image-size/cnf-testsuite.yml b/sample-cnfs/ndn-reasonable-image-size/cnf-testsuite.yml index 69f386908..dac617cc1 100644 --- a/sample-cnfs/ndn-reasonable-image-size/cnf-testsuite.yml +++ b/sample-cnfs/ndn-reasonable-image-size/cnf-testsuite.yml @@ -1,5 +1,4 @@ --- helm_chart: oci://docker.io/envoyproxy/gateway-helm --version v0.0.0-latest -helm_install_namespace: "envoy-gateway-system" release_name: envoy service_name: envoy diff --git a/sample-cnfs/sample-bad-zombie/cnf-testsuite.yml b/sample-cnfs/sample-bad-zombie/cnf-testsuite.yml index aaf516a02..8c7aecd3c 100644 --- a/sample-cnfs/sample-bad-zombie/cnf-testsuite.yml +++ b/sample-cnfs/sample-bad-zombie/cnf-testsuite.yml @@ -5,4 +5,3 @@ helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable helm_chart: stable/coredns -helm_install_namespace: cnfspace diff --git a/sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml b/sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml index aaf516a02..8c7aecd3c 100644 --- a/sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml +++ b/sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml @@ -5,4 +5,3 @@ helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable helm_chart: stable/coredns -helm_install_namespace: cnfspace diff --git a/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml b/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml index 4c94eb4a7..26f8a5bc8 100644 --- a/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml +++ b/sample-cnfs/sample-multiple-processes/cnf-testsuite.yml @@ -4,4 +4,3 @@ release_name: multi-proc helm_repository: name: repo_url: -helm_install_namespace: cnfspace diff --git a/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml b/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml index d841b2604..ab73fef5e 100644 --- a/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml +++ b/sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml @@ -4,4 +4,3 @@ release_name: coredns helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable -helm_install_namespace: cnfspace diff --git a/sample-cnfs/sample_coredns/cnf-testsuite.yml b/sample-cnfs/sample_coredns/cnf-testsuite.yml index d841b2604..ab73fef5e 100644 --- a/sample-cnfs/sample_coredns/cnf-testsuite.yml +++ b/sample-cnfs/sample_coredns/cnf-testsuite.yml @@ -4,4 +4,3 @@ release_name: coredns helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable -helm_install_namespace: cnfspace diff --git a/sample-cnfs/sample_coredns_bad_liveness/cnf-testsuite.yml b/sample-cnfs/sample_coredns_bad_liveness/cnf-testsuite.yml index 59c95c13d..a735c6fed 100644 --- a/sample-cnfs/sample_coredns_bad_liveness/cnf-testsuite.yml +++ b/sample-cnfs/sample_coredns_bad_liveness/cnf-testsuite.yml @@ -1,5 +1,4 @@ --- helm_directory: chart -helm_install_namespace: cnfspace release_name: bad-liveness service_name: bad-liveness-coredns diff --git a/sample-cnfs/sample_good_signal_handling_tini/cnf-testsuite.yml b/sample-cnfs/sample_good_signal_handling_tini/cnf-testsuite.yml index ae219dbbf..17367f5c4 100644 --- a/sample-cnfs/sample_good_signal_handling_tini/cnf-testsuite.yml +++ b/sample-cnfs/sample_good_signal_handling_tini/cnf-testsuite.yml @@ -5,5 +5,4 @@ helm_repository: name: jenkins repo_url: https://charts.jenkins.io helm_chart: jenkins/jenkins -helm_install_namespace: cnfspace helm_values: "--set controller.sidecars.configAutoReload.enabled=false" diff --git a/sample-cnfs/sample_hostport/cnf-testsuite.yml b/sample-cnfs/sample_hostport/cnf-testsuite.yml index d7d732c64..c30bc4352 100644 --- a/sample-cnfs/sample_hostport/cnf-testsuite.yml +++ b/sample-cnfs/sample_hostport/cnf-testsuite.yml @@ -1,6 +1,5 @@ --- helm_directory: chart -helm_install_namespace: cnfspace git_clone_url: install_script: chart release_name: unifi diff --git a/sample-cnfs/sample_nodeport/cnf-testsuite.yml b/sample-cnfs/sample_nodeport/cnf-testsuite.yml index 87283bc81..e710fc0f8 100644 --- a/sample-cnfs/sample_nodeport/cnf-testsuite.yml +++ b/sample-cnfs/sample_nodeport/cnf-testsuite.yml @@ -1,6 +1,5 @@ --- helm_directory: chart -helm_install_namespace: cnfspace git_clone_url: install_script: chart release_name: unifi diff --git a/sample-cnfs/sample_rolling/cnf-testsuite.yml b/sample-cnfs/sample_rolling/cnf-testsuite.yml index 9ab7fd13e..aaa522298 100644 --- a/sample-cnfs/sample_rolling/cnf-testsuite.yml +++ b/sample-cnfs/sample_rolling/cnf-testsuite.yml @@ -4,7 +4,6 @@ release_name: coredns helm_repository: name: stable repo_url: https://cncf.gitlab.io/stable -helm_install_namespace: cnfspace container_names: - name: coredns rolling_update_test_tag: "1.8.0" diff --git a/sample-cnfs/sample_secret_volume/cnf-testsuite.yml b/sample-cnfs/sample_secret_volume/cnf-testsuite.yml index 8e23485a0..102af59dc 100644 --- a/sample-cnfs/sample_secret_volume/cnf-testsuite.yml +++ b/sample-cnfs/sample_secret_volume/cnf-testsuite.yml @@ -1,6 +1,5 @@ --- helm_directory: postgresql -helm_install_namespace: cnfspace git_clone_url: install_script: chart release_name: postgresql diff --git a/sample-cnfs/sample_unmounted_secret_volume/cnf-testsuite.yml b/sample-cnfs/sample_unmounted_secret_volume/cnf-testsuite.yml index 8e23485a0..102af59dc 100644 --- a/sample-cnfs/sample_unmounted_secret_volume/cnf-testsuite.yml +++ b/sample-cnfs/sample_unmounted_secret_volume/cnf-testsuite.yml @@ -1,6 +1,5 @@ --- helm_directory: postgresql -helm_install_namespace: cnfspace git_clone_url: install_script: chart release_name: postgresql diff --git a/spec/workload/state_spec.cr b/spec/workload/state_spec.cr index 274664d83..d5171a6a8 100644 --- a/spec/workload/state_spec.cr +++ b/spec/workload/state_spec.cr @@ -42,8 +42,8 @@ describe "State" do begin Log.info { "Installing Mysql " } # todo make helm directories work with parameters - ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample-mysql/cnf-testsuite.yml") - KubectlClient::Get.resource_wait_for_install("Pod", "mysql-0") + result = ShellCmd.run_testsuite("cnf_setup cnf-config=./sample-cnfs/sample-mysql/cnf-testsuite.yml") + result[:status].success?.should be_true result = ShellCmd.run_testsuite("database_persistence", cmd_prefix: "LOG_LEVEL=info") (/(PASSED).*(CNF uses database with cloud-native persistence)/ =~ result[:output]).should_not be_nil ensure diff --git a/src/tasks/constants.cr b/src/tasks/constants.cr index 36bab2b6d..bb90f2f4b 100644 --- a/src/tasks/constants.cr +++ b/src/tasks/constants.cr @@ -23,6 +23,7 @@ EMPTY_JSON_ARRAY = JSON.parse(%([])) SPECIALIZED_INIT_SYSTEMS = ["tini", "dumb-init", "s6-svscan"] TESTSUITE_NAMESPACE = "cnf-testsuite" +DEFAULT_CNF_NAMESPACE = "cnf-default" #Embedded global text variables EmbeddedFileManager.node_failure_values diff --git a/src/tasks/utils/cnf_manager.cr b/src/tasks/utils/cnf_manager.cr index a25e54ef8..c2d5dd0d7 100644 --- a/src/tasks/utils/cnf_manager.cr +++ b/src/tasks/utils/cnf_manager.cr @@ -80,11 +80,10 @@ module CNFManager release_name = config.cnf_config[:release_name] helm_chart_path = config.cnf_config[:helm_chart_path] manifest_file_path = config.cnf_config[:manifest_file_path] - helm_install_namespace = config.cnf_config[:helm_install_namespace] helm_values = config.cnf_config[:helm_values] test_passed = true - default_namespace = "default" + deployment_namespace = CNFManager.get_deployment_namespace(config) install_method = CNFInstall.cnf_installation_method(config) Log.debug { "install_method: #{install_method}" } template_ymls = [] of YAML::Any @@ -94,12 +93,10 @@ module CNFManager Helm.generate_manifest_from_templates(release_name, helm_chart_path, manifest_file_path, - helm_install_namespace, + deployment_namespace, helm_values) template_ymls = CNFInstall::Manifest.parse_manifest_as_ymls(manifest_file_path) - if !helm_install_namespace.empty? - default_namespace = config.cnf_config[:helm_install_namespace] - end + when CNFInstall::InstallMethod::ManifestDirectory # if release_name.empty? # no helm chart template_ymls = CNFInstall::Manifest.manifest_ymls_from_file_list(CNFInstall::Manifest.manifest_file_list( destination_cnf_dir + "/" + manifest_directory)) @@ -135,17 +132,30 @@ module CNFManager # ``` # CNFManager.cnf_workload_resources(args, config) {|cnf_config, resource| #your code} # ``` - def self.cnf_workload_resources(args, config, &block) - helm_install_namespace = config.cnf_config[:helm_install_namespace] - # - default_namespace = "default" - if !helm_install_namespace.empty? - default_namespace = config.cnf_config[:helm_install_namespace] + + def self.get_deployment_namespace(config) + install_method = CNFInstall.cnf_installation_method(config) + case install_method[0] + when CNFInstall::InstallMethod::HelmChart, Helm::InstallMethod::HelmDirectory + if !config.cnf_config[:helm_install_namespace].empty? + Log.info { "deployment namespace was set to: #{config.cnf_config[:helm_install_namespace]}" } + config.cnf_config[:helm_install_namespace] + else + Log.info { "deployment namespace was set to: #{DEFAULT_CNF_NAMESPACE}" } + DEFAULT_CNF_NAMESPACE + end + else + Log.info { "deployment namespace was set to: default" } + "default" end + end + + def self.cnf_workload_resources(args, config, &block) + deployment_namespace = CNFManager.get_deployment_namespace(config) template_ymls = cnf_resource_ymls(args, config) # call cnf cnf_resources to get unfiltered yml - resource_ymls = Helm.all_workload_resources(template_ymls, default_namespace) + resource_ymls = Helm.all_workload_resources(template_ymls, deployment_namespace) resource_resp = resource_ymls.map do | resource | resp = yield resource Log.debug { "cnf_workload_resource yield resp: #{resp}" } @@ -178,11 +188,9 @@ module CNFManager resource end - default_namespace = "default" - if !config.cnf_config[:helm_install_namespace].empty? - default_namespace = config.cnf_config[:helm_install_namespace] - end - resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: default_namespace) + deployment_namespace = CNFManager.get_deployment_namespace(config) + + resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: deployment_namespace) Log.info { "resource names: #{resource_names}" } if resource_names && resource_names.size > 0 initialized = true @@ -629,13 +637,10 @@ module CNFManager helm_repository = config.cnf_config[:helm_repository] helm_repo_name = "#{helm_repository && helm_repository["name"]}" helm_repo_url = "#{helm_repository && helm_repository["repo_url"]}" + deployment_namespace = CNFManager.get_deployment_namespace(config) + helm_namespace_option = "-n #{deployment_namespace}" + ensure_namespace_exists!(deployment_namespace) - helm_install_namespace = config.cnf_config[:helm_install_namespace] - helm_namespace_option = "" - if !helm_install_namespace.empty? - helm_namespace_option = "-n #{helm_install_namespace}" - ensure_namespace_exists!(helm_install_namespace) - end Log.info { "helm_repo_name: #{helm_repo_name}" } Log.info { "helm_repo_url: #{helm_repo_url}" } @@ -665,8 +670,6 @@ module CNFManager helm_install = {status: "", output: "", error: ""} helm_error = false - default_namespace = "default" - # todo determine what the ric is/if there is a ric installed (labeling) #option 1 # todo determine what pad/node the ric is in (pod/node by label) @@ -701,18 +704,11 @@ module CNFManager Log.for("verbose").info { "deploying by manifest file" } if verbose KubectlClient::Apply.file("#{destination_cnf_dir}/#{manifest_directory}") when CNFInstall::InstallMethod::HelmChart - if !helm_install_namespace.empty? - # default_namespace = config.cnf_config[:helm_install_namespace] - helm_install_namespace = config.cnf_config[:helm_install_namespace] - else - helm_install_namespace = default_namespace - end helm_chart = config.cnf_config[:helm_chart] if !helm_repo_name.empty? || !helm_repo_url.empty? Helm.helm_repo_add(helm_repo_name, helm_repo_url) end Log.for("verbose").info { "deploying with chart repository" } if verbose - begin helm_install = Helm.install(release_name, helm_chart, helm_namespace_option, helm_values) # helm_install = Helm.install("#{release_name} #{helm_chart} #{helm_namespace_option}") @@ -727,16 +723,9 @@ module CNFManager end export_published_chart(config, cli_args) when CNFInstall::InstallMethod::HelmDirectory - if !helm_install_namespace.empty? - # default_namespace = config.cnf_config[:helm_install_namespace] - helm_install_namespace = config.cnf_config[:helm_install_namespace] - else - helm_install_namespace = default_namespace - end Log.for("verbose").info { "deploying with helm directory" } if verbose #TODO Add helm options into cnf-testsuite yml #e.g. helm install nsm --set insecure=true ./nsm/helm_chart - begin # helm_install = Helm.install("#{release_name} #{destination_cnf_dir}/#{helm_directory} #{helm_namespace_option}") helm_install = Helm.install(release_name, "#{install_method[1]}", helm_namespace_option, helm_values) @@ -757,10 +746,8 @@ module CNFManager resource end - resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace) + resource_names = Helm.workload_resource_kind_names(resource_ymls, deployment_namespace) #TODO move to kubectlclient and make resource_install_and_wait_for_all function - - # # get liveness probe initialDelaySeconds and FailureThreshold # if ((periodSeconds * failureThreshhold) + initialDelaySeconds) / defaultFailureThreshold) > startuptimelimit then fail; else pass # get largest startuptime of all resoures, then save into config map @@ -900,15 +887,9 @@ module CNFManager helm_chart_path = config.cnf_config[:helm_chart_path] helm_chart = config.cnf_config[:helm_chart] destination_cnf_dir = config.cnf_config[:destination_cnf_dir] - - helm_install_namespace = config.cnf_config[:helm_install_namespace] - helm_namespace_option = "" - if !helm_install_namespace.empty? - helm_namespace_option = "-n #{helm_install_namespace}" - ensure_namespace_exists!(helm_install_namespace, kubeconfig: kubeconfig) - else - Log.for("cnf_to_new_cluster").info { "helm_install_namespace option is empty" } - end + deployment_namespace = CNFManager.get_deployment_namespace(config) + helm_namespace_option = "-n #{deployment_namespace}" + ensure_namespace_exists!(deployment_namespace, kubeconfig: kubeconfig) Log.for("cnf_to_new_cluster").info { "Install method: #{install_method[0]}" } case install_method[0] @@ -934,11 +915,7 @@ module CNFManager resource end - default_namespace = "default" - if !helm_install_namespace.empty? - default_namespace = config.cnf_config[:helm_install_namespace] - end - resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: default_namespace) + resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: deployment_namespace) wait_list = resource_names.map do | resource | case resource[:kind].downcase @@ -984,17 +961,13 @@ module CNFManager elsif dir_exists Log.for("sample_cleanup").info { "Destination dir #{destination_cnf_dir} exists" } end - - default_namespace = "default" + install_method = CNFInstall.cnf_installation_method(parsed_config) Log.for("sample_cleanup:install_method").info { install_method } case install_method[0] when CNFInstall::InstallMethod::HelmChart, CNFInstall::InstallMethod::HelmDirectory - helm_install_namespace = parsed_config.cnf_config[:helm_install_namespace] - if helm_install_namespace != nil && helm_install_namespace != "" - default_namespace = helm_install_namespace - helm_namespace_option = "-n #{helm_install_namespace}" - end + deployment_namespace = CNFManager.get_deployment_namespace(parsed_config) + helm_namespace_option = "-n #{deployment_namespace}" result = Helm.uninstall(release_name + " #{helm_namespace_option}") Log.for("sample_cleanup:helm_uninstall").info { result[:output].to_s } if verbose if result[:status].success? @@ -1021,7 +994,8 @@ module CNFManager def self.workload_resource_keys(args, config) resource_keys = CNFManager.cnf_workload_resources(args, config) do |resource| - namespace = resource.dig?("metadata", "namespace") || config.cnf_config[:helm_install_namespace] + deployment_namespace = CNFManager.get_deployment_namespace(config) + namespace = resource.dig?("metadata", "namespace") || deployment_namespace kind = resource.dig?("kind") name = resource.dig?("metadata", "name") "#{namespace},#{kind}/#{name}".downcase diff --git a/src/tasks/workload/compatibility.cr b/src/tasks/workload/compatibility.cr index 85d5e0b34..d65e4c752 100644 --- a/src/tasks/workload/compatibility.cr +++ b/src/tasks/workload/compatibility.cr @@ -38,7 +38,7 @@ rolling_version_change_test_names.each do |tn| # note: all images are not on docker hub nor are they always on a docker hub compatible api task_response = update_applied && CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - namespace = resource["namespace"] || config.cnf_config[:helm_install_namespace] + namespace = resource["namespace"] || CNFManager.get_deployment_namespace(config) test_passed = true valid_cnf_testsuite_yml = true Log.for(t.name).debug { "container: #{container}" } @@ -110,7 +110,7 @@ task "rollback" do |t, args| task_response = update_applied && CNFManager.workload_resource_test(args, config) do |resource, container, initialized| resource_kind = resource["kind"] resource_name = resource["name"] - namespace = resource["namespace"] || config.cnf_config[:helm_install_namespace] + namespace = resource["namespace"] || CNFManager.get_deployment_namespace(config) container_name = container.as_h["name"].as_s full_image_name_tag = container.as_h["image"].as_s.rpartition(":") image_name = full_image_name_tag[0] diff --git a/src/tasks/workload/configuration.cr b/src/tasks/workload/configuration.cr index 2dc5e2de9..ca3e4073a 100644 --- a/src/tasks/workload/configuration.cr +++ b/src/tasks/workload/configuration.cr @@ -356,7 +356,7 @@ task "secrets_used" do |t, args| # but do not have a corresponding k8s secret defined, this # is an installation problem, and does not stop the test from passing - namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) secrets = KubectlClient::Get.secrets(namespace: namespace) secrets["items"].as_a.each do |s| @@ -565,7 +565,7 @@ task "immutable_configmap" do |t, args| # If the install type is manifest, the namesapce would be in the manifest. # Else rely on config for helm-based install - namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) configmaps = KubectlClient::Get.configmaps(namespace: namespace) if configmaps.dig?("items") configmaps = configmaps.dig("items").as_a diff --git a/src/tasks/workload/microservice.cr b/src/tasks/workload/microservice.cr index f52725446..56d08a6a7 100644 --- a/src/tasks/workload/microservice.cr +++ b/src/tasks/workload/microservice.cr @@ -679,11 +679,8 @@ task "service_discovery" do |t, args| CNFManager::Task.task_runner(args, task: t) do |args,config| # Get all resources for the CNF resource_ymls = CNFManager.cnf_workload_resources(args, config) { |resource| resource } - default_namespace = "default" - if !config.cnf_config[:helm_install_namespace].empty? - default_namespace = config.cnf_config[:helm_install_namespace] - end - resources = Helm.workload_resource_kind_names(resource_ymls, default_namespace) + deployment_namespace = CNFManager.get_deployment_namespace(config) + resources = Helm.workload_resource_kind_names(resource_ymls, default_namespace: deployment_namespace) # Collect service names from the CNF resource list cnf_service_names = [] of String diff --git a/src/tasks/workload/reliability.cr b/src/tasks/workload/reliability.cr index 52ff6ac08..8d1bb7572 100644 --- a/src/tasks/workload/reliability.cr +++ b/src/tasks/workload/reliability.cr @@ -90,7 +90,7 @@ task "pod_network_latency", ["install_litmus"] do |t, args| destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| Log.info { "Current Resource Name: #{resource["name"]} Type: #{resource["kind"]}" } - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 && resource["kind"] == "Deployment" @@ -188,7 +188,7 @@ task "pod_network_corruption", ["install_litmus"] do |t, args| destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| Log.info {"Current Resource Name: #{resource["name"]} Type: #{resource["kind"]}"} - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 && resource["kind"] == "Deployment" test_passed = true @@ -241,7 +241,7 @@ task "pod_network_duplication", ["install_litmus"] do |t, args| #TODO tests should fail if cnf not installed destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) Log.info{ "Current Resource Name: #{resource["name"]} Type: #{resource["kind"]} Namespace: #{resource["namespace"]}"} spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 && resource["kind"] == "Deployment" @@ -296,7 +296,7 @@ task "disk_fill", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -354,7 +354,7 @@ task "pod_delete", ["install_litmus"] do |t, args| destination_cnf_dir = config.cnf_config[:destination_cnf_dir] #todo clear all annotations task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -454,7 +454,7 @@ task "pod_memory_hog", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -512,7 +512,7 @@ task "pod_io_stress", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -577,7 +577,7 @@ task "pod_dns_error", ["install_litmus"] do |t, args| Log.info { "pod_dns_error runtimes: #{runtimes}" } if runtimes.find{|r| r.downcase.includes?("docker")} task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true diff --git a/src/tasks/workload/state.cr b/src/tasks/workload/state.cr index 86ab281cb..592cfb6ce 100644 --- a/src/tasks/workload/state.cr +++ b/src/tasks/workload/state.cr @@ -24,7 +24,7 @@ module Volume def self.elastic_by_volumes?(volumes : Array(JSON::Any), namespace : String? = nil) Log.info {"Volume.elastic_by_volumes"} storage_class_names = storage_class_by_volumes(volumes, namespace) - elastic = StorageClass.elastic_by_storage_class?(storage_class_names) + elastic = StorageClass.elastic_by_storage_class?(storage_class_names, namespace) Log.info {"Volume.elastic_by_volumes elastic: #{elastic}"} elastic end @@ -180,7 +180,7 @@ module VolumeClaimTemplate def self.storage_class_by_vct_resource(resource, namespace) Log.info {"storage_class_by_vct_resource"} pvc_name = VolumeClaimTemplate.pvc_name_by_vct_resource(resource) - resource = KubectlClient::Get.resource("pvc", pvc_name.to_s) + resource = KubectlClient::Get.resource("pvc", pvc_name.to_s, namespace) Log.info {"pvc resource #{resource}"} storage_class = nil @@ -205,10 +205,10 @@ module WorkloadResource if VolumeClaimTemplate.vct_resource?(resource) storage_class = VolumeClaimTemplate.storage_class_by_vct_resource(resource, namespace) if storage_class - elastic = StorageClass.elastic_by_storage_class?([storage_class]) + elastic = StorageClass.elastic_by_storage_class?([storage_class], namespace) end else - elastic = Volume.elastic_by_volumes?(volumes) + elastic = Volume.elastic_by_volumes?(volumes, namespace) end Log.info {"workloadresource elastic?: #{elastic}"} elastic @@ -221,7 +221,7 @@ task "node_drain", ["install_litmus"] do |t, args| skipped = false destination_cnf_dir = config.cnf_config[:destination_cnf_dir] task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || config.cnf_config[:helm_install_namespace] + app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) Log.info { "Current Resource Name: #{resource["kind"]}/#{resource["name"]} Namespace: #{resource["namespace"]}" } spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) @@ -369,7 +369,7 @@ task "elastic_volumes" do |t, args| # todo use workload resource # elastic = WorkloadResource.elastic?(volumes) - namespace = CNFManager.namespace_from_parameters(CNFInstall.install_parameters(config)) + namespace = CNFManager.namespace_from_parameters(CNFInstall.install_parameters(config)) || CNFManager.get_deployment_namespace(config) full_resource = KubectlClient::Get.resource(resource["kind"], resource["name"], namespace) elastic_result = WorkloadResource.elastic?(full_resource, volumes.as_a, namespace) @@ -408,11 +408,8 @@ task "database_persistence" do |t, args| match = Mysql.match Log.info {"database_persistence mysql: #{match}"} if match && match[:found] - default_namespace = "default" - if !config.cnf_config[:helm_install_namespace].empty? - default_namespace = config.cnf_config[:helm_install_namespace] - end - statefulset_exists = Helm.kind_exists?(args, config, "statefulset", default_namespace) + deployment_namespace = CNFManager.get_deployment_namespace(config) + statefulset_exists = Helm.kind_exists?(args, config, "statefulset", deployment_namespace) unless statefulset_exists all_mysql_elastic_statefulset = false @@ -427,7 +424,7 @@ task "database_persistence" do |t, args| end end - namespace = resource["namespace"] || default_namespace + namespace = resource["namespace"] || deployment_namespace Log.info {"database_persistence namespace: #{namespace}"} Log.info {"database_persistence resource: #{resource}"} Log.info {"database_persistence volumes: #{volumes}"}