From 9fbbd258956b3fa20d3057b20d5227f47817b2b3 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Wed, 30 Jan 2019 12:49:26 +0200 Subject: [PATCH 1/3] Drop phase master: parameter --- lib/pharos/cluster_manager.rb | 36 ++++++++++----------- lib/pharos/phase.rb | 4 +-- spec/pharos/phases/configure_calico_spec.rb | 2 +- spec/pharos/phases/configure_dns_spec.rb | 2 +- spec/pharos/phases/label_node_spec.rb | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/pharos/cluster_manager.rb b/lib/pharos/cluster_manager.rb index 94cee8f25..8c9eb9362 100644 --- a/lib/pharos/cluster_manager.rb +++ b/lib/pharos/cluster_manager.rb @@ -60,7 +60,7 @@ def gather_facts apply_phase(Phases::ConnectSSH, config.hosts, parallel: true) apply_phase(Phases::AuthenticateSSH, config.hosts.reject(&:ssh?), parallel: false) apply_phase(Phases::GatherFacts, config.hosts, parallel: true) - apply_phase(Phases::ConfigureClient, [config.master_host], master: config.master_host, parallel: false, optional: true) + apply_phase(Phases::ConfigureClient, [config.master_host], parallel: false, optional: true) end def validate @@ -68,15 +68,15 @@ def validate addon_manager.validate gather_facts apply_phase(Phases::ValidateHost, config.hosts, parallel: true) - apply_phase(Phases::ValidateVersion, [config.master_host], master: config.master_host, parallel: false) + apply_phase(Phases::ValidateVersion, [config.master_host], parallel: false) end def apply_phases master_hosts = config.master_hosts apply_phase(Phases::MigrateMaster, master_hosts, parallel: true) - apply_phase(Phases::ConfigureHost, config.hosts, master: master_hosts.first, parallel: true) + apply_phase(Phases::ConfigureHost, config.hosts, parallel: true) apply_phase(Phases::ConfigureFirewalld, config.hosts, parallel: true) - apply_phase(Phases::ConfigureClient, [master_hosts.first], master: master_hosts.first, parallel: false, optional: true) + apply_phase(Phases::ConfigureClient, [master_hosts.first], parallel: false, optional: true) unless @config.etcd&.endpoints etcd_hosts = config.etcd_hosts @@ -88,32 +88,32 @@ def apply_phases apply_phase(Phases::ConfigureSecretsEncryption, master_hosts, parallel: false) apply_phase(Phases::SetupMaster, master_hosts, parallel: true) - apply_phase(Phases::UpgradeMaster, master_hosts, master: master_hosts.first, parallel: false) # requires optional early ConfigureClient + apply_phase(Phases::UpgradeMaster, master_hosts, parallel: false) # requires optional early ConfigureClient - apply_phase(Phases::MigrateWorker, config.worker_hosts, parallel: true, master: master_hosts.first) + apply_phase(Phases::MigrateWorker, config.worker_hosts, parallel: true) apply_phase(Phases::ConfigureKubelet, config.hosts, parallel: true) apply_phase(Phases::PullMasterImages, master_hosts, parallel: true) apply_phase(Phases::ConfigureMaster, master_hosts, parallel: false) - apply_phase(Phases::ConfigureClient, [master_hosts.first], master: master_hosts.first, parallel: false) + apply_phase(Phases::ConfigureClient, [master_hosts.first], parallel: false) # master is now configured and can be used - apply_phase(Phases::LoadClusterConfiguration, [master_hosts.first], master: master_hosts.first) + apply_phase(Phases::LoadClusterConfiguration, [master_hosts.first]) # configure essential services - apply_phase(Phases::ConfigurePSP, [master_hosts.first], master: master_hosts.first) - apply_phase(Phases::ConfigureDNS, [master_hosts.first], master: master_hosts.first) - apply_phase(Phases::ConfigureWeave, [master_hosts.first], master: master_hosts.first) if config.network.provider == 'weave' - apply_phase(Phases::ConfigureCalico, [master_hosts.first], master: master_hosts.first) if config.network.provider == 'calico' - apply_phase(Phases::ConfigureCustomNetwork, [master_hosts.first], master: master_hosts.first) if config.network.provider == 'custom' + apply_phase(Phases::ConfigurePSP, [master_hosts.first]) + apply_phase(Phases::ConfigureDNS, [master_hosts.first]) + apply_phase(Phases::ConfigureWeave, [master_hosts.first]) if config.network.provider == 'weave' + apply_phase(Phases::ConfigureCalico, [master_hosts.first]) if config.network.provider == 'calico' + apply_phase(Phases::ConfigureCustomNetwork, [master_hosts.first]) if config.network.provider == 'custom' apply_phase(Phases::ConfigureBootstrap, [master_hosts.first]) # using `kubeadm token`, not the kube API apply_phase(Phases::JoinNode, config.worker_hosts, parallel: true) - apply_phase(Phases::LabelNode, config.hosts, master: master_hosts.first, parallel: false) # NOTE: uses the @master kube API for each node, not threadsafe + apply_phase(Phases::LabelNode, config.hosts, parallel: false) # NOTE: uses the @master kube API for each node, not threadsafe # configure services that need workers - apply_phase(Phases::ConfigureMetrics, [master_hosts.first], master: master_hosts.first) - apply_phase(Phases::ConfigureTelemetry, [master_hosts.first], master: master_hosts.first) + apply_phase(Phases::ConfigureMetrics, [master_hosts.first]) + apply_phase(Phases::ConfigureTelemetry, [master_hosts.first]) end # @param hosts [Array] @@ -121,7 +121,7 @@ def apply_reset_hosts(hosts) master_hosts = config.master_hosts if master_hosts.first.master_sort_score.zero? apply_phase(Phases::Drain, hosts, parallel: false) - apply_phase(Phases::DeleteHost, hosts, parallel: false, master: master_hosts.first) + apply_phase(Phases::DeleteHost, hosts, parallel: false) end addon_manager.each do |addon| next unless addon.enabled? @@ -168,7 +168,7 @@ def post_install_messages def save_config master_host = config.master_host - apply_phase(Phases::StoreClusterConfiguration, [master_host], master: master_host) + apply_phase(Phases::StoreClusterConfiguration, [master_host]) end def disconnect diff --git a/lib/pharos/phase.rb b/lib/pharos/phase.rb index 05a2998fe..6195d380e 100644 --- a/lib/pharos/phase.rb +++ b/lib/pharos/phase.rb @@ -24,11 +24,9 @@ def self.register_component(component) # @param host [Pharos::Configuration::Host] # @param config [Pharos::Config] - # @param master [Pharos::Configuration::Host] - def initialize(host, config: nil, master: nil, cluster_context: nil) + def initialize(host, config: nil, cluster_context: nil) @host = host @config = config - @master = master @cluster_context = cluster_context end diff --git a/spec/pharos/phases/configure_calico_spec.rb b/spec/pharos/phases/configure_calico_spec.rb index da5b7f7ea..4181d9f68 100644 --- a/spec/pharos/phases/configure_calico_spec.rb +++ b/spec/pharos/phases/configure_calico_spec.rb @@ -11,7 +11,7 @@ kubelet: {read_only_port: false} ) } - subject { described_class.new(host, config: config, master: host) } + subject { described_class.new(host, config: config) } describe '#get_ippool' do let(:kube_client) { instance_double(K8s::Client) } diff --git a/spec/pharos/phases/configure_dns_spec.rb b/spec/pharos/phases/configure_dns_spec.rb index 859f602c9..d8be3ba84 100644 --- a/spec/pharos/phases/configure_dns_spec.rb +++ b/spec/pharos/phases/configure_dns_spec.rb @@ -19,7 +19,7 @@ allow(master).to receive(:cpu_arch).and_return(cpu_arch) end - subject { described_class.new(master, config: config, master: master) } + subject { described_class.new(master, config: config) } describe '#call' do context "with one host" do diff --git a/spec/pharos/phases/label_node_spec.rb b/spec/pharos/phases/label_node_spec.rb index a8e8ce540..9a1b932d7 100644 --- a/spec/pharos/phases/label_node_spec.rb +++ b/spec/pharos/phases/label_node_spec.rb @@ -3,7 +3,7 @@ describe Pharos::Phases::LabelNode do let(:master) { Pharos::Configuration::Host.new(address: '192.0.2.1') } let(:host) { Pharos::Configuration::Host.new(address: '192.0.2.2', labels: { foo: 'bar' } ) } - let(:subject) { described_class.new(host, master: master) } + let(:subject) { described_class.new(host) } let(:kube_client) { instance_double(K8s::Client) } let(:kube_api_v1) { instance_double(K8s::APIClient) } From 80931d0f903a38f758742e52fc8db6591c2401a3 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Wed, 30 Jan 2019 12:52:39 +0200 Subject: [PATCH 2/3] Pro configure_host had @master --- non-oss/pharos_pro/phases/configure_host.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/non-oss/pharos_pro/phases/configure_host.rb b/non-oss/pharos_pro/phases/configure_host.rb index 6c46da965..0fb003fa6 100644 --- a/non-oss/pharos_pro/phases/configure_host.rb +++ b/non-oss/pharos_pro/phases/configure_host.rb @@ -41,12 +41,8 @@ def drain_host! master_ssh.exec!("kubectl drain --force --grace-period=0 --ignore-daemonsets --delete-local-data #{@host.hostname}") end - def master_ssh - @master.ssh - end - def master_healthy? - @master.master_sort_score.zero? + @config.master_host.master_sort_score.zero? end end end From 281a11381a0b9be2bbebc98d5ec78d06d6371d5c Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Wed, 30 Jan 2019 12:57:33 +0200 Subject: [PATCH 3/3] Prettify the [master_hosts.first] --- lib/pharos/cluster_manager.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/pharos/cluster_manager.rb b/lib/pharos/cluster_manager.rb index 8c9eb9362..3b914b052 100644 --- a/lib/pharos/cluster_manager.rb +++ b/lib/pharos/cluster_manager.rb @@ -73,10 +73,11 @@ def validate def apply_phases master_hosts = config.master_hosts + master_only = [config.master_host] apply_phase(Phases::MigrateMaster, master_hosts, parallel: true) apply_phase(Phases::ConfigureHost, config.hosts, parallel: true) apply_phase(Phases::ConfigureFirewalld, config.hosts, parallel: true) - apply_phase(Phases::ConfigureClient, [master_hosts.first], parallel: false, optional: true) + apply_phase(Phases::ConfigureClient, master_only, parallel: false, optional: true) unless @config.etcd&.endpoints etcd_hosts = config.etcd_hosts @@ -95,25 +96,25 @@ def apply_phases apply_phase(Phases::PullMasterImages, master_hosts, parallel: true) apply_phase(Phases::ConfigureMaster, master_hosts, parallel: false) - apply_phase(Phases::ConfigureClient, [master_hosts.first], parallel: false) + apply_phase(Phases::ConfigureClient, master_only, parallel: false) # master is now configured and can be used - apply_phase(Phases::LoadClusterConfiguration, [master_hosts.first]) + apply_phase(Phases::LoadClusterConfiguration, master_only) # configure essential services - apply_phase(Phases::ConfigurePSP, [master_hosts.first]) - apply_phase(Phases::ConfigureDNS, [master_hosts.first]) - apply_phase(Phases::ConfigureWeave, [master_hosts.first]) if config.network.provider == 'weave' - apply_phase(Phases::ConfigureCalico, [master_hosts.first]) if config.network.provider == 'calico' - apply_phase(Phases::ConfigureCustomNetwork, [master_hosts.first]) if config.network.provider == 'custom' + apply_phase(Phases::ConfigurePSP, master_only) + apply_phase(Phases::ConfigureDNS, master_only) + apply_phase(Phases::ConfigureWeave, master_only) if config.network.provider == 'weave' + apply_phase(Phases::ConfigureCalico, master_only) if config.network.provider == 'calico' + apply_phase(Phases::ConfigureCustomNetwork, master_only) if config.network.provider == 'custom' - apply_phase(Phases::ConfigureBootstrap, [master_hosts.first]) # using `kubeadm token`, not the kube API + apply_phase(Phases::ConfigureBootstrap, master_only) # using `kubeadm token`, not the kube API apply_phase(Phases::JoinNode, config.worker_hosts, parallel: true) apply_phase(Phases::LabelNode, config.hosts, parallel: false) # NOTE: uses the @master kube API for each node, not threadsafe # configure services that need workers - apply_phase(Phases::ConfigureMetrics, [master_hosts.first]) - apply_phase(Phases::ConfigureTelemetry, [master_hosts.first]) + apply_phase(Phases::ConfigureMetrics, master_only) + apply_phase(Phases::ConfigureTelemetry, master_only) end # @param hosts [Array]