ky 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1de2efb87f781886061141962646b113a33da52
4
- data.tar.gz: c51ee92b728200441a515f09953a2a25ac71d494
3
+ metadata.gz: a3e2cbbf671a3e7fd09fb7eac2e4b209cc2eccc5
4
+ data.tar.gz: aea2bbb6db0bde006fea255fdbbcc53bb502b79f
5
5
  SHA512:
6
- metadata.gz: 435791205d319456386a1b81774768ef80618225a15a55edca06839cdd1905bf4ad91cc0ee8e654ef5ed6d8a4bd032d95b4c878b103e4213aa96280325479064
7
- data.tar.gz: 5b41cec9ba39bbf3b67cc5e7bfd102d5dfebc45992550031032500d164270fd8bf8053dbf7ee18576e1affab37c07c590f55dd4748a1bb4069714ed6f708af7b
6
+ metadata.gz: a486fa1c392976cd44a83a5498728fb60f6ebd222432725537bc2b82609a6f035956a6a24fd1feaa583ed715168fa9af38a3b7e10787019eb409c22afb93f5dc
7
+ data.tar.gz: 0def538f73dcbbe5a574363911feff3b94e58f92646b8370074b375bdcfb3288b66424ca67f64eb87279934e7c7bd0356e121d927dce37db3d5cf77d236357ff
data/ky.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_development_dependency 'rspec', '~> 3.5'
18
18
  s.add_development_dependency 'pry', '~> 0.10'
19
19
  s.add_runtime_dependency 'thor', '~> 0.19'
20
+ s.add_runtime_dependency 'activesupport', '>= 3.0'
20
21
  s.add_runtime_dependency 'deep_merge', '~> 1.1'
21
22
 
22
23
  s.description = <<-DESC
data/lib/ky/cli.rb CHANGED
@@ -1,40 +1,40 @@
1
1
  require_relative '../ky'
2
2
  require 'thor'
3
- class KY
3
+ module KY
4
4
  class Cli < Thor
5
5
  MissingParametersError = Class.new(StandardError)
6
6
  desc "encode secrets.yml", "base64 encoded yaml version of data attributes in secrets.yml"
7
7
  def encode(input_source=$stdin, output_source=$stdout)
8
8
  input_output(input_source, output_source) do |input_object, output_object|
9
- KY.new.encode(output_object, input_object)
9
+ Manipulation.encode(output_object, input_object)
10
10
  end
11
11
  end
12
12
 
13
13
  desc "decode secrets.yml", "decoded yaml version of secrets.yml with base64 encoded data attributes"
14
14
  def decode(input_source=$stdin, output_source=$stdout)
15
15
  input_output(input_source, output_source) do |input_object, output_object|
16
- KY.new.decode(output_object, input_object)
16
+ Manipulation.decode(output_object, input_object)
17
17
  end
18
18
  end
19
19
 
20
20
  desc "merge base.yml env.yml", "deep merged/combined yaml of two seperate files"
21
21
  def merge(input_source1, input_source2=$stdin, output_source=$stdout)
22
22
  input_output(input_source1, output_source) do |input_object1, output_object|
23
- with(input_source2, 'r') {|input_object2| KY.new.merge(output_object, input_object1, input_object2) }
23
+ with(input_source2, 'r') {|input_object2| Manipulation.merge(output_object, input_object1, input_object2) }
24
24
  end
25
25
  end
26
26
 
27
27
  desc "env config.yml secrets.yml", "generate env variables section of a deployment from a config and a secrets file"
28
28
  def env(input_source1, input_source2=$stdin, output_source=$stdout)
29
29
  input_output(input_source1, output_source) do |input_object1, output_object|
30
- with(input_source2, 'r') {|input_object2| KY.new.env(output_object, input_object1, input_object2) }
30
+ with(input_source2, 'r') {|input_object2| EnvGeneration.env(output_object, input_object1, input_object2) }
31
31
  end
32
32
  end
33
33
 
