kubes 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26abdb16aa89e6a5c34aefee8430ee36e7444bb387b2bd85c4327d6f07afc038
4
- data.tar.gz: 8513c5be9f224cf0081f70197390f5d55eda823c2d1b46d1c1f81d82d9e44460
3
+ metadata.gz: 9bfe400824a8ee2877643cba9abfbd10a5e57b058e88977313457836a490c7f0
4
+ data.tar.gz: 98bff5118293f84161ed5b10b9d0162df5181b75a6dbc09dc88ed2ecd5e7029e
5
5
  SHA512:
6
- metadata.gz: 972853cd07d7a56344f8575c4c977f60cb72156a434b0589c99b311e3383f9ed30d218baf3caff7b83ee33881ae45eda496beb13935fae86c4b707bcf342de95
7
- data.tar.gz: 7ada5c671ac68171034c83c56f0c535f0e33ca27aa63da9b8d96215670e7541416d4714d7151496f87cea17acc781c40ea62986d390456f7475e394f226871c6
6
+ metadata.gz: 0f3a2a36e27e2c64d5821f429368bd515c259045a26d24b8ee16713a356f53d6370938a2748bf1e65f95779936ea654547117f49bef8da2c0b435461f5456099
7
+ data.tar.gz: 9e603c401b2e9a56fc38cd1aec28d3ceaf9ff821d5add2b22bf9d8d2e5d209d7ab5609b9ab0116bd1189d5594a0e6ee00a071984605b235408ac6a0fffbeee1b
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.4.4]
7
+ - #30 friendly message for rendered erb yaml and dsl errors
8
+ - fix backtrace_reject pattern
9
+
6
10
  ## [0.4.3]
7
11
  - #29 fix edge case when user provides hook on option for non-kubectl hooks
8
12
 
@@ -27,7 +27,7 @@ To explain the layering, here's the general processing order that Kubes takes.
27
27
 
28
28
  Note, both YAML and DSL forms support layering.
29
29
 
30
- Layering only combines resources definitions with the same form. For example, `base/all.rb` will not be combined with `web/deployment.yaml`.
30
+ Layering only combines resources definitions with the same form. For example, the DSL form `base/all.rb` will not be combined with YAML form `web/deployment.yaml`.
31
31
 
32
32
  ## Full Layering
33
33
 
@@ -17,7 +17,7 @@ require "yaml"
17
17
  # core helper libraries
18
18
  require "kubes_google"
19
19
 
20
- DslEvaluator.backtrace_reject = ".kubes"
20
+ DslEvaluator.backtrace_reject = "lib/kubes"
21
21
 
22
22
  require "kubes/autoloader"
23
23
  Kubes::Autoloader.setup
@@ -1,13 +1,12 @@
1
1
  class Kubes::Compiler::Strategy
2
2
  class Base
3
3
  include Kubes::Logging
4
+ include Kubes::Compiler::Util::SaveFile
4
5
 
5
6
  def initialize(options={})
6
7
  @options = options
7
8
  @path = options[:path]
8
-
9
- @filename = @path.sub(%r{.*\.kubes/resources/},'') # IE: web/deployment.rb or web/deployment.yaml
10
- @save_file = @filename.sub('.yml','.yaml').sub('.rb','.yaml')
9
+ @save_file = save_file(@path)
11
10
  end
12
11
  end
13
12
  end
@@ -17,7 +17,7 @@ class Kubes::Compiler::Strategy
17
17
  end
18
18
 
19
19
  def syntax_class
20
- klass_name = normalize_kind(@filename)
20
+ klass_name = normalize_kind(@save_file)
21
21
  "Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
22
22
  rescue NameError
23
23
  logger.debug "Using default resource for: #{klass_name}"
@@ -25,7 +25,7 @@ class Kubes::Compiler::Strategy
25
25
  end
26
26
 
27
27
  def block_form?
28
- type = extract_type(@filename)
28
+ type = extract_type(@save_file)
29
29
  type.pluralize == type
30
30
  end
31
31
  end
@@ -32,11 +32,18 @@ class Kubes::Compiler::Strategy
32
32
  def render_result(path)
33
33
  if File.exist?(path)
