Class: Porkadot::Configs::EtcdNode

Inherits:
Object
  • Object
show all
Includes:
Porkadot::ConfigUtils, CertsUtils
Defined in:
lib/porkadot/configs/etcd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CertsUtils

#certs_root_dir, #ipaddr?

Methods included from Porkadot::ConfigUtils

#asset_path, #config, #logger, #method_missing, #raw, #respond_to_missing?, #secrets_path

Constructor Details

#initialize(config, name, raw) ⇒ EtcdNode

Returns a new instance of EtcdNode.



27
28
29
30
31
32
# File 'lib/porkadot/configs/etcd.rb', line 27

def initialize config, name, raw
  @config = config
  @kubelet = config.nodes[name]
  @name = name
  @raw = raw || ::Porkadot::Raw.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Porkadot::ConfigUtils

Instance Attribute Details

#kubeletObject (readonly)

Returns the value of attribute kubelet.



24
25
26
# File 'lib/porkadot/configs/etcd.rb', line 24

def kubelet
  @kubelet
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/porkadot/configs/etcd.rb', line 25

def name
  @name
end

Instance Method Details

#additional_sansObject



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/porkadot/configs/etcd.rb', line 107

def additional_sans
  sans = []
  [self.member_name, self.member_address].each do |san|
    if self.ipaddr?(san)
      sans << "IP:#{san}"
    else
      sans << "DNS:#{san}"
    end
  end
  sans << "IP:127.0.0.1"
  return sans
end


69
70
71
# File 'lib/porkadot/configs/etcd.rb', line 69

def advertise_client_urls
 ["https://#{member_address}:2379"]
end


73
74
75
# File 'lib/porkadot/configs/etcd.rb', line 73

def advertise_peer_urls
  ["https://#{member_address}:2380"]
end

#ca_crt_pathObject



128
129
130
# File 'lib/porkadot/configs/etcd.rb', line 128

def ca_crt_path
  File.join(self.target_secrets_path, 'ca.crt')
end

#etcd_crt_pathObject



136
137
138
# File 'lib/porkadot/configs/etcd.rb', line 136

def etcd_crt_path
  File.join(self.target_secrets_path, 'etcd.crt')
end

#etcd_key_pathObject



132
133
134
# File 'lib/porkadot/configs/etcd.rb', line 132

def etcd_key_path
  File.join(self.target_secrets_path, 'etcd.key')
end

#initial_clusterObject



99
100
101
102
103
104
105
# File 'lib/porkadot/configs/etcd.rb', line 99

def initial_cluster
  return {}.tap do |rtn|
    self.config.etcd_nodes.each do |_, v|
      rtn[v.member_name] = "https://#{v.member_address}:2380"
    end
  end
end

#listen_address(label_key) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/porkadot/configs/etcd.rb', line 42

def listen_address label_key
  listen_address = nil
  if self.raw.labels
    listen_address = self.raw.labels[label_key] || self.raw.labels[Porkadot::ETCD_LISTEN_ADDRESS_LABEL]
  end

  if !listen_adress
    if self.ipaddr?(self.raw.hostname)
      listen_address = self.raw.hostname
    elsif self.ipaddr?(self.raw.name)
      listen_address = self.raw.name
    else
      listen_address = '0.0.0.0'
    end
  end

  return listen_address
end

#listen_client_addressObject



61
62
63
# File 'lib/porkadot/configs/etcd.rb', line 61

def listen_client_address
  return self.listen_address(Porkadot::ETCD_LISTEN_CLIENT_ADDRESS_LABEL)
end

#listen_client_urlsObject



77
78
79
80
81
82
83
84
# File 'lib/porkadot/configs/etcd.rb', line 77

def listen_client_urls
  address = self.listen_client_address
  if address != '0.0.0.0'
    return  ["https://#{address}:2379", "https://127.0.0.1:2379"]
  else
    return  ["https://#{address}:2379"]
  end
end

#listen_metrics_urlsObject



90
91
92
93
94
95
96
97
# File 'lib/porkadot/configs/etcd.rb', line 90

def listen_metrics_urls
  address = self.listen_client_address
  if address != '0.0.0.0'
    return  ["http://#{address}:2381", "http://127.0.0.1:2381"]
  else
    return  ["http://#{address}:2381"]
  end
end

#listen_peer_addressObject



65
66
67
# File 'lib/porkadot/configs/etcd.rb', line 65

def listen_peer_address
  return self.listen_address(Porkadot::ETCD_LISTEN_PEER_ADDRESS_LABEL)
end

#listen_peer_urlsObject



86
87
88
# File 'lib/porkadot/configs/etcd.rb', line 86

def listen_peer_urls
  ["https://#{self.listen_client_address}:2380"]
end

#member_addressObject



38
39
40
# File 'lib/porkadot/configs/etcd.rb', line 38

def member_address
  return (self.raw.labels && self.raw.labels[Porkadot::ETCD_ADDRESS_LABEL]) || self.raw.hostname || self.name
end

#member_nameObject



34
35
36
# File 'lib/porkadot/configs/etcd.rb', line 34

def member_name
  return (self.raw.labels && self.raw.labels[Porkadot::ETCD_MEMBER_LABEL]) || self.raw.hostname || self.name
end

#target_pathObject



120
121
122
# File 'lib/porkadot/configs/etcd.rb', line 120

def target_path
  File.join(self.kubelet.addon_path, 'etcd')
end

#target_secrets_pathObject



124
125
126
# File 'lib/porkadot/configs/etcd.rb', line 124

def target_secrets_path
  File.join(self.kubelet.addon_secrets_path, 'etcd')
end