34
- desc "compile Procfile config.yml secrets.yml output", <<-DOC.strip_heredoc
35
- Generate kubernetes deployment.yml from Procfile;
34
+ desc "compile (config.yml secrets.yml output)", <<-DOC.strip_heredoc
35
+ Generate kubernetes deployment.yml from Procfile and env files;
36
36
  also generate/copy config/secrets files to output_dir, base64 encode secrets if unencoded.
37
- Procfile path may also be specified in configuration as procfile_path
37
+ Procfile path may be specified in configuration as procfile_path or via flag.
38
38
  ConfigMap.yml file path may also be specified in configuration as config_path
39
39
  secrets.yml file path may also be specified in configuration as secret_path
40
40
  Output directory may also be specified in configuration as output_dir
@@ -42,15 +42,15 @@ class KY
42
42
  method_option :namespace, type: :string, aliases: "-n"
43
43
  method_option :environment, type: :string, aliases: "-e"
44
44
  method_option :image_tag, type: :string, aliases: "-t"
45
- def compile(procfile_path=nil, config_or_secrets_path=nil, secrets_or_config_path=nil, output_dir=nil)
46
- instance = KY.new(options.with_indifferent_access)
47
- procfile_path ||= instance.configuration['procfile_path']
45
+ method_option :procfile_path, type: :string, aliases: "-p"
46
+ def compile(config_or_secrets_path=nil, secrets_or_config_path=nil, output_dir=nil)
47
+ instance = Compilation.new(options.with_indifferent_access)
48
48
  config_or_secrets_path ||= instance.configuration['config_path'] || instance.configuration['secret_path']
49
49
  secrets_or_config_path ||= instance.configuration['secret_path'] || instance.configuration['config_path']
50
50
  output_dir ||= instance.configuration['output_dir']
51
- raise MissingParametersError unless procfile_path && config_or_secrets_path && secrets_or_config_path && output_dir
51
+ raise MissingParametersError unless config_or_secrets_path && secrets_or_config_path && output_dir && instance.configuration['procfile_path']
52
52
  input_input(config_or_secrets_path, secrets_or_config_path) do |input1, input2|
53
- instance.compile(procfile_path, input1, input2, output_dir)
53
+ instance.compile(input1, input2, output_dir)
54
54
  end
55
55
  end
56
56
 