34
34
  yaml = RenderMePretty.result(path, context: self)
35
- result = YAML.load(yaml)
35
+ result = yaml_load(path, yaml)
36
36
  result.is_a?(Hash) ? result : {} # in case of blank yaml doc a Boolean false is returned
37
37
  else
38
38
  {}
39
39
  end
40
40
  end
41
+
42
+ def yaml_load(path, yaml)
43
+ YAML.load(yaml)
44
+ rescue Psych::SyntaxError
45
+ YamlError.new(path, yaml).show
46
+ exit 1
47
+ end
41
48
  end
42
49
  end
@@ -0,0 +1,60 @@
1
+ class Kubes::Compiler::Strategy::Erb
2
+ class YamlError
3
+ include Kubes::Compiler::Util::SaveFile
4
+
5
+ def initialize(path, rendered_yaml)
6
+ @path, @rendered_yaml = path, rendered_yaml
7
+ end
8
+
9
+ def show
10
+ FileUtils.mkdir_p(File.dirname(dest))
11
+ IO.write(dest, @rendered_yaml)
12
+ show_error(dest)
13
+ end
14
+
15
+ def dest
16
+ save_file = save_file(@path)
17
+ "#{Kubes.root}/.kubes/output/#{save_file}"
18
+ end
19
+
20
+ def show_error(path)
21
+ text = IO.read(path)
22
+ begin
23
+ YAML.load(text)
24
+ rescue Psych::SyntaxError => e
25
+ handle_yaml_syntax_error(e, path)
26
+ end
27
+ end
28
+
29
+ def handle_yaml_syntax_error(e, path)
30
+ io = StringIO.new
31
+ io.puts "Invalid yaml. Output written for debugging: #{path}".color(:red)
32
+ io.puts "ERROR: #{e.message}".color(:red)
33
+
34
+ # Grab line info. Example error:
35
+ # ERROR: (<unknown>): could not find expected ':' while scanning a simple key at line 2 column 1
36
+ md = e.message.match(/at line (\d+) column (\d+)/)
37
+ line = md[1].to_i
38
+
39
+ lines = IO.read(path).split("\n")
40
+ context = 5 # lines of context
41
+ top, bottom = [line-context-1, 0].max, line+context-1
42
+ spacing = lines.size.to_s.size
43
+ lines[top..bottom].each_with_index do |line_content, index|
44
+ line_number = top+index+1
45
+ if line_number == line
46
+ io.printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
47
+ else
48
+ io.printf("%#{spacing}d %s\n", line_number, line_content)
49
+ end
50
+ end
51
+
52
+ if ENV['KUBES_TEST']
53
+ io.string
54
+ else
55
+ puts io.string
56
+ exit 1
57
+ end
58
+ end
59
+ end
60
+ end
@@ -5,7 +5,7 @@ module Kubes::Compiler::Util
5
5
  end
6
6
 
7
7
  def extract_type(path)
8
- File.basename(path).sub('.rb','').sub(/-.*/,'')
8
+ File.basename(path).sub('.yaml','').sub('.yml','').sub('.rb','').sub(/-.*/,'')
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,8 @@
1
+ module Kubes::Compiler::Util
2
+ module SaveFile
3
+ def save_file(path)
4
+ filename = path.sub(%r{.*\.kubes/resources/},'') # IE: web/deployment.rb or web/deployment.yaml
5
+ filename.sub('.yml','.yaml').sub('.rb','.yaml')
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Kubes
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-17 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -540,9 +540,11 @@ files:
540
540
  - lib/kubes/compiler/strategy/base.rb
541
541
  - lib/kubes/compiler/strategy/dsl.rb
542
542
  - lib/kubes/compiler/strategy/erb.rb
543
+ - lib/kubes/compiler/strategy/erb/yaml_error.rb
543
544
  - lib/kubes/compiler/strategy/pass.rb
544
545
  - lib/kubes/compiler/strategy/result.rb
545
546
  - lib/kubes/compiler/util/normalize.rb
547
+ - lib/kubes/compiler/util/save_file.rb
546
548
  - lib/kubes/compiler/util/yaml_dump.rb
547
549
  - lib/kubes/completer.rb
548
550
  - lib/kubes/completer/script.rb