Skip to content

Commit

Permalink
Feature: CNF Installation (5.1) - test preparation
Browse files Browse the repository at this point in the history
- open_metrics and prometheus_traffic - change name of config maps
- ip_addresses - removed
- hardcoded_ip_addresses_in_k8s_runtime_configuration -
  change to use common_manifest.yml file

Refs: #2153
Signed-off-by: barmull [email protected]
  • Loading branch information
barmull committed Oct 22, 2024
1 parent 24744bc commit 88d49a0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ jobs:
./cnf-testsuite setup
wget -O cnf-testsuite.yml https://raw.githubusercontent.com/cnti-testcatalog/testsuite/${GITHUB_SHA}/example-cnfs/coredns/cnf-testsuite.yml
./cnf-testsuite cnf_setup cnf-config=./cnf-testsuite.yml
LOG_LEVEL=info ./cnf-testsuite all ~resilience ~compatibility ~pod_network_latency ~platform ~increase_capacity ~decrease_capacity ~ip_addresses ~liveness ~readiness ~rolling_update ~rolling_downgrade ~rolling_version_change ~nodeport_not_used ~hostport_not_used ~hardcoded_ip_addresses_in_k8s_runtime_configuration ~install_script_helm ~helm_chart_valid ~helm_chart_published ~rollback ~secrets_used ~immutable_configmap verbose
LOG_LEVEL=info ./cnf-testsuite all ~resilience ~compatibility ~pod_network_latency ~platform ~increase_capacity ~decrease_capacity ~liveness ~readiness ~rolling_update ~rolling_downgrade ~rolling_version_change ~nodeport_not_used ~hostport_not_used ~hardcoded_ip_addresses_in_k8s_runtime_configuration ~install_script_helm ~helm_chart_valid ~helm_chart_published ~rollback ~secrets_used ~immutable_configmap verbose
- name: Delete Cluster
if: ${{ always() }}
run: |
Expand Down Expand Up @@ -552,7 +552,7 @@ jobs:
./cnf-testsuite setup
wget -O cnf-testsuite.yml https://raw.githubusercontent.com/cnti-testcatalog/testsuite/${GITHUB_SHA}/example-cnfs/coredns/cnf-testsuite.yml
./cnf-testsuite cnf_setup cnf-config=./cnf-testsuite.yml
LOG_LEVEL=info ./cnf-testsuite all ~resilience ~platform ~ip_addresses ~liveness ~readiness ~rolling_update ~rolling_downgrade ~rolling_version_change ~nodeport_not_used ~hostport_not_used ~hardcoded_ip_addresses_in_k8s_runtime_configuration ~rollback ~secrets_used ~immutable_configmap ~reasonable_startup_time ~reasonable_image_size verbose
LOG_LEVEL=info ./cnf-testsuite all ~resilience ~platform ~liveness ~readiness ~rolling_update ~rolling_downgrade ~rolling_version_change ~nodeport_not_used ~hostport_not_used ~hardcoded_ip_addresses_in_k8s_runtime_configuration ~rollback ~secrets_used ~immutable_configmap ~reasonable_startup_time ~reasonable_image_size verbose
- name: Delete Cluster
if: ${{ always() }}
run: |
Expand Down
11 changes: 0 additions & 11 deletions spec/workload/configuration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,6 @@ describe CnfTestSuite do
end
end

it "'ip_addresses' should pass when no uncommented ip addresses are found in helm chart source", tags: ["ip_addresses"] do
begin
ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample-coredns-cnf-source/cnf-testsuite.yml verbose skip_wait_for_install")
result = ShellCmd.run_testsuite("ip_addresses verbose")
result[:status].success?.should be_true
(/(PASSED).*(No IP addresses found)/ =~ result[:output]).should_not be_nil
ensure
result = ShellCmd.run_testsuite("sample_coredns_source_cleanup verbose")
end
end

it "'hardcoded_ip_addresses_in_k8s_runtime_configuration' should fail when a hardcoded ip is found in the K8s configuration", tags: ["ip_addresses"] do
begin
ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_coredns_hardcoded_ips deploy_with_chart=false")
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/static.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ require "colorize"
require "totem"

desc "Static tests"
task "static", ["liveness", "ip_addresses"] do |_, args|
task "static", ["liveness"] do |_, args|
end

58 changes: 2 additions & 56 deletions src/tasks/workload/configuration.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ rolling_version_change_test_names = ["rolling_update", "rolling_downgrade", "rol
desc "Configuration should be managed in a declarative manner, using ConfigMaps, Operators, or other declarative interfaces."

task "configuration", [
"ip_addresses",
"nodeport_not_used",
"hostport_not_used",
"hardcoded_ip_addresses_in_k8s_runtime_configuration",
Expand Down Expand Up @@ -101,50 +100,6 @@ task "latest_tag" do |t, args|
end
end

desc "Does a search for IP addresses or subnets come back as negative?"
task "ip_addresses" do |t, args|
CNFManager::Task.task_runner(args, task: t) do |args, config|
cdir = FileUtils.pwd()
response = String::Builder.new
helm_chart_path = CNFInstall::Config.get_helm_chart_path(config)
Log.info { "Path: #{helm_chart_path}" }
if File.directory?(helm_chart_path)
# Switch to the helm chart directory
Dir.cd(helm_chart_path)
# Look for all ip addresses that are not comments
Log.for(t.name).info { "current directory: #{ FileUtils.pwd()}" }
# should catch comments (# // or /*) and ignore 0.0.0.0
# note: grep wants * escaped twice
Process.run("grep -r -P '^(?!.+0\.0\.0\.0)(?![[:space:]]*0\.0\.0\.0)(?!#)(?![[:space:]]*#)(?!\/\/)(?![[:space:]]*\/\/)(?!\/\\*)(?![[:space:]]*\/\\*)(.+([0-9]{1,3}[\.]){3}[0-9]{1,3})' --exclude=*.txt", shell: true) do |proc|
while line = proc.output.gets
response << line
VERBOSE_LOGGING.info "#{line}" if check_verbose(args)
end
end
Dir.cd(cdir)
parsed_resp = response.to_s
if parsed_resp.size > 0
response_lines = parsed_resp.split("\n")
stdout_failure("Lines with hard-coded IP addresses:")
response_lines.each do |line|
line_parts = line.split(":")
file_name = line_parts.shift()
matching_line = line_parts.join(":").strip()
stdout_failure(" * In file #{file_name}: #{matching_line}")
end
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "IP addresses found")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "No IP addresses found")
end
else
# TODO If no helm chart directory, exit with 0 points
# ADD SKIPPED tag for points.yml to allow for 0 points
Dir.cd(cdir)
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "No IP addresses found")
end
end
end