@@ -0,0 +1,20 @@
1
+ module KY
2
+ class Compilation
3
+ attr_reader :configuration
4
+
5
+ def initialize(opts={})
6
+ @configuration = Configuration.new(opts)
7
+ end
8
+
9
+ def compile(env1path, env2path, base_output_dir)
10
+ full_output_dir = Pathname.new(base_output_dir).join(configuration[:environment].to_s).to_s
11
+ FileUtils.mkdir_p(full_output_dir)
12
+ env_obj = EnvGeneration.new(env1path, env2path, configuration)
13
+ deploys_hash = DeployGeneration.new(full_output_dir, env_obj.project, configuration).to_h
14
+ deploys_hash.each do |file_path, deploy_hash|
15
+ File.write(file_path, Manipulation.merge_hash(deploy_hash, env_obj.to_h).to_plain_yaml)
16
+ end
17
+ Manipulation.write_configs_encode_if_needed(env_obj.config_hsh, env_obj.secret_hsh, full_output_dir, configuration[:project_name])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,51 @@
1
+ module KY
2
+ class Configuration
3
+ AmbiguousEnvironmentFile = Class.new(StandardError)
4
+ attr_reader :configuration, :opts
5
+
6
+ def initialize(opts={})
7
+ @opts = opts
8
+ @configuration = build_configuration
9
+ end
10
+
11
+ def [](key)
12
+ configuration[key]
13
+ end
14
+
15
+ def keys
16
+ configuration.keys
17
+ end
18
+
19
+ def build_configuration
20
+ config = if config_file_location
21
+ YAML.load(File.read(config_file_location)).with_indifferent_access
22
+ else
23
+ DEFAULT_CONFIG
24
+ end
25
+ config.merge(current_environment_hash(config))
26
+ end
27
+
28
+ def current_environment_hash(partial_config)
29
+ current_config = partial_config || configuration
30
+ current_environment = opts[:environment] || current_config[:environment]
31
+ env_file_paths = environment_files(current_config).select {|file| file.match(current_environment) if current_environment }
32
+ if env_file_paths.count <= 1 # workaround for current possible env/path ambiguity
33
+ env_file_path = env_file_paths.first
34
+ else
35
+ raise AmbiguousEnvironmentFile.new("More than one file path matched the environment")
36
+ end
37
+ hsh = env_file_path ? YAML.load(File.read(env_file_path)).with_indifferent_access : {}
38
+ (hsh[:configuration] ? hsh[:configuration].merge(opts) : hsh.merge(opts)).with_indifferent_access
39
+ end
40
+
41
+ def environment_files(partial_config)
42
+ environments = (partial_config || configuration)[:environments].flat_map {|env| ["#{env}.yml", "#{env}.yaml"]}
43
+ (CONFIG_LOCATIONS * environments.count).zip(environments).map(&:join).select {|path| File.exist?(path) && !File.directory?(path) }
44
+ end
45
+
46
+ def config_file_location
47
+ (CONFIG_LOCATIONS * CONFIG_FILE_NAMES.count).zip(CONFIG_FILE_NAMES).map(&:join).find {|path| File.exist?(path) && !File.directory?(path) }
48
+ end
49
+
50
+ end
51
+ end
@@ -1,14 +1,13 @@
1
- class KY
1
+ module KY
2
2
  class DeployGeneration
3
- def initialize(instance, proc_path, full_output_dir, project_name=nil, current_namespace=nil)
4
- @instance = instance
5
- @proc_commands = File.read(proc_path).split("\n")
3
+ def initialize(full_output_dir, project_name, configuration=Configuration.new)
4
+ @configuration = configuration
5
+ @proc_commands = File.read(configuration[:procfile_path]).split("\n")
6
6
  .map {|line| line.split(':', 2) }
7
7
  .map {|k, v| [k, ["/bin/bash","-c", v]] }
8
8
  .to_h
9
9
  @full_output_dir = full_output_dir
10
- @project_name = project_name || instance.configuration[:project_name]
11
- @current_namespace = current_namespace || instance.configuration[:namespace]
10
+ @project_name = project_name || configuration[:project_name]
12
11
  @deployment_yaml = read_deployment_yaml
13
12
  end
14
13
 
@@ -25,11 +24,11 @@ class KY
25
24
  end
26
25
 
27
26
  private
28
- attr_reader :proc_commands, :full_output_dir, :project_name, :current_namespace, :deployment_yaml, :instance
27
+ attr_reader :proc_commands, :full_output_dir, :project_name, :deployment_yaml, :configuration
29
28
 
30
29
  def read_deployment_yaml
31
- if instance.configuration['deployment']
32
- File.read(instance.configuration['deployment'])
30
+ if configuration['deployment']
31
+ File.read(configuration['deployment'])
33
32
  else
34
33
  File.read(default_deployment_template)
35
34
  end
@@ -40,14 +39,19 @@ class KY
40
39
  end
41
40
 
42
41
  def template_hash(id, command_array)
43
- app_name = instance.configuration['app_name'] || "#{project_name}-#{id}"
44
- template_context = Template.context(app_name: app_name, id: id, command_array: command_array)
42
+ app_name = configuration['app_name'] || "#{project_name}-#{id}"
43
+ template_context = Template.new(configuration).context(app_name: app_name, id: id, command_array: command_array)
45
44
  tmp = Manipulation.merge_hash(
46
45
  YAML.load(
47
46
  ERB.new(deployment_yaml).result(template_context)
48
47
  ),
49
- instance.deploy_merge(id)
48
+ deploy_merge(id)
50
49
  )
51
50
  end
