kube-dsl 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Rakefile +28 -24
- data/lib/kube-dsl/builder.rb +33 -31
- data/lib/kube-dsl/dsl/pkg/version/info.rb +19 -1
- data/lib/kube-dsl/generator.rb +6 -6
- data/lib/kube-dsl/ref.rb +8 -5
- data/lib/kube-dsl/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03cadaa643bb90a6baa5338e3de7905f8243c0032fde7991db072ad7b964691c
|
4
|
+
data.tar.gz: 40feae243bcc6e2a953b1b97ae0bbd865b6239354e7abe47b471227b2dff582a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4c771dd4d07ee252b160c1ca4d0de23b913298974bf12f9374ac58ff05aa368a0962a458a9543cb959fea1e4a1596257b22a0b4571d88a0a6bf634f920d1210
|
7
|
+
data.tar.gz: 17ac1ab5ebea2c780623bc8d5bf7600b660b09d709c2a132bedb130477b9c61f8377ecf6f22cb9be8335778eb902f1736e5d0adf1d45fa4ad65a230c81be1bc9
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -16,6 +16,7 @@ end
|
|
16
16
|
|
17
17
|
task :generate do
|
18
18
|
require 'dry/inflector'
|
19
|
+
require 'fileutils'
|
19
20
|
|
20
21
|
FileUtils.rm_rf('./lib/kube-dsl/entrypoint.rb')
|
21
22
|
FileUtils.rm_rf('./lib/kube-dsl/dsl.rb')
|
@@ -24,33 +25,36 @@ task :generate do
|
|
24
25
|
FileUtils.mkdir_p('./vendor')
|
25
26
|
|
26
27
|
export_url = "https://github.com/instrumenta/kubernetes-json-schema/trunk/v#{KubeDSL::KUBERNETES_VERSION}-local"
|
27
|
-
|
28
|
+
local_schema_path = "vendor/kubernetes-json-schema/v#{KubeDSL::KUBERNETES_VERSION}-local"
|
28
29
|
|
29
|
-
unless File.exist?(
|
30
|
-
system("svn export #{export_url} #{
|
30
|
+
unless File.exist?(local_schema_path)
|
31
|
+
system("svn export #{export_url} #{local_schema_path}")
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
generator.generate_autoload_files
|
51
|
-
generator.generate_entrypoint_file do |resource, ns|
|
52
|
-
version = resource.ref.version || ''
|
53
|
-
!version.include?('beta') && !version.include?('alpha')
|
34
|
+
generator = KubeDSL::Generator.new(
|
35
|
+
schema_dir: local_schema_path,
|
36
|
+
output_dir: File.join('lib'),
|
37
|
+
autoload_prefix: File.join('kube-dsl', 'dsl'),
|
38
|
+
dsl_namespace: ['KubeDSL', 'DSL'],
|
39
|
+
entrypoint_namespace: ['KubeDSL'],
|
40
|
+
inflector: Dry::Inflector.new do |inflections|
|
41
|
+
inflections.acronym('DSL')
|
42
|
+
|
43
|
+
inflections.singular('tls', 'tls')
|
44
|
+
inflections.singular('causes', 'cause')
|
45
|
+
|
46
|
+
inflections.plural('tls', 'tlses')
|
47
|
+
inflections.plural('enum', 'enums')
|
48
|
+
inflections.plural('one_of', 'one_ofs')
|
49
|
+
inflections.plural('any_of', 'any_ofs')
|
50
|
+
inflections.plural('all_of', 'all_ofs')
|
54
51
|
end
|
52
|
+
)
|
53
|
+
|
54
|
+
generator.generate_resource_files
|
55
|
+
generator.generate_autoload_files
|
56
|
+
generator.generate_entrypoint_file do |resource, ns|
|
57
|
+
version = resource.ref.version || ''
|
58
|
+
!version.include?('beta') && !version.include?('alpha')
|
55
59
|
end
|
56
60
|
end
|
data/lib/kube-dsl/builder.rb
CHANGED
@@ -4,12 +4,17 @@ module KubeDSL
|
|
4
4
|
class Builder
|
5
5
|
include StringHelpers
|
6
6
|
|
7
|
-
attr_reader :schema_dir, :output_dir, :
|
7
|
+
attr_reader :schema_dir, :output_dir, :autoload_prefix
|
8
|
+
attr_reader :dsl_namespace, :entrypoint_namespace
|
9
|
+
attr_reader :inflector, :resolvers
|
8
10
|
|
9
|
-
def initialize(schema_dir:, output_dir:, inflector:)
|
11
|
+
def initialize(schema_dir:, output_dir:, autoload_prefix:, inflector:, dsl_namespace:, entrypoint_namespace:)
|
10
12
|
@schema_dir = schema_dir
|
11
13
|
@output_dir = output_dir
|
14
|
+
@autoload_prefix = autoload_prefix
|
12
15
|
@inflector = inflector
|
16
|
+
@dsl_namespace = dsl_namespace
|
17
|
+
@entrypoint_namespace = entrypoint_namespace
|
13
18
|
@resolvers ||= {}
|
14
19
|
end
|
15
20
|
|
@@ -19,25 +24,17 @@ module KubeDSL
|
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
|
-
def
|
27
|
+
def each_resource_file
|
23
28
|
return to_enum(__method__) unless block_given?
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
# schema, i.e. k8s resources like ObjectMeta that other
|
28
|
-
# k8s-compatible schemas depend on.
|
29
|
-
#
|
30
|
-
# Resources can be "empty" if they contain no properties. This
|
31
|
-
# usually happens for resources that are really just aliases
|
32
|
-
# for basic types like integer and string. The k8s' Duration
|
33
|
-
# object is a good example. It's just an alias for string.
|
34
|
-
yield res if !res.external? && !res.empty?
|
30
|
+
each_resource do |res|
|
31
|
+
yield File.join(output_dir, res.ref.ruby_autoload_path), res
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
def entrypoint(&block)
|
39
36
|
''.tap do |ruby_code|
|
40
|
-
ruby_code << "module #{
|
37
|
+
ruby_code << "module #{entrypoint_namespace.join('::')}::Entrypoint\n"
|
41
38
|
|
42
39
|
each_resource do |resource|
|
43
40
|
ns = resource.ref.ruby_namespace.join('::')
|
@@ -53,26 +50,15 @@ module KubeDSL
|
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
|
-
def namespace
|
57
|
-
@namespace ||= inflector.classify(
|
58
|
-
File
|
59
|
-
.split(output_dir)
|
60
|
-
.map { |seg| inflector.camelize(underscore(seg)) }
|
61
|
-
.join('/')
|
62
|
-
).split('::')
|
63
|
-
end
|
64
|
-
|
65
53
|
def entrypoint_path
|
66
|
-
File.join(File.dirname(
|
54
|
+
File.join(output_dir, File.dirname(autoload_prefix), 'entrypoint.rb')
|
67
55
|
end
|
68
56
|
|
69
57
|
def each_autoload_file(&block)
|
70
58
|
return to_enum(__method__) unless block
|
71
59
|
|
72
|
-
start = output_dir.split(File::SEPARATOR).first
|
73
|
-
|
74
60
|
each_autoload_file_helper(
|
75
|
-
autoload_map[
|
61
|
+
autoload_map[:root], [], &block
|
76
62
|
)
|
77
63
|
end
|
78
64
|
|
@@ -88,11 +74,27 @@ module KubeDSL
|
|
88
74
|
end
|
89
75
|
|
90
76
|
def parse_ref(ref_str)
|
91
|
-
Ref.new(ref_str,
|
77
|
+
Ref.new(ref_str, dsl_namespace, inflector, schema_dir, autoload_prefix)
|
92
78
|
end
|
93
79
|
|
94
80
|
private
|
95
81
|
|
82
|
+
def each_resource
|
83
|
+
return to_enum(__method__) unless block_given?
|
84
|
+
|
85
|
+
resources.each do |res|
|
86
|
+
# "External" resources are ones that live outside the current
|
87
|
+
# schema, i.e. k8s resources like ObjectMeta that other
|
88
|
+
# k8s-compatible schemas depend on.
|
89
|
+
#
|
90
|
+
# Resources can be "empty" if they contain no properties. This
|
91
|
+
# usually happens for resources that are really just aliases
|
92
|
+
# for basic types like integer and string. The k8s' Duration
|
93
|
+
# object is a good example. It's just an alias for string.
|
94
|
+
yield res if !res.external? && !res.empty?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
96
98
|
def resources
|
97
99
|
JSON.parse(File.read(start_path))['oneOf'].map do |entry|
|
98
100
|
resource_from_ref(resolve_ref(entry['$ref']))
|
@@ -105,7 +107,7 @@ module KubeDSL
|
|
105
107
|
parts = res.ref.ruby_autoload_path.split(File::SEPARATOR)
|
106
108
|
parts.reject!(&:empty?)
|
107
109
|
|
108
|
-
parts.inject(amap) do |ret, seg|
|
110
|
+
[:root, *parts].inject(amap) do |ret, seg|
|
109
111
|
if seg.end_with?('.rb')
|
110
112
|
ret[seg] = res
|
111
113
|
else
|
@@ -137,7 +139,7 @@ module KubeDSL
|
|
137
139
|
end
|
138
140
|
|
139
141
|
ruby_code << "end\n"
|
140
|
-
yield File.join(*path, "#{ns}.rb"), ruby_code
|
142
|
+
yield File.join(output_dir, *path, "#{ns}.rb"), ruby_code
|
141
143
|
each_autoload_file_helper(children, path + [ns], &block)
|
142
144
|
end
|
143
145
|
end
|
@@ -216,7 +218,7 @@ module KubeDSL
|
|
216
218
|
end
|
217
219
|
|
218
220
|
def start_path
|
219
|
-
@
|
221
|
+
@start_path ||= File.join(schema_dir, 'all.json')
|
220
222
|
end
|
221
223
|
|
222
224
|
def resource_cache
|
@@ -1,6 +1,24 @@
|
|
1
1
|
module KubeDSL::DSL::Pkg::Version
|
2
2
|
class Info < ::KubeDSL::DSLObject
|
3
|
-
|
3
|
+
value_field :build_date
|
4
|
+
value_field :compiler
|
5
|
+
value_field :git_commit
|
6
|
+
value_field :git_tree_state
|
7
|
+
value_field :git_version
|
8
|
+
value_field :go_version
|
9
|
+
value_field :major
|
10
|
+
value_field :minor
|
11
|
+
value_field :platform
|
12
|
+
|
13
|
+
validates :build_date, field: { format: :string }, presence: false
|
14
|
+
validates :compiler, field: { format: :string }, presence: false
|
15
|
+
validates :git_commit, field: { format: :string }, presence: false
|
16
|
+
validates :git_tree_state, field: { format: :string }, presence: false
|
17
|
+
validates :git_version, field: { format: :string }, presence: false
|
18
|
+
validates :go_version, field: { format: :string }, presence: false
|
19
|
+
validates :major, field: { format: :string }, presence: false
|
20
|
+
validates :minor, field: { format: :string }, presence: false
|
21
|
+
validates :platform, field: { format: :string }, presence: false
|
4
22
|
|
5
23
|
def serialize
|
6
24
|
{}.tap do |result|
|
data/lib/kube-dsl/generator.rb
CHANGED
@@ -13,14 +13,14 @@ module KubeDSL
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def generate_resource_files
|
16
|
-
builder.
|
17
|
-
FileUtils.mkdir_p(File.dirname(
|
16
|
+
builder.each_resource_file do |path, res|
|
17
|
+
FileUtils.mkdir_p(File.dirname(path))
|
18
18
|
|
19
|
-
if File.exist?(
|
20
|
-
puts "Skipping #{
|
19
|
+
if File.exist?(path)
|
20
|
+
puts "Skipping #{path} because it already exists"
|
21
21
|
else
|
22
|
-
puts "Writing #{
|
23
|
-
File.write(
|
22
|
+
puts "Writing #{path}"
|
23
|
+
File.write(path, res.to_ruby)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/kube-dsl/ref.rb
CHANGED
@@ -5,12 +5,12 @@ module KubeDSL
|
|
5
5
|
attr_reader :str, :kind, :namespace, :version, :inflector, :schema_dir
|
6
6
|
attr_reader :ruby_namespace_prefix, :autoload_prefix
|
7
7
|
|
8
|
-
def initialize(str, ruby_namespace_prefix,
|
8
|
+
def initialize(str, ruby_namespace_prefix, inflector, schema_dir, autoload_prefix)
|
9
9
|
@str = str
|
10
10
|
@ruby_namespace_prefix = ruby_namespace_prefix
|
11
|
-
@autoload_prefix = autoload_prefix
|
12
11
|
@inflector = inflector
|
13
12
|
@schema_dir = schema_dir
|
13
|
+
@autoload_prefix = autoload_prefix
|
14
14
|
|
15
15
|
ns, v, k = str.split('.').last(3)
|
16
16
|
|
@@ -41,15 +41,18 @@ module KubeDSL
|
|
41
41
|
def ruby_namespace
|
42
42
|
@ruby_namespace ||= begin
|
43
43
|
[*ruby_namespace_prefix].tap do |mods|
|
44
|
-
mods <<
|
45
|
-
mods <<
|
44
|
+
mods << namespace if namespace
|
45
|
+
mods << version if version
|
46
|
+
mods.map! do |m|
|
47
|
+
inflector.camelize(underscore(m))
|
48
|
+
end
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
53
|
def ruby_autoload_path
|
51
54
|
@ruby_autoload_path ||= File.join(
|
52
|
-
[
|
55
|
+
[autoload_prefix].tap do |path|
|
53
56
|
path << underscore(namespace) if namespace
|
54
57
|
path << underscore(version) if version
|
55
58
|
path << "#{underscore(kind)}.rb"
|
data/lib/kube-dsl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kube-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|
@@ -803,7 +803,7 @@ files:
|
|
803
803
|
homepage: http://github.com/getkuby/kube-dsl
|
804
804
|
licenses: []
|
805
805
|
metadata: {}
|
806
|
-
post_install_message:
|
806
|
+
post_install_message:
|
807
807
|
rdoc_options: []
|
808
808
|
require_paths:
|
809
809
|
- lib
|
@@ -818,8 +818,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
818
818
|
- !ruby/object:Gem::Version
|
819
819
|
version: '0'
|
820
820
|
requirements: []
|
821
|
-
rubygems_version: 3.1.
|
822
|
-
signing_key:
|
821
|
+
rubygems_version: 3.1.6
|
822
|
+
signing_key:
|
823
823
|
specification_version: 4
|
824
824
|
summary: A Ruby DSL for defining Kubernetes resources.
|
825
825
|
test_files: []
|