Grid環境構築用のChefリポジトリです。
Révision | 1dfe2cbd425ade948000ceff2eab75cfcfff6b31 (tree) |
---|---|
l'heure | 2016-09-20 20:20:20 |
Auteur | whitestar <whitestar@gaea...> |
Commiter | whitestar |
dcos-grid-0.3.3
@@ -31,7 +31,7 @@ Style/WordArray: | ||
31 | 31 | |
32 | 32 | #Style/AccessorMethodName: |
33 | 33 | # Enabled: false |
34 | -#Style/MethodLength: | |
35 | -# Max: 30 | |
34 | +Style/MethodLength: | |
35 | + Max: 15 | |
36 | 36 | #Style/ModuleLength: |
37 | 37 | # Max: 150 |
@@ -1,6 +1,10 @@ | ||
1 | 1 | dcos-grid CHANGELOG |
2 | 2 | =================== |
3 | 3 | |
4 | +0.3.3 | |
5 | +----- | |
6 | +- improves configuration validation. | |
7 | + | |
4 | 8 | 0.3.2 |
5 | 9 | ----- |
6 | 10 | - adds `['dcos-grid']['bootstrap']['config']['master_discovery']` default value. |
@@ -18,6 +18,7 @@ | ||
18 | 18 | # |
19 | 19 | |
20 | 20 | module DCOSGrid |
21 | + # Helper methods | |
21 | 22 | module Helper |
22 | 23 | CONFIG_PARAMS = %w( |
23 | 24 | agent_list |
@@ -65,6 +66,38 @@ module DCOSGrid | ||
65 | 66 | oauth_enabled |
66 | 67 | oauth_issuer_url |
67 | 68 | oauth_client_id |
69 | + dcos_overlay_network | |
70 | + vtep_subnet | |
71 | + vtep_mac_oui | |
72 | + overlays | |
73 | + name | |
74 | + subnet | |
75 | + prefix | |
68 | 76 | ).freeze |
77 | + | |
78 | + def sanitize_config(config) | |
79 | + config = Marshal.load(Marshal.dump(config)) | |
80 | + validate_config_keys(config) | |
81 | + config | |
82 | + end | |
83 | + | |
84 | + def validate_config_keys(config_node) | |
85 | + if config_node.is_a?(Hash) | |
86 | + config_node.each {|key, value| | |
87 | + unless CONFIG_PARAMS.include?(key) | |
88 | + Chef::Log.warn("invalid config key: #{key}") | |
89 | + # Chef attribute container is immutable. | |
90 | + #config_node.delete(key) | |
91 | + next | |
92 | + end | |
93 | + | |
94 | + validate_config_keys(value) | |
95 | + } | |
96 | + elsif config_node.is_a?(Array) | |
97 | + config_node.each {|elm| | |
98 | + validate_config_keys(elm) | |
99 | + } | |
100 | + end | |
101 | + end | |
69 | 102 | end |
70 | 103 | end |
@@ -5,7 +5,7 @@ maintainer_email '' | ||
5 | 5 | license 'Apache 2.0' |
6 | 6 | description 'Installs/Configures DC/OS Cluster Node.' |
7 | 7 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) |
8 | -version '0.3.2' | |
8 | +version '0.3.3' | |
9 | 9 | source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git' |
10 | 10 | issues_url 'https://osdn.jp/projects/metasearch/ticket' |
11 | 11 |
@@ -23,12 +23,13 @@ include_recipe 'dcos-grid::node-commons' | ||
23 | 23 | |
24 | 24 | genconf_dir = node['dcos-grid']['bootstrap']['genconf_dir'] |
25 | 25 | |
26 | +validate_config_keys(node['dcos-grid']['bootstrap']['config']) | |
27 | + | |
26 | 28 | template "#{genconf_dir}/config.yaml" do |
27 | 29 | source 'opt/dcos-grid/genconf/config.yaml' |
28 | 30 | owner 'root' |
29 | 31 | group 'root' |
30 | 32 | mode '0644' |
31 | - variables config_params: CONFIG_PARAMS | |
32 | 33 | end |
33 | 34 | |
34 | 35 | template "#{genconf_dir}/ip-detect" do |
@@ -29,12 +29,13 @@ directory genconf_dir do | ||
29 | 29 | action :create |
30 | 30 | end |
31 | 31 | |
32 | +validate_config_keys(node['dcos-grid']['bootstrap']['config']) | |
33 | + | |
32 | 34 | template "#{File.dirname(genconf_dir)}/cloud-config.yaml" do |
33 | 35 | source 'opt/dcos-grid/cloud-config.yaml' |
34 | 36 | owner 'root' |
35 | 37 | group 'root' |
36 | 38 | mode '0644' |
37 | - variables config_params: CONFIG_PARAMS | |
38 | 39 | end |
39 | 40 | |
40 | 41 | log <<-EOM |
@@ -71,35 +71,11 @@ dcos_config['resolvers'].each {|resolv| | ||
71 | 71 | owner: "<%= cloud_config['target_owner'] %>" |
72 | 72 | <% |
73 | 73 | require 'yaml' |
74 | -indent = ' ' * 6 | |
75 | -yaml_str = dcos_config.to_yaml.each_line.map {|line| indent + line}.join | |
74 | +# trimming ! tags and indentation. | |
75 | +yaml_str = dcos_config.to_yaml.gsub!(/ !.+$/, '').gsub!(/^/, ' ' * 6) | |
76 | 76 | -%> |
77 | 77 | content: | |
78 | -<%#= yaml_str -%> | |
79 | - --- | |
80 | -<% | |
81 | -dcos_config.each {|key, value| | |
82 | - if !@config_params.include?(key) || value.nil? || value.empty? then | |
83 | - Chef::Log.warn("invalid config key: #{key}") | |
84 | - next | |
85 | - end | |
86 | - | |
87 | - if value.is_a?(String) then | |
88 | --%> | |
89 | - <%= key %>: <%= value %> | |
90 | -<% | |
91 | - elsif value.is_a?(Array) then | |
92 | --%> | |
93 | - <%= key %>: | |
94 | -<% | |
95 | - value.each {|val| | |
96 | --%> | |
97 | - - <%= val %> | |
98 | -<% | |
99 | - } | |
100 | - end | |
101 | -} | |
102 | --%> | |
78 | +<%= yaml_str -%> | |
103 | 79 | - path: "<%= cloud_config['target_dir'] %>/genconf/ip-detect" |
104 | 80 | permissions: "0755" |
105 | 81 | owner: "<%= cloud_config['target_owner'] %>" |
@@ -1,31 +1,10 @@ | ||
1 | ---- | |
2 | 1 | <% |
3 | 2 | # NOTE for cookbook developer: If you edit this script, you must update opt/dcos-grid/cloud-config.yaml |
4 | 3 | |
5 | -config = node['dcos-grid']['bootstrap']['config'] | |
4 | +dcos_config = node['dcos-grid']['bootstrap']['config'] | |
6 | 5 | |
7 | -#require 'yaml' | |
8 | -#yaml_str = config.to_yaml | |
9 | - | |
10 | -config.each {|key, value| | |
11 | - if !@config_params.include?(key) || value.nil? || value.empty? then | |
12 | - Chef::Log.warn("invalid config key: #{key}") | |
13 | - next | |
14 | - end | |
15 | - | |
16 | - if value.is_a?(String) then | |
17 | --%> | |
18 | -<%= key %>: <%= value %> | |
19 | -<% | |
20 | - elsif value.is_a?(Array) then | |
21 | --%> | |
22 | -<%= key %>: | |
23 | -<% | |
24 | - value.each {|val| | |
25 | --%> | |
26 | -- <%= val %> | |
27 | -<% | |
28 | - } | |
29 | - end | |
30 | -} | |
6 | +require 'yaml' | |
7 | +# trimming ! tags. | |
8 | +yaml_str = dcos_config.to_yaml.gsub!(/ !.+$/, '') | |
31 | 9 | -%> |
10 | +<%= yaml_str %> |
@@ -30,7 +30,25 @@ override_attributes( | ||
30 | 30 | 'resolvers' => [ |
31 | 31 | '8.8.8.8', |
32 | 32 | '8.8.4.4', |
33 | + #{ | |
34 | + # 'invalid_name' => 'dummy', | |
35 | + #}, | |
33 | 36 | ], |
37 | + 'telemetry_enabled' => 'false', | |
38 | + #'invalid_key' => 'dummy', | |
39 | +=begin | |
40 | + 'dcos_overlay_network' => { | |
41 | + 'vtep_subnet' => '44.128.0.0/20', | |
42 | + 'vtep_mac_oui' => '70:B3:D5:00:00:00', | |
43 | + 'overlays' => [ | |
44 | + { | |
45 | + 'name' => 'dcos', | |
46 | + 'subnet' => '9.0.0.0/8', | |
47 | + 'prefix' => '26', | |
48 | + }, | |
49 | + ], | |
50 | + }, | |
51 | +=end | |
34 | 52 | }, |
35 | 53 | 'ip-detect' => { |
36 | 54 | # the first detected interface's ip is adopted. |