51
+
52
+ def deploy_merge(id)
53
+ return {} unless configuration[:merge]
54
+ configuration[:merge][id].to_h
55
+ end
52
56
  end
53
57
  end
@@ -1,7 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
3
  require 'securerandom'
4
- class KY
4
+ module KY
5
5
  class EnvGeneration
6
6
  ConflictingProjectError = Class.new(StandardError)
7
7
 
@@ -10,14 +10,24 @@ class KY
10
10
  define_method(raw_string.underscore) { raw_string }
11
11
  end
12
12
 
13
- def self.generate_env(instance, input1, input2)
14
- new(instance, input1, input2).to_h
13
+ def self.env(output, input1, input2)
14
+ output << generate_env(input1, input2).to_plain_yaml
15
+ rescue ConflictingProjectError => e
16
+ $stderr << "Error processing yml files, please provide a config and a secrets file from the same kubernetes project/name"
17
+ exit(1)
15
18
  end
16
19
 
17
- attr_reader :config_hsh, :secret_hsh, :instance
18
- def initialize(instance, input1, input2)
19
- input_hashes = YAML.load(input1.read), YAML.load(input2.read)
20
- @instance = instance
20
+ def self.generate_env(input1, input2)
21
+ new(input1, input2).to_h
22
+ end
23
+
24
+ attr_reader :config_hsh, :secret_hsh, :configuration
25
+ def initialize(input1, input2, configuration = Configuration.new)
26
+ input_hashes = YAML.load(input1.read).with_indifferent_access, YAML.load(input2.read).with_indifferent_access
27
+ @configuration = configuration
28
+ input_hashes.each do |env_hsh|
29
+ env_hsh[:metadata][:namespace] = configuration[:namespace]
30
+ end
21
31
  @config_hsh = input_hashes.find {|h| h[kind] == config_map }
22
32
  @secret_hsh = input_hashes.find {|h| h[kind] == secret }
23
33
  raise ConflictingProjectError.new("Config and Secret metadata names do not agree") unless secret_hsh[metadata][name] == project
@@ -34,7 +44,7 @@ class KY
34
44
  private
35
45
 
36
46
  def force_config
37
- return [] unless instance.configuration[:force_configmap_apply]
47
+ return [] unless configuration[:force_configmap_apply]
38
48
  [inline_env_map(config_map_key_ref, "force-configmap-apply", SecureRandom.hex)]
39
49
  end
40
50
 
@@ -47,12 +57,12 @@ class KY
47
57
  end
48
58
 
49
59
  def inline_config?
50
- instance.configuration[:inline_config]
60
+ configuration[:inline_config]
51
61
  end
52
62
 
53
63
 
54
64
  def inline_secret?
55
- instance.configuration[:inline_secret]
65
+ configuration[:inline_secret]
56
66
  end
57
67
 
58
68
  def inline_env_map(type, kebab_version, env_value)
@@ -1,10 +1,23 @@
1
1
  require 'deep_merge/rails_compat'
2
- class KY
2
+ module KY
3
3
  module Manipulation
4
4
  DEFAULT_DATA_KEY = 'data'
5
5
  MAGIC_DELIMITER = '@'
6
6
  BASE_64_DETECTION_REGEX = /^([A-Za-z0-9+]{4})*([A-Za-z0-9+]{4}|[A-Za-z0-9+]{3}=|[A-Za-z0-9+]{2}==)$/
7
7
  class << self
8
+
9
+ def decode(output, input)
10
+ output << code_yaml(input, :decode)
11
+ end
12
+
13
+ def encode(output, input)
14
+ output << code_yaml(input, :encode)
15
+ end
16
+
17
+ def merge(output, input1, input2)
18
+ output << merge_yaml(input1, input2)
19
+ end
20
+
8
21
  def merge_yaml(input1, input2)
9
22
  combined = {}
10
23
  YAML.load(input1.read).tap { |hsh|
data/lib/ky/template.rb CHANGED
@@ -1,19 +1,17 @@
1
- class KY
1
+ module KY
2
2
  class Template
3
- def self.context(hsh)
4
- new(hsh).context
5
- end
6
3
 
7
- attr_reader :context_hash
8
- def initialize(hsh)
9
- @context_hash = hsh
4
+ def initialize(configuration)
5
+ define_methods_from_config(configuration)
10
6
  end
11
7
 
12
- def environment
13
- KY.environment
8
+ def define_methods_from_config(config)
9
+ config.keys.each do |key|
10
+ define_singleton_method(key) { config[key] }
11
+ end
14
12
  end
15
13
 
16
- def context
14
+ def context(context_hash)
17
15
  template_context = binding
18
16
  context_hash.each do |var, value|
19
17
  template_context.local_variable_set(var, value)
data/lib/ky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- class KY
2
- VERSION = "0.4.0"
1
+ module KY
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/ky.rb CHANGED
@@ -3,6 +3,8 @@ require 'base64'
3
3
  require 'open-uri'
4
4
  require 'fileutils'
5
5
  require 'pathname'
6
+ require_relative 'ky/configuration'
7
+ require_relative 'ky/compilation'
6
8
  require_relative 'ky/manipulation'
7
9
  require_relative 'ky/env_generation'
8
10
  require_relative 'ky/template'
@@ -10,7 +12,7 @@ require_relative 'ky/deploy_generation'
10
12
  require_relative 'ky/hash'
11
13
 
12
14
 
13
- class KY
15
+ module KY
14
16
  CONFIG_FILE_NAMES = [".ky.yml", ".ky.yaml", "Lubefile"]
15
17
  CONFIG_LOCATIONS = ["#{Dir.pwd}/", "#{Dir.home}/"]
16
18
  DEFAULT_CONFIG = {
@@ -27,79 +29,4 @@ class KY
27
29
  force_configmap_apply: false
28
30
  }.with_indifferent_access
29
31
 
30
- attr_reader :opts, :configuration
31
-
32
- def initialize(opts={})
33
- @opts=opts
34
- @configuration = build_configuration
35
- define_methods_from_config(configuration)
36
- end
37
-
38
- def decode(output, input)
39
- output << Manipulation.code_yaml(input, :decode)
40
- end
41
-
42
- def encode(output, input)
43
- output << Manipulation.code_yaml(input, :encode)
44
- end
45
-
46
- def merge(output, input1, input2)
47
- output << Manipulation.merge_yaml(input1, input2)
48
- end
49
-
50
- def env(output, input1, input2)
51
- output << EnvGeneration.generate_env(self, input1, input2).to_plain_yaml
52
- rescue KY::EnvGeneration::ConflictingProjectError => e
53
- $stderr << "Error processing yml files, please provide a config and a secrets file from the same kubernetes project/name"
54
- exit(1)
55
- end
56
-
57
- def compile(proc_path, env1path, env2path, base_output_dir)
58
- full_output_dir = Pathname.new(base_output_dir).join(configuration[:environment].to_s).to_s
59
- FileUtils.mkdir_p(full_output_dir)
60
- env_obj = EnvGeneration.new(self, env1path, env2path)
61
- deploys_hash = DeployGeneration.new(self, proc_path, full_output_dir, env_obj.project, configuration[:namespace]).to_h
62
- deploys_hash.each do |file_path, deploy_hash|
63
- File.write(file_path, Manipulation.merge_hash(deploy_hash, env_obj.to_h).to_plain_yaml)
64
- end
65
- Manipulation.write_configs_encode_if_needed(env_obj.config_hsh, env_obj.secret_hsh, full_output_dir, configuration[:project_name])
66
- end
67
-
68
- def build_configuration
69
- config = if config_file_location
70
- YAML.load(File.read(config_file_location))
71
- else
72
- DEFAULT_CONFIG
73
- end.with_indifferent_access
74
- config.merge!(current_environment_hash(config))
75
- config
76
- end
77
-
78
- def deploy_merge(id)
79
- return {} unless configuration[:merge]
80
- configuration[:merge][id].to_h
81
- end
82
-
83
- def current_environment_hash(partial_config)
84
- current_config = partial_config || configuration
85
- env_file_path = environment_files(current_config).find {|file| file.match(opts[:environment] || current_config[:environment]) } if opts[:environment] || current_config[:environment] # ugh, this find is accident waiting to happen, REFACTOR/RETHINK!
86
- hsh = env_file_path ? YAML.load(File.read(env_file_path)).with_indifferent_access : {}
87
- (hsh[:configuration] ? hsh[:configuration].merge(opts) : hsh.merge(opts)).with_indifferent_access
88
- end
89
-
90
- def environment_files(partial_config)
91
- environments = (partial_config || configuration)[:environments].flat_map {|env| ["#{env}.yml", "#{env}.yaml"]}
92
- (CONFIG_LOCATIONS * environments.count).zip(environments).map(&:join).select {|path| File.exist?(path) && !File.directory?(path) }
93
- end
94
-
95
- def config_file_location
96
- (CONFIG_LOCATIONS * CONFIG_FILE_NAMES.count).zip(CONFIG_FILE_NAMES).map(&:join).find {|path| File.exist?(path) && !File.directory?(path) }
97
- end
98
-
99
- def define_methods_from_config(config)
100
- config.keys.each do |key|
101
- Template.send(:define_method, key) { config[key] }
102
- end
103
- end
104
-
105
32
  end
data/spec/ky_bin_spec.rb CHANGED
@@ -64,11 +64,14 @@ describe "ky cli" do
64
64
  describe "primary cli command generates and" do
65
65
  let(:instance) { KY.new }
66
66
  let(:fake_tag) { 'fake_tag' }
67
+ let(:fake_namespace) { 'fake_namespace' }
67
68
  let(:tmpdir) { 'spec/support/tmpdir' }
68
69
  after { `rm -r #{tmpdir}` }
69
70
  describe "compiles Procfile and env secrets/configs into entire deployments" do
70
71
  it "to directory" do
71
- KY::Cli.new.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
72
+ instance = KY::Cli.new
73
+ instance.options = {procfile_path: 'spec/support/Procfile'}
74
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
72
75
  expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
73
76
  expect(File.exists?("#{tmpdir}/worker.deployment.yml")).to be true
74
77
  expect(File.exists?("#{tmpdir}/jobs.deployment.yml")).to be true
@@ -78,7 +81,8 @@ describe "ky cli" do
78
81
  describe "encodes secrets.yml when compiling from Procfile without image_tag" do
79
82
  it "to directory" do
80
83
  instance = KY::Cli.new
81
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
84
+ instance.options = {procfile_path: 'spec/support/Procfile'}
85
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
82
86
  expect(File.exists?("#{tmpdir}/global.secret.yml")).to be true
83
87
  YAML.load(File.read("#{tmpdir}/global.secret.yml"))['data'].each do |_k, v|
84
88
  expect(v).to match(KY::Manipulation::BASE_64_DETECTION_REGEX)
@@ -89,8 +93,8 @@ describe "ky cli" do
89
93
  describe "encodes secrets.yml when compiling from Procfile with image_tag" do
90
94
  it "to directory" do
91
95
  instance = KY::Cli.new
92
- instance.options = {image_tag: fake_tag}
93
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
96
+ instance.options = {image_tag: fake_tag, procfile_path: 'spec/support/Procfile'}
97
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
94
98
  expect(File.exists?("#{tmpdir}/global.secret.yml")).to be true
95
99
  YAML.load(File.read("#{tmpdir}/global.secret.yml"))['data'].each do |_k, v|
96
100
  expect(v).to match(KY::Manipulation::BASE_64_DETECTION_REGEX)
@@ -101,8 +105,8 @@ describe "ky cli" do
101
105
  describe "uses image_tag when passed in as option" do
102
106
  it "to directory" do
103
107
  instance = KY::Cli.new
104
- instance.options = {image_tag: fake_tag}
105
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
108
+ instance.options = {image_tag: fake_tag, procfile_path: 'spec/support/Procfile'}
109
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
106
110
  expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
107
111
  expect(File.read("#{tmpdir}/web.deployment.yml")).to match(fake_tag)
108
112
  end
@@ -111,10 +115,10 @@ describe "ky cli" do
111
115
  describe "uses namespace when passed in as option" do
112
116
  it "to directory" do
113
117
  instance = KY::Cli.new
114
- instance.options = {namespace: fake_tag}
115
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
118
+ instance.options = {namespace: fake_namespace, procfile_path: 'spec/support/Procfile'}
119
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
116
120
  expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
117
- expect(File.read("#{tmpdir}/web.deployment.yml")).to match(fake_tag)
121
+ expect(File.read("#{tmpdir}/web.deployment.yml")).to match(fake_namespace)
118
122
  end
119
123
  end
120
124
 
@@ -123,7 +127,8 @@ describe "ky cli" do
123
127
  after { `rm Lubefile` }
124
128
  it "to directory" do
125
129
  instance = KY::Cli.new
126
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
130
+ instance.options = {procfile_path: 'spec/support/Procfile'}
131
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
127
132
  expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
128
133
  expect(File.exists?("#{tmpdir}/jobs.deployment.yml")).to be true
129
134
  expect(File.read("#{tmpdir}/web.deployment.yml")).to match('port')
@@ -136,7 +141,7 @@ describe "ky cli" do
136
141
  after { `rm Lubefile` }
137
142
  it "to directory" do
138
143
  instance = KY::Cli.new
139
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
144
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
140
145
  expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
141
146
  expect(File.read("#{tmpdir}/web.deployment.yml")).not_to match('HashWithIndifferentAccess')
142
147
  end
@@ -147,13 +152,33 @@ describe "ky cli" do
147
152
  after { `rm Lubefile` }
148
153
  it "to directory" do
149
154
  instance = KY::Cli.new
150
- instance.options = {force_configmap_apply: true}
151
- instance.compile('spec/support/Procfile', 'spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
155
+ instance.options = {procfile_path: 'spec/support/Procfile', force_configmap_apply: true}
156
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
152
157
  expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
153
158
  expect(File.read("#{tmpdir}/web.deployment.yml")).to match('FORCE_CONFIGMAP_APPLY')
154
159
  end
155
160
  end
156
161
 
162
+ describe "applies namespace to generated" do
163
+
164
+ before do
165
+ instance = KY::Cli.new
166
+ instance.options = {namespace: fake_namespace, procfile_path: 'spec/support/Procfile'}
167
+ instance.compile('spec/support/config.yml', 'spec/support/decoded.yml', tmpdir)
168
+ end
169
+
170
+ it "configmaps" do
171
+ expect(File.exists?("#{tmpdir}/global.configmap.yml")).to be true
172
+ expect(YAML.load(File.read("#{tmpdir}/global.configmap.yml"))['metadata']['namespace']).to match(fake_namespace)
173
+ end
174
+
175
+ it "deployments" do
176
+ expect(File.exists?("#{tmpdir}/web.deployment.yml")).to be true
177
+ expect(YAML.load(File.read("#{tmpdir}/web.deployment.yml"))['metadata']['namespace']).to match(fake_namespace)
178
+ end
179
+
180
+ end
181
+
157
182
  end
158
183
  end
159
184
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Glusman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: deep_merge
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +102,8 @@ files:
88
102
  - ky.gemspec
89
103
  - lib/ky.rb
90
104
  - lib/ky/cli.rb
105
+ - lib/ky/compilation.rb
106
+ - lib/ky/configuration.rb
91
107
  - lib/ky/deploy_generation.rb
92
108
  - lib/ky/env_generation.rb
93
109
  - lib/ky/hash.rb