Skip to content

Commit

Permalink
[MAINTENANCE] Create new namespace - cnf-default (cnti-testcatalog#2056)
Browse files Browse the repository at this point in the history
- remove helm_install_namespace from all samples
- cnfs are deployed into cnf-default namespace
- add condition into cleanup to terminate pods
  from cnf-default namespace
- update ## helm_install_namespaces section in
  CNF_TESTSUITE_YML_USAGE.md file

Signed-off-by: barmull <[email protected]>
  • Loading branch information
barmull authored Aug 5, 2024
1 parent c84cbef commit 67affef
Show file tree
Hide file tree
Showing 31 changed files with 71 additions and 122 deletions.
10 changes: 6 additions & 4 deletions CNF_TESTSUITE_YML_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion example-cnfs/coredns/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion example-cnfs/ip-forwarder/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion example-cnfs/linkerd2/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion example-cnfs/nsm/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
helm_directory: chart
helm_install_namespace: cnfspace
release_name: sidecar-container-demo
service_name:
helm_repository:
Expand Down
1 change: 0 additions & 1 deletion sample-cnfs/k8s-multiple-processes/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
helm_directory: chart
helm_install_namespace: cnfspace
git_clone_url:
install_script:
release_name: sidecar-container-demo
Expand Down
1 change: 0 additions & 1 deletion sample-cnfs/ndn-reasonable-image-size/cnf-testsuite.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion sample-cnfs/sample-bad-zombie/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ helm_repository:
name: stable
repo_url: https://cncf.gitlab.io/stable
helm_chart: stable/coredns
helm_install_namespace: cnfspace
1 change: 0 additions & 1 deletion sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ helm_repository:
name: stable
repo_url: https://cncf.gitlab.io/stable
helm_chart: stable/coredns
helm_install_namespace: cnfspace
1 change: 0 additions & 1 deletion sample-cnfs/sample-multiple-processes/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ release_name: multi-proc
helm_repository:
name:
repo_url:
helm_install_namespace: cnfspace
1 change: 0 additions & 1 deletion sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ release_name: coredns
helm_repository:
name: stable
repo_url: https://cncf.gitlab.io/stable
helm_install_namespace: cnfspace
1 change: 0 additions & 1 deletion sample-cnfs/sample_coredns/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ release_name: coredns
helm_repository:
name: stable
repo_url: https://cncf.gitlab.io/stable
helm_install_namespace: cnfspace
1 change: 0 additions & 1 deletion sample-cnfs/sample_coredns_bad_liveness/cnf-testsuite.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
helm_directory: chart
helm_install_namespace: cnfspace
release_name: bad-liveness
service_name: bad-liveness-coredns
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion sample-cnfs/sample_hostport/cnf-testsuite.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
helm_directory: chart
helm_install_namespace: cnfspace
git_clone_url:
install_script: chart
release_name: unifi
Expand Down
1 change: 0 additions & 1 deletion sample-cnfs/sample_nodeport/cnf-testsuite.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
helm_directory: chart
helm_install_namespace: cnfspace
git_clone_url:
install_script: chart
release_name: unifi
Expand Down
1 change: 0 additions & 1 deletion sample-cnfs/sample_rolling/cnf-testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion sample-cnfs/sample_secret_volume/cnf-testsuite.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
helm_directory: postgresql
helm_install_namespace: cnfspace
git_clone_url:
install_script: chart
release_name: postgresql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
helm_directory: postgresql
helm_install_namespace: cnfspace
git_clone_url:
install_script: chart
release_name: postgresql
Expand Down
4 changes: 2 additions & 2 deletions spec/workload/state_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/tasks/constants.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 39 additions & 65 deletions src/tasks/utils/cnf_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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}" }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}" }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}")
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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
Expand Down
Loading

0 comments on commit 67affef

Please sign in to comment.