Skip to content

Commit

Permalink
Merge pull request #570 from cncf/feature/#569-cnf-refactor
Browse files Browse the repository at this point in the history
cnf installation refactor #569
  • Loading branch information
denverwilliams authored Jan 15, 2021
2 parents ac2a398 + e867582 commit d9f4fc9
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 225 deletions.
80 changes: 61 additions & 19 deletions spec/utils/cnf_manager_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe "SampleUtils" do
end

it "'CNFManager.wait_for_install' should wait for a cnf to be installed", tags: "happy-path" do
`./cnf-conformance sample_coredns_setup`
LOGGING.debug `./cnf-conformance sample_coredns_setup`
$?.success?.should be_true

current_dir = FileUtils.pwd
Expand All @@ -38,11 +38,27 @@ describe "SampleUtils" do
current_replicas = `kubectl get deployments coredns-coredns -o=jsonpath='{.status.readyReplicas}'`
(current_replicas.to_i > 0).should be_true
end
it "'CNFManager.sample_setup_cli_args(args) and CNFManager.sample_setup(cli_args)' should set up a sample cnf", tags: "happy-path" do
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-conformance.yml", "verbose", "wait_count=180"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(cli_hash[:config_file]))
release_name = config.cnf_config[:release_name]

(Dir.exists? "cnfs/#{release_name}").should be_true
(File.exists?("cnfs/#{release_name}/cnf-conformance.yml")).should be_true
(File.exists?("cnfs/#{release_name}/exported_chart/Chart.yaml")).should be_true
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
(Dir.exists? "cnfs/#{release_name}").should be_false
end

it "'CNFManager.sample_setup' should set up a sample cnf", tags: "happy-path" do
args = Sam::Args.new
config_file = "sample-cnfs/sample-generic-cnf"
CNFManager.sample_setup(config_file: config_file, release_name: "", deployment_name: "coredns-coredns", helm_chart: "stable/coredns", helm_directory: "", git_clone_url: "https://github.com/coredns/coredns.git", wait_count: 0, verbose: true)
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# CNFManager.sample_setup(config_file: config_file, release_name: "", deployment_name: "coredns-coredns", helm_chart: "stable/coredns", helm_directory: "", git_clone_url: "https://github.com/coredns/coredns.git", wait_count: 0, verbose: true)
# check if directory exists
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = config.cnf_config[:release_name]
Expand All @@ -55,9 +71,12 @@ describe "SampleUtils" do
end

it "'CNFManager.sample_setup_args' should set up a sample cnf from a argument", tags: "happy-path" do
args = Sam::Args.new
config_file = "sample-cnfs/sample-generic-cnf"
CNFManager.sample_setup_args(sample_dir: config_file, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# CNFManager.sample_setup_args(sample_dir: config_file, args: args, verbose: true, wait_count: 0 )
# check if directory exists
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = config.cnf_config[:release_name]
Expand All @@ -69,9 +88,12 @@ describe "SampleUtils" do
end

it "'CNFManager.sample_setup_args' should set up a sample cnf from a config file", tags: "happy-path" do
args = Sam::Args.new
config_file = "sample-cnfs/sample-generic-cnf/cnf-conformance.yml"
CNFManager.sample_setup_args(sample_dir: config_file, args: args, verbose: true, wait_count: 0 )
config_file = "sample-cnfs/sample-generic-cnf"
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# CNFManager.sample_setup_args(sample_dir: config_file, args: args, verbose: true, wait_count: 0 )
# check if directory exists
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = config.cnf_config[:release_name]
Expand All @@ -83,8 +105,11 @@ describe "SampleUtils" do
end

it "'CNFManager.sample_cleanup' should clean up a sample cnf from a argument", tags: "happy-path" do
args = Sam::Args.new
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 )
cleanup = CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
(cleanup).should be_true
(Dir.exists? "cnfs/coredns").should be_false
Expand All @@ -93,9 +118,12 @@ describe "SampleUtils" do
end

it "'CNFManager.sample_setup_args' should be able to deploy using a helm_directory", tags: "happy-path" do
args = Sam::Args.new
config_file = "sample-cnfs/sample_privileged_cnf"
CNFManager.sample_setup_args(sample_dir: config_file, deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# CNFManager.sample_setup_args(sample_dir: config_file, deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = config.cnf_config[:release_name]
(Dir.exists? "cnfs/#{release_name}").should be_true
Expand All @@ -108,9 +136,13 @@ describe "SampleUtils" do
end

it "'CNFManager.sample_setup_args and CNFManager.sample_cleanup' should be able to deploy and cleanup using a manifest_directory", tags: "happy-path" do
args = Sam::Args.new
config_file = "sample-cnfs/k8s-non-helm"
CNFManager.sample_setup_args(sample_dir: config_file, deploy_with_chart: false, args: args, verbose: true, install_from_manifest: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# config_file = "sample-cnfs/k8s-non-helm"
# CNFManager.sample_setup_args(sample_dir: config_file, deploy_with_chart: false, args: args, verbose: true, install_from_manifest: true, wait_count: 0 )
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = config.cnf_config[:release_name]
(Dir.exists? "cnfs/#{release_name}").should be_true
Expand All @@ -129,18 +161,28 @@ describe "SampleUtils" do
end

it "'CNFManager.cnf_config_list' should return a list of all of the config files from the cnf directory", tags: "happy-path" do
args = Sam::Args.new
config_file = "sample-cnfs/sample-generic-cnf"
CNFManager.sample_setup_args(sample_dir: config_file, args: args, verbose: true, wait_count: 1 )
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", args: args, verbose: true )
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# args = Sam::Args.new
# config_file = "sample-cnfs/sample-generic-cnf"
# CNFManager.sample_setup_args(sample_dir: config_file, args: args, verbose: true, wait_count: 1 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_privileged_cnf/cnf-conformance.yml", "verbose"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", args: args, verbose: true )
config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = config.cnf_config[:release_name]
CNFManager.cnf_config_list()[0].should contain("#{release_name}/#{CONFIG_FILE}")
end

it "'CNFManager.helm_repo_add' should add a helm repo if the helm repo is valid", tags: "happy-path" do
args = Sam::Args.new
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 1 )
config_file = "sample-cnfs/sample-generic-cnf"
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
# args = Sam::Args.new
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 1 )
# CNFManager.helm_repo_add.should eq(true)
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-conformance.yml"])
CNFManager.helm_repo_add(args: args).should eq(true)
Expand Down
13 changes: 10 additions & 3 deletions spec/utils/utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,17 @@ describe "Utils" do
end

it "'task_runner' should run a test against a single cnf if passed a cnf-config argument even if there are multiple cnfs installed" do
my_args = Sam::Args.new
config_file = "sample-cnfs/sample-generic-cnf"
CNFManager.sample_setup_args(sample_dir: config_file, args: my_args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", args: my_args )
args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_privileged_cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
# my_args = Sam::Args.new
# config_file = "sample-cnfs/sample-generic-cnf"
# CNFManager.sample_setup_args(sample_dir: config_file, args: my_args)
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", args: my_args )
cnfmng_config = CNFManager::Config.parse_config_yml(CNFManager.ensure_cnf_conformance_yml_path(config_file))
release_name = cnfmng_config.cnf_config[:release_name]
installed_args = Sam::Args.new(["cnf-config=./cnfs/#{release_name}/cnf-conformance.yml"])
Expand Down
98 changes: 64 additions & 34 deletions src/tasks/cnf_setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,108 @@ require "./utils/utils.cr"

desc "Sets up sample CoreDNS CNF"
task "sample_coredns_setup", ["helm_local_install"] do |_, args|
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf", args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf", args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-coredns-cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "sample_coredns_with_wait_setup", ["helm_local_install"] do |_, args|
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf", args: args, verbose: true)
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf", args: args, verbose: true)
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-coredns-cnf/cnf-conformance.yml", "verbose"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

desc "Sets up sample CoreDNS CNF with source"
task "sample_coredns_source_setup", ["helm_local_install"] do |_, args|
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf-source", args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf-source", args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-coredns-cnf-source/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

desc "Sets up an alternate sample CoreDNS CNF"
task "sample_coredns", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "sample_coredns new setup" if check_verbose(args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_coredns", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_coredns", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_coredns/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

desc "Sets up a Bad helm CNF Setup"
task "bad_helm_cnf_setup", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "bad_helm_cnf_setup" if check_verbose(args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-bad_helm_coredns-cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-bad_helm_coredns-cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-bad_helm_coredns-cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "sample_privileged_cnf_whitelisted_setup", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "sample_privileged_cnf_whitelisted_setup" if check_verbose(args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_whitelisted_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_whitelisted_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_whitelisted_privileged_cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "sample_privileged_cnf_non_whitelisted_setup", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "sample_privileged_cnf_non_whitelisted_setup" if check_verbose(args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_privileged_cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "sample_coredns_bad_liveness", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "sample_coredns_bad_liveness" if check_verbose(args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_coredns_bad_liveness", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_coredns_bad_liveness", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_coredns_bad_liveness/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "sample_generic_cnf_setup", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "sample_generic_cnf" if check_verbose(args)
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", deploy_with_chart: false, args: args, verbose: true )
# CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", deploy_with_chart: false, args: args, verbose: true )
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-conformance.yml", "verbose", "wait_count=0"])
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "cnf_setup", ["helm_local_install"] do |_, args|
VERBOSE_LOGGING.info "cnf_setup" if check_verbose(args)
VERBOSE_LOGGING.debug "args = #{args.inspect}" if check_verbose(args)
if args.named.keys.includes? "cnf-config"
yml_file = args.named["cnf-config"].as(String)
# example_cnf = File.dirname(File.expand_path(yml_file))
cnf = File.dirname(yml_file)
elsif args.named.keys.includes? "cnf-path"
cnf = args.named["cnf-path"].as(String)
else
stdout_failure "Error: You must supply either cnf-config or cnf-path"
exit 1
end
if args.named.keys.includes? "wait_count"
wait_count = args.named["wait_count"].to_i
elsif args.named.keys.includes? "wait-count"
wait_count = args.named["wait-count"].to_i
else
wait_count = 180
end
VERBOSE_LOGGING.info "cnf_setup cnf: #{cnf}" if check_verbose(args)
#TODO get cnf-conformance yml and if helm_directory supplied (or deploy with chart supplied) use deploy with chart
if args.named["deploy_with_chart"]? && args.named["deploy_with_chart"] == "false"
deploy_with_chart = false
else
deploy_with_chart = true
end
CNFManager.sample_setup_args(sample_dir: cnf, deploy_with_chart: deploy_with_chart, args: args, verbose: check_verbose(args), wait_count: wait_count )
# if args.named.keys.includes? "cnf-config"
# yml_file = args.named["cnf-config"].as(String)
# # example_cnf = File.dirname(File.expand_path(yml_file))
# cnf = File.dirname(yml_file)
# elsif args.named.keys.includes? "cnf-path"
# cnf = args.named["cnf-path"].as(String)
# else
# stdout_failure "Error: You must supply either cnf-config or cnf-path"
# exit 1
# end
# if args.named.keys.includes? "wait_count"
# wait_count = args.named["wait_count"].to_i
# elsif args.named.keys.includes? "wait-count"
# wait_count = args.named["wait-count"].to_i
# else
# wait_count = 180
# end
# VERBOSE_LOGGING.info "cnf_setup cnf: #{cnf}" if check_verbose(args)
# #TODO get cnf-conformance yml and if helm_directory supplied (or deploy with chart supplied) use deploy with chart
# if args.named["deploy_with_chart"]? && args.named["deploy_with_chart"] == "false"
# deploy_with_chart = false
# else
# deploy_with_chart = true
# end
# #TODO call sample_setup_cli_args
# CNFManager.sample_setup_args(sample_dir: cnf, deploy_with_chart: deploy_with_chart, args: args, verbose: check_verbose(args), wait_count: wait_count )
cli_hash = CNFManager.sample_setup_cli_args(args)
CNFManager.sample_setup(cli_hash)
end

task "cnf_cleanup" do |_, args|
Expand Down
Loading

0 comments on commit d9f4fc9

Please sign in to comment.