Module: KubernetesHarness::Subcommand
- Defined in:
- lib/k8s_harness/subcommand.rb
Overview
All entrypoints for our subcommands live here.
Class Method Summary collapse
- .create! ⇒ Object
- .destroy(options = {}) ⇒ Object
- .destroy_cluster!(disable_teardown) ⇒ Object
- .fail_if_validate_fails!(options) ⇒ Object
- .print_post_create_message(cluster_info) ⇒ Object
- .print_warning_if_teardown_disabled(teardown_flag) ⇒ Object
- .provision!(cluster_info) ⇒ Object
- .run(options = {}) ⇒ Object
- .run_tests!(options) ⇒ Object
- .setup!(options) ⇒ Object
- .teardown!(options) ⇒ Object
- .validate(options = {}) ⇒ Object
Class Method Details
.create! ⇒ Object
50 51 52 53 54 55 |
# File 'lib/k8s_harness/subcommand.rb', line 50 def self.create! KubernetesHarness.nice_logger.info( 'Creating your cluster now. Provisioning will occur in a few minutes.' ) KubernetesHarness::Clusters.create! end |
.destroy(options = {}) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/k8s_harness/subcommand.rb', line 32 def self.destroy( = {}) return true if .to_h[:show_usage] KubernetesHarness.nice_logger.info('Destroying your cluster (if any found).') KubernetesHarness::Clusters.destroy_existing! end |
.destroy_cluster!(disable_teardown) ⇒ Object
75 76 77 78 |
# File 'lib/k8s_harness/subcommand.rb', line 75 def self.destroy_cluster!(disable_teardown) KubernetesHarness.nice_logger.info('Done. Tearing down the cluster.') KubernetesHarness::Clusters.teardown! unless disable_teardown end |
.fail_if_validate_fails!(options) ⇒ Object
80 81 82 |
# File 'lib/k8s_harness/subcommand.rb', line 80 def self.fail_if_validate_fails!() _ = KubernetesHarness::HarnessFile.render() end |
.print_post_create_message(cluster_info) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/k8s_harness/subcommand.rb', line 84 def self.(cluster_info) # TODO: Make this not hardcoded. cluster_info_yaml_path = File.join Clusters::Metadata.default_dir, 'cluster.yaml' KubernetesHarness.nice_logger.info( <<~MESSAGE.strip Cluster has been created. Details are below and in YAML at #{cluster_info_yaml_path}: * Master address: '#{cluster_info.master_ip_address}' * Worker addresses: #{cluster_info.worker_ip_addresses} * Docker registry address: '#{cluster_info.docker_registry_address}' * Kubeconfig path: #{cluster_info.kubeconfig_path} * SSH key path: #{cluster_info.ssh_key_path} MESSAGE ) end |
.print_warning_if_teardown_disabled(teardown_flag) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/k8s_harness/subcommand.rb', line 39 def self.print_warning_if_teardown_disabled(teardown_flag) return unless teardown_flag KubernetesHarness.nice_logger.warn( <<~MESSAGE.strip Teardown is disabled. Your cluster will stay up until you run \ 'k8s-harness destroy'. MESSAGE ) end |
.provision!(cluster_info) ⇒ Object
57 58 59 60 |
# File 'lib/k8s_harness/subcommand.rb', line 57 def self.provision!(cluster_info) KubernetesHarness.nice_logger.info('Provisioning the cluster. This will take a few minutes.') KubernetesHarness::Clusters.provision!(cluster_info) end |
.run(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/k8s_harness/subcommand.rb', line 11 def self.run( = {}) fail_if_validate_fails!() disable_teardown = !.nil? && [:disable_teardown] return true if !.nil? && [:show_usage] print_warning_if_teardown_disabled(disable_teardown) cluster_info = create! provision!(cluster_info) (cluster_info) setup!() run_tests!() teardown!() destroy_cluster!(disable_teardown) end |
.run_tests!(options) ⇒ Object
66 67 68 69 |
# File 'lib/k8s_harness/subcommand.rb', line 66 def self.run_tests!() KubernetesHarness.nice_logger.info('Running your tests.') KubernetesHarness::HarnessFile.execute_tests!() end |
.setup!(options) ⇒ Object
62 63 64 |
# File 'lib/k8s_harness/subcommand.rb', line 62 def self.setup!() KubernetesHarness::HarnessFile.execute_setup!() end |
.teardown!(options) ⇒ Object
71 72 73 |
# File 'lib/k8s_harness/subcommand.rb', line 71 def self.teardown!() KubernetesHarness::HarnessFile.execute_teardown!() end |
.validate(options = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/k8s_harness/subcommand.rb', line 26 def self.validate( = {}) return true if .to_h[:show_usage] KubernetesHarness::HarnessFile.validate() end |