desc "Do all cnf images have versioned tags?"
task "versioned_tag", ["install_opa"] do |t, args|
CNFManager::Task.task_runner(args, task: t) do |args,config|
Expand Down Expand Up @@ -261,22 +216,13 @@ task "hardcoded_ip_addresses_in_k8s_runtime_configuration" do |t, args|
helm_chart = config.deployments.get_deployment_param(:helm_chart)
helm_directory = config.deployments.get_deployment_param(:helm_directory)
destination_cnf_dir = config.dynamic.destination_cnf_dir
helm_chart_yml_path = "#{destination_cnf_dir}/helm_chart.yml"
current_dir = FileUtils.pwd
helm = Helm::BinarySingleton.helm
VERBOSE_LOGGING.info "Helm Path: #{helm}" if check_verbose(args)

KubectlClient::Create.command("namespace hardcoded-ip-test")
unless helm_chart.empty?
helm_install = Helm.install("--namespace hardcoded-ip-test hardcoded-ip-test #{helm_chart} --dry-run --debug > #{helm_chart_yml_path}")
else
helm_install = Helm.install("--namespace hardcoded-ip-test hardcoded-ip-test #{destination_cnf_dir}/#{helm_directory} --dry-run --debug > #{helm_chart_yml_path}")
VERBOSE_LOGGING.info "helm_directory: #{helm_directory}" if check_verbose(args)
end

found_violations = [] of NamedTuple(line_number: Int32, line: String)
line_number = 1
File.open("#{helm_chart_yml_path}") do |file|
File.open(COMMON_MANIFEST_FILE_PATH) do |file|
file.each_line do |line|
if line.matches?(/NOTES:/)
break
Expand All @@ -294,7 +240,7 @@ task "hardcoded_ip_addresses_in_k8s_runtime_configuration" do |t, args|
if found_violations.empty?
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "No hard-coded IP addresses found in the runtime K8s configuration")
else
stdout_failure("Hard-coded IP addresses found in #{helm_chart_yml_path}")
stdout_failure("Hard-coded IP addresses found in #{COMMON_MANIFEST_FILE_PATH}")
found_violations.each do |violation|
stdout_failure(" * Line #{violation[:line_number]}: #{violation[:line]}")
end
Expand Down
8 changes: 3 additions & 5 deletions src/tasks/workload/observability.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ end
desc "Does the CNF emit prometheus traffic"
task "prometheus_traffic" do |t, args|
task_response = CNFManager::Task.task_runner(args, task: t) do |args, config|
release_name = config.deployments.get_deployment_param(:name)
destination_cnf_dir = config.dynamic.destination_cnf_dir

do_this_on_each_retry = ->(ex : Exception, attempt : Int32, elapsed_time : Time::Span, next_interval : Time::Span) do
Expand Down Expand Up @@ -112,15 +111,15 @@ task "prometheus_traffic" do |t, args|
end
if msg[:status].success?
metrics_config_map = Prometheus::OpenMetricConfigMapTemplate.new(
"cnf-testsuite-#{release_name}-open-metrics",
"cnf-testsuite-open-metrics",
true,
"",
immutable_configmap
).to_s
else
Log.info { "Openmetrics failure reason: #{msg[:output]}"}
metrics_config_map = Prometheus::OpenMetricConfigMapTemplate.new(
"cnf-testsuite-#{release_name}-open-metrics",
"cnf-testsuite-open-metrics",
false,
msg[:output],
immutable_configmap
Expand Down Expand Up @@ -159,8 +158,7 @@ end
desc "Does the CNF emit prometheus open metric compatible traffic"
task "open_metrics", ["prometheus_traffic"] do |t, args|
task_response = CNFManager::Task.task_runner(args, task: t) do |args, config|
release_name = config.deployments.get_deployment_param(:name)
configmap = KubectlClient::Get.configmap("cnf-testsuite-#{release_name}-open-metrics")
configmap = KubectlClient::Get.configmap("cnf-testsuite-open-metrics")
if configmap != EMPTY_JSON
open_metrics_validated = configmap["data"].as_h["open_metrics_validated"].as_s

Expand Down
2 changes: 1 addition & 1 deletion tools/curl_install_tester_docker_setup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ from base as ci_test
COPY cnf-testsuite .
RUN ./cnf-testsuite setup verbose
RUN wget https://raw.githubusercontent.com/cnti-testcatalog/testsuite/main/example-cnfs/coredns/cnf-testsuite.yml
RUN ./cnf-testsuite ip_addresses cnf-config=./cnf-testsuite.yml verbose
RUN ./cnf-testsuite helm_chart_valid cnf-config=./cnf-testsuite.yml verbose

0 comments on commit 88d49a0

Please sign in to comment.