kustomizer 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/kustomize/builtin_plugins/kustomizer.covalenthq.com/v1/test_generator.rb +15 -0
- data/lib/kustomize/builtin_plugins/kustomizer.covalenthq.com/v1/test_transformer.rb +15 -0
- data/lib/kustomize/emitter.rb +4 -0
- data/lib/kustomize/emitter/document_emitter/kustomization_document_emitter.rb +40 -14
- data/lib/kustomize/emitter/generator_plugins_emitter.rb +26 -0
- data/lib/kustomize/generator_plugin.rb +16 -0
- data/lib/kustomize/plugin.rb +30 -5
- data/lib/kustomize/plugin_manager.rb +31 -16
- data/lib/kustomize/plugin_registry.rb +39 -0
- data/lib/kustomize/session.rb +10 -7
- data/lib/kustomize/transform.rb +9 -1
- data/lib/kustomize/transform/fingerprint_suffix_transform.rb +57 -0
- data/lib/kustomize/transform/image_transform.rb +1 -1
- data/lib/kustomize/transform/json_6902_patch_transform.rb +1 -1
- data/lib/kustomize/transform/namespace_transform.rb +1 -1
- data/lib/kustomize/transform/purge_internal_annotations_transform.rb +31 -0
- data/lib/kustomize/transform/ref_fixup_transform.rb +55 -0
- data/lib/kustomize/transform/transformer_plugins_transform.rb +28 -0
- data/lib/kustomize/transformer_plugin.rb +16 -0
- data/lib/kustomize/version.rb +1 -1
- metadata +12 -4
- data/lib/kustomize/emitter/plugin_emitter.rb +0 -30
- data/lib/kustomize/transform/name_digest_autosuffix_transform.rb +0 -83
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68396a12fb43e0ef4405296a562b431f8e4c45403b00b11043899045c2637729
|
4
|
+
data.tar.gz: 48ee78953be0b1876e3176b8b7ddf1eb0f064dfc7ca29f24d3a23fb747ff521f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87a0e6cc3c175393548e44b120a6d14a65aa894589b0551fbc56bb550b04e3fdd77902c86b6523abc7187f9a6af3f629ec4a1b69367413b9b61b5516ff7d0d42
|
7
|
+
data.tar.gz: 38323824b787ff945a22c46b2630db09af3ea667d83fce738ef96e0723b6445f6451f90b8b9205583f8c12651be76e9d8cb7df31b7be1baef054da513e5175cb
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kustomizer (0.1.
|
4
|
+
kustomizer (0.1.2)
|
5
5
|
accessory (~> 0.1.9)
|
6
6
|
base32-multi
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
accessory (0.1.
|
11
|
+
accessory (0.1.10)
|
12
12
|
base32-multi (0.1.1)
|
13
13
|
diff-lcs (1.4.4)
|
14
14
|
rake (13.0.3)
|
@@ -35,4 +35,4 @@ DEPENDENCIES
|
|
35
35
|
rspec (~> 3.0)
|
36
36
|
|
37
37
|
BUNDLED WITH
|
38
|
-
2.2.
|
38
|
+
2.2.6
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'kustomize/generator_plugin'
|
2
|
+
|
3
|
+
module CovalentKustomizer; end
|
4
|
+
|
5
|
+
class CovalentKustomizer::TestGenerator < Kustomize::GeneratorPlugin
|
6
|
+
match_on api_version: 'kustomizer.covalenthq.com/v1'
|
7
|
+
|
8
|
+
def initialize(rc)
|
9
|
+
@docs = rc['emit'] || []
|
10
|
+
end
|
11
|
+
|
12
|
+
def emit
|
13
|
+
@docs
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'kustomize/transformer_plugin'
|
2
|
+
|
3
|
+
module CovalentKustomizer; end
|
4
|
+
|
5
|
+
class CovalentKustomizer::TestTransformer < Kustomize::TransformerPlugin
|
6
|
+
match_on api_version: 'kustomizer.covalenthq.com/v1'
|
7
|
+
|
8
|
+
def initialize(rc)
|
9
|
+
@insertions = rc['insert'] || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def rewrite(rc)
|
13
|
+
rc.merge(@insertions)
|
14
|
+
end
|
15
|
+
end
|
data/lib/kustomize/emitter.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'kustomize/emitter/document_emitter'
|
2
2
|
require 'kustomize/emitter/file_emitter'
|
3
3
|
require 'kustomize/emitter/directory_emitter'
|
4
|
-
require 'kustomize/emitter/
|
4
|
+
require 'kustomize/emitter/generator_plugins_emitter'
|
5
5
|
|
6
6
|
require 'kustomize/transform/json_6902_patch_transform'
|
7
7
|
require 'kustomize/transform/image_transform'
|
8
8
|
require 'kustomize/transform/namespace_transform'
|
9
|
-
require 'kustomize/transform/
|
9
|
+
require 'kustomize/transform/fingerprint_suffix_transform'
|
10
|
+
require 'kustomize/transform/ref_fixup_transform'
|
11
|
+
require 'kustomize/transform/purge_internal_annotations_transform'
|
12
|
+
require 'kustomize/transform/transformer_plugins_transform'
|
10
13
|
|
11
14
|
class Kustomize::Emitter::DocumentEmitter::KustomizationDocumentEmitter < Kustomize::Emitter::DocumentEmitter
|
12
15
|
def source_directory
|
@@ -20,18 +23,24 @@ class Kustomize::Emitter::DocumentEmitter::KustomizationDocumentEmitter < Kustom
|
|
20
23
|
(@doc['bases'] || []) +
|
21
24
|
(@doc['resources'] || [])
|
22
25
|
|
23
|
-
|
26
|
+
gen_plugin_pathspecs =
|
24
27
|
(@doc['generators'] || [])
|
25
28
|
|
26
29
|
input_emitters = rc_pathspecs.map do |rel_path|
|
27
30
|
build_input_emitter(rel_path)
|
28
31
|
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
gen_plugin_rc_emitters = gen_plugin_pathspecs.map do |rel_path|
|
34
|
+
build_input_emitter(rel_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
unless gen_plugin_rc_emitters.empty?
|
38
|
+
gen_plugins_emitter = Kustomize::Emitter::GeneratorPluginsEmitter.new(
|
39
|
+
gen_plugin_rc_emitters,
|
33
40
|
session: @session
|
34
41
|
)
|
42
|
+
|
43
|
+
input_emitters.push(gen_plugins_emitter)
|
35
44
|
end
|
36
45
|
|
37
46
|
@input_emitters = input_emitters
|
@@ -66,6 +75,24 @@ class Kustomize::Emitter::DocumentEmitter::KustomizationDocumentEmitter < Kustom
|
|
66
75
|
end
|
67
76
|
end
|
68
77
|
|
78
|
+
def transformer_plugin_transforms
|
79
|
+
xformer_plugin_rc_emitters =
|
80
|
+
(@doc['transformers'] || []).map do |rel_path|
|
81
|
+
build_input_emitter(rel_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
if xformer_plugin_rc_emitters.length > 0
|
85
|
+
xform = Kustomize::Transform::TransformerPluginsTransform.create(
|
86
|
+
xformer_plugin_rc_emitters,
|
87
|
+
session: @session
|
88
|
+
)
|
89
|
+
|
90
|
+
[xform]
|
91
|
+
else
|
92
|
+
[]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
69
96
|
def namespace_transforms
|
70
97
|
if new_ns = @doc['namespace']
|
71
98
|
[Kustomize::Transform::NamespaceTransform.create(new_ns)]
|
@@ -74,24 +101,23 @@ class Kustomize::Emitter::DocumentEmitter::KustomizationDocumentEmitter < Kustom
|
|
74
101
|
end
|
75
102
|
end
|
76
103
|
|
77
|
-
def name_digest_autosuffix_transforms
|
78
|
-
[Kustomize::Transform::NameDigestAutosuffixTransform.create(self)]
|
79
|
-
end
|
80
|
-
|
81
104
|
def transforms
|
82
105
|
return @transforms if @transforms
|
83
106
|
|
84
107
|
@transforms = [
|
85
108
|
self.namespace_transforms,
|
86
109
|
self.image_transforms,
|
87
|
-
|
88
|
-
self.json_6902_patch_transforms
|
110
|
+
Kustomize::Transform::FingerprintSuffixTransform.instance,
|
111
|
+
self.json_6902_patch_transforms,
|
112
|
+
self.transformer_plugin_transforms,
|
113
|
+
Kustomize::Transform::RefFixupTransform.instance,
|
114
|
+
Kustomize::Transform::PurgeInternalAnnotationsTransform.instance
|
89
115
|
].flatten
|
90
116
|
end
|
91
117
|
|
92
118
|
def emit
|
93
|
-
self.input_resources
|
94
|
-
|
119
|
+
self.transforms.inject(self.input_resources) do |rcs, xform|
|
120
|
+
xform.rewrite_all(rcs)
|
95
121
|
end
|
96
122
|
end
|
97
123
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'kustomize/emitter'
|
2
|
+
|
3
|
+
class Kustomize::Emitter::GeneratorPluginsEmitter < Kustomize::Emitter
|
4
|
+
def initialize(plugin_rc_emitters, session:)
|
5
|
+
@session = session
|
6
|
+
@plugin_rc_emitters = plugin_rc_emitters
|
7
|
+
end
|
8
|
+
|
9
|
+
def plugin_rcs
|
10
|
+
@plugin_rc_emitters.flat_map(&:emit)
|
11
|
+
end
|
12
|
+
|
13
|
+
def plugin_instances
|
14
|
+
return @plugin_instances if @plugin_instances
|
15
|
+
|
16
|
+
@plugin_instances =
|
17
|
+
self.plugin_rcs.map do |rc|
|
18
|
+
plugin_klass = @session.plugin_manager.get(api_version: rc['apiVersion'], kind: rc['kind'])
|
19
|
+
plugin_klass.create(rc, session: @session)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def emit
|
24
|
+
self.plugin_instances.flat_map(&:emit)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'kustomize/plugin'
|
2
|
+
|
3
|
+
class Kustomize::GeneratorPlugin < Kustomize::Plugin
|
4
|
+
def self.inherited(subklass)
|
5
|
+
reg = Kustomize::PluginRegistry.instance
|
6
|
+
reg.probe_queue.push(subklass)
|
7
|
+
end
|
8
|
+
|
9
|
+
def emit
|
10
|
+
[]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_yaml_stream
|
14
|
+
self.emit.map(&:to_yaml).join("")
|
15
|
+
end
|
16
|
+
end
|
data/lib/kustomize/plugin.rb
CHANGED
@@ -1,11 +1,36 @@
|
|
1
|
-
|
1
|
+
require 'pathname'
|
2
2
|
|
3
3
|
class Kustomize::Plugin
|
4
|
-
def
|
5
|
-
|
4
|
+
def self.create(rc, session:)
|
5
|
+
inst = new(rc)
|
6
|
+
inst.session = session
|
7
|
+
inst
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
class << self
|
11
|
+
private :new
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :session
|
15
|
+
|
16
|
+
def self.match_on(kind: nil, api_version: nil)
|
17
|
+
if kind
|
18
|
+
@kustomize_plugin_match_kind = kind
|
19
|
+
end
|
20
|
+
|
21
|
+
if api_version
|
22
|
+
@kustomize_plugin_match_api_version = api_version
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.kustomize_plugin_match_kind
|
27
|
+
return @kustomize_plugin_match_kind if @kustomize_plugin_match_kind
|
28
|
+
self.name.split('::').last
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.kustomize_plugin_match_api_version
|
32
|
+
return @kustomize_plugin_match_api_version if @kustomize_plugin_match_api_version
|
33
|
+
api_dir = Pathname.new(__FILE__).parent
|
34
|
+
api_dir.relative_path_from(api_dir.parent.parent).to_s
|
10
35
|
end
|
11
36
|
end
|
@@ -1,31 +1,46 @@
|
|
1
|
-
require '
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
require 'kustomize/plugin_registry'
|
2
4
|
|
3
5
|
class Kustomize::PluginManager
|
4
6
|
def initialize(session:)
|
5
7
|
@session = session
|
6
|
-
@
|
8
|
+
@registry = Kustomize::PluginRegistry.instance
|
7
9
|
end
|
8
10
|
|
9
|
-
def get(api_version
|
10
|
-
|
11
|
-
|
12
|
-
return cached_inst if cached_inst
|
11
|
+
def get(api_version:, kind:)
|
12
|
+
plugin_klass = @registry.get(api_version: api_version, kind: kind)
|
13
|
+
return plugin_klass if plugin_klass
|
13
14
|
|
14
|
-
|
15
|
+
try_loading(api_version, kind)
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
private
|
19
|
+
def try_loading(api_version, kind)
|
20
|
+
rel_load_path = Pathname.new(api_version) / "#{underscore(kind)}.rb"
|
20
21
|
|
21
|
-
|
22
|
-
@session.
|
23
|
-
.map{ |prefix| prefix /
|
22
|
+
abs_load_path =
|
23
|
+
@session.effective_load_paths
|
24
|
+
.map{ |prefix| prefix / rel_load_path }
|
24
25
|
.find{ |f| f.file? }
|
25
26
|
|
26
|
-
raise
|
27
|
+
raise LoadError, "could not find kustomize plugin to load" unless abs_load_path
|
28
|
+
|
29
|
+
Kernel.require(abs_load_path)
|
30
|
+
|
31
|
+
plugin_klass = @registry.get(api_version: api_version, kind: kind)
|
32
|
+
|
33
|
+
raise LoadError, "#{abs_load_path} did not define expected plugin" unless plugin_klass
|
34
|
+
|
35
|
+
plugin_klass
|
36
|
+
end
|
27
37
|
|
28
|
-
|
29
|
-
|
38
|
+
private
|
39
|
+
def underscore(str)
|
40
|
+
str
|
41
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
42
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
43
|
+
.tr("-", "_")
|
44
|
+
.downcase
|
30
45
|
end
|
31
46
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Kustomize; end
|
4
|
+
|
5
|
+
class Kustomize::PluginRegistry
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@klasses = {}
|
10
|
+
@probe_queue = []
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :probe_queue
|
14
|
+
|
15
|
+
def get(api_version:, kind:)
|
16
|
+
drain_probe_queue!
|
17
|
+
|
18
|
+
rc_target_id = make_rc_target_id(api_version, kind)
|
19
|
+
@klasses[rc_target_id]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def drain_probe_queue!
|
24
|
+
return if @probe_queue.empty?
|
25
|
+
|
26
|
+
while plugin_klass = @probe_queue.shift
|
27
|
+
rc_target_id = make_rc_target_id(
|
28
|
+
plugin_klass.kustomize_plugin_match_api_version,
|
29
|
+
plugin_klass.kustomize_plugin_match_kind
|
30
|
+
)
|
31
|
+
@klasses[rc_target_id] = plugin_klass
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def make_rc_target_id(api_version, kind)
|
37
|
+
[api_version, kind].join('/').to_s.intern
|
38
|
+
end
|
39
|
+
end
|
data/lib/kustomize/session.rb
CHANGED
@@ -3,15 +3,18 @@ module Kustomize; end
|
|
3
3
|
require 'kustomize/plugin_manager'
|
4
4
|
|
5
5
|
class Kustomize::Session
|
6
|
-
def
|
7
|
-
|
6
|
+
def initialize(load_paths: [])
|
7
|
+
@load_paths = load_paths
|
8
8
|
@plugin_manager = Kustomize::PluginManager.new(session: self)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
attr_reader :plugin_manager
|
12
|
+
|
13
|
+
def builtin_load_paths
|
14
|
+
[Pathname.new(__FILE__).expand_path.parent / 'builtin_plugins']
|
15
|
+
end
|
16
|
+
|
17
|
+
def effective_load_paths
|
18
|
+
@load_paths + self.builtin_load_paths
|
16
19
|
end
|
17
20
|
end
|
data/lib/kustomize/transform.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'digest'
|
3
|
+
require 'set'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
require 'accessory'
|
7
|
+
require 'digest/base32'
|
8
|
+
|
9
|
+
require 'kustomize/transform'
|
10
|
+
|
11
|
+
class Kustomize::Transform::FingerprintSuffixTransform < Kustomize::Transform
|
12
|
+
include Accessory
|
13
|
+
include Singleton
|
14
|
+
|
15
|
+
SUFFIX_JOINER = "-"
|
16
|
+
|
17
|
+
APPLICABLE_KINDS = Set[
|
18
|
+
'Secret',
|
19
|
+
'SealedSecret',
|
20
|
+
'ConfigMap'
|
21
|
+
]
|
22
|
+
|
23
|
+
NAME_LENS = Lens["metadata", "name"]
|
24
|
+
|
25
|
+
CONTENT_LENS_BY_KIND = {
|
26
|
+
"Secret" => Lens["data"],
|
27
|
+
"ConfigMap" => Lens["data"],
|
28
|
+
"SealedSecret" => Lens["spec", "encryptedData"]
|
29
|
+
}
|
30
|
+
|
31
|
+
FINGERPRINT_LENS = Lens['metadata', 'annotations', 'kustomizer.covalenthq.com/effective-fingerprint']
|
32
|
+
|
33
|
+
def rewrite(rc)
|
34
|
+
rc_kind = rc['kind']
|
35
|
+
return rc unless APPLICABLE_KINDS.member?(rc_kind)
|
36
|
+
|
37
|
+
FINGERPRINT_LENS.update_in(rc) do |orig_value|
|
38
|
+
next(:keep) if orig_value
|
39
|
+
|
40
|
+
content_part = CONTENT_LENS_BY_KIND[rc_kind].get_in(rc)
|
41
|
+
content_ser = content_part.to_json
|
42
|
+
fingerprint = Digest::SHA256.base32digest(content_ser, :zbase32)[0, 6]
|
43
|
+
|
44
|
+
[:set, fingerprint]
|
45
|
+
end
|
46
|
+
|
47
|
+
base_name = NAME_LENS.get_in(rc)
|
48
|
+
fingerprint = FINGERPRINT_LENS.get_in(rc)
|
49
|
+
|
50
|
+
NAME_LENS.update_in(rc) do |base_name|
|
51
|
+
suffixed_name = [base_name, fingerprint].join(SUFFIX_JOINER)
|
52
|
+
[:set, suffixed_name]
|
53
|
+
end
|
54
|
+
|
55
|
+
rc
|
56
|
+
end
|
57
|
+
end
|
@@ -27,7 +27,7 @@ class Kustomize::Transform::ImageTransform < Kustomize::Transform
|
|
27
27
|
"Deployment" => Lens["spec", "template", "spec", "containers", Access.all, "image"]
|
28
28
|
}
|
29
29
|
|
30
|
-
def
|
30
|
+
def rewrite(rc_doc)
|
31
31
|
lens = LENS_BY_KIND[rc_doc['kind']]
|
32
32
|
return rc_doc unless lens
|
33
33
|
|
@@ -44,7 +44,7 @@ class Kustomize::Transform::Json6902PatchTransform < Kustomize::Transform
|
|
44
44
|
attr_reader :target
|
45
45
|
attr_reader :patches
|
46
46
|
|
47
|
-
def
|
47
|
+
def rewrite(resource_doc)
|
48
48
|
if @target.match?(resource_doc)
|
49
49
|
@patches.inject(resource_doc){ |doc, patch| patch.apply(doc) }
|
50
50
|
else
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
require 'accessory'
|
4
|
+
|
5
|
+
require 'kustomize/transform'
|
6
|
+
|
7
|
+
class Kustomize::Transform::PurgeInternalAnnotationsTransform < Kustomize::Transform
|
8
|
+
include Accessory
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
ANNOTS_LENS = Lens['metadata', 'annotations']
|
12
|
+
|
13
|
+
INTERNAL_ANNOT_PATTERN = /^kustomizer\.covalenthq\.com\//
|
14
|
+
|
15
|
+
def rewrite(rc)
|
16
|
+
ANNOTS_LENS.update_in(rc) do |orig_annots|
|
17
|
+
next(:keep) unless orig_annots and orig_annots.length.nonzero?
|
18
|
+
|
19
|
+
new_annots =
|
20
|
+
orig_annots.reject{ |k, v| INTERNAL_ANNOT_PATTERN.match?(k) }
|
21
|
+
|
22
|
+
if new_annots.length == orig_annots.length
|
23
|
+
:keep
|
24
|
+
elsif new_annots.empty?
|
25
|
+
:pop
|
26
|
+
else
|
27
|
+
[:set, new_annots]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
require 'accessory'
|
4
|
+
|
5
|
+
require 'kustomize/transform'
|
6
|
+
|
7
|
+
class Kustomize::Transform::RefFixupTransform < Kustomize::Transform
|
8
|
+
include Accessory
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
SUFFIX_JOINER = "-"
|
12
|
+
|
13
|
+
NAME_LENS = Lens["metadata", "name"]
|
14
|
+
|
15
|
+
FINGERPRINT_LENS = Lens['metadata', 'annotations', 'kustomizer.covalenthq.com/effective-fingerprint']
|
16
|
+
|
17
|
+
KEY_REF_LENSES_BY_KIND = {
|
18
|
+
"Deployment" => [
|
19
|
+
Lens["spec", "template", "spec", "containers", Access.all, "envFrom", Access.all, "configMapRef", "name"],
|
20
|
+
Lens["spec", "template", "spec", "containers", Access.all, "env", Access.all, "valueFrom", "configMapKeyRef", "name"],
|
21
|
+
Lens["spec", "template", "spec", "volumes", Access.all, "configMap", "name"],
|
22
|
+
|
23
|
+
Lens["spec", "template", "spec", "containers", Access.all, "env", Access.all, "valueFrom", "secretKeyRef", "name"],
|
24
|
+
Lens["spec", "template", "spec", "volumes", Access.all, "secret", "name"],
|
25
|
+
Lens["spec", "template", "spec", "volumes", Access.all, "secret", "secretName"]
|
26
|
+
]
|
27
|
+
}
|
28
|
+
|
29
|
+
def rewrite_all(rcs)
|
30
|
+
ref_fixups =
|
31
|
+
rcs.flat_map do |rc|
|
32
|
+
fingerprint = FINGERPRINT_LENS.get_in(rc)
|
33
|
+
next([]) unless fingerprint
|
34
|
+
|
35
|
+
suffixed_name = NAME_LENS.get_in(rc)
|
36
|
+
base_name = suffixed_name.gsub(/-#{fingerprint}$/, '')
|
37
|
+
[[base_name, suffixed_name]]
|
38
|
+
end.to_h
|
39
|
+
|
40
|
+
rcs.map do |rc|
|
41
|
+
key_ref_lenses = KEY_REF_LENSES_BY_KIND[rc['kind']]
|
42
|
+
next(rc) unless key_ref_lenses
|
43
|
+
|
44
|
+
key_ref_lenses.inject(rc) do |doc, lens|
|
45
|
+
lens.update_in(doc) do |base_name|
|
46
|
+
if suffixed_name = ref_fixups[base_name]
|
47
|
+
[:set, suffixed_name]
|
48
|
+
else
|
49
|
+
:keep
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'kustomize/transform'
|
2
|
+
|
3
|
+
class Kustomize::Transform::TransformerPluginsTransform < Kustomize::Transform
|
4
|
+
def initialize(plugin_rc_emitters, session:)
|
5
|
+
@session = session
|
6
|
+
@plugin_rc_emitters = plugin_rc_emitters
|
7
|
+
end
|
8
|
+
|
9
|
+
def plugin_rcs
|
10
|
+
@plugin_rc_emitters.flat_map(&:emit)
|
11
|
+
end
|
12
|
+
|
13
|
+
def plugin_instances
|
14
|
+
return @plugin_instances if @plugin_instances
|
15
|
+
|
16
|
+
@plugin_instances =
|
17
|
+
self.plugin_rcs.map do |rc|
|
18
|
+
plugin_klass = @session.plugin_manager.get(api_version: rc['apiVersion'], kind: rc['kind'])
|
19
|
+
plugin_klass.create(rc, session: @session)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def rewrite_all(rcs)
|
24
|
+
self.plugin_instances.inject(rcs) do |docs, plugin_inst|
|
25
|
+
plugin_inst.rewrite_all(rcs)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'kustomize/plugin'
|
2
|
+
|
3
|
+
class Kustomize::TransformerPlugin < Kustomize::Plugin
|
4
|
+
def self.inherited(subklass)
|
5
|
+
reg = Kustomize::PluginRegistry.instance
|
6
|
+
reg.probe_queue.push(subklass)
|
7
|
+
end
|
8
|
+
|
9
|
+
def rewrite_all(rcs)
|
10
|
+
rcs.map{ |rc| rewrite(rc) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def rewrite(rc)
|
14
|
+
rc
|
15
|
+
end
|
16
|
+
end
|
data/lib/kustomize/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kustomizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Levi Aul
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: accessory
|
@@ -56,12 +56,15 @@ files:
|
|
56
56
|
- bin/setup
|
57
57
|
- kustomizer.gemspec
|
58
58
|
- lib/kustomize.rb
|
59
|
+
- lib/kustomize/builtin_plugins/kustomizer.covalenthq.com/v1/test_generator.rb
|
60
|
+
- lib/kustomize/builtin_plugins/kustomizer.covalenthq.com/v1/test_transformer.rb
|
59
61
|
- lib/kustomize/emitter.rb
|
60
62
|
- lib/kustomize/emitter/directory_emitter.rb
|
61
63
|
- lib/kustomize/emitter/document_emitter.rb
|
62
64
|
- lib/kustomize/emitter/document_emitter/kustomization_document_emitter.rb
|
63
65
|
- lib/kustomize/emitter/file_emitter.rb
|
64
|
-
- lib/kustomize/emitter/
|
66
|
+
- lib/kustomize/emitter/generator_plugins_emitter.rb
|
67
|
+
- lib/kustomize/generator_plugin.rb
|
65
68
|
- lib/kustomize/json_6902_patch.rb
|
66
69
|
- lib/kustomize/json_6902_patch/add_op.rb
|
67
70
|
- lib/kustomize/json_6902_patch/gsub_op.rb
|
@@ -70,13 +73,18 @@ files:
|
|
70
73
|
- lib/kustomize/pathname_refinements.rb
|
71
74
|
- lib/kustomize/plugin.rb
|
72
75
|
- lib/kustomize/plugin_manager.rb
|
76
|
+
- lib/kustomize/plugin_registry.rb
|
73
77
|
- lib/kustomize/session.rb
|
74
78
|
- lib/kustomize/target_spec.rb
|
75
79
|
- lib/kustomize/transform.rb
|
80
|
+
- lib/kustomize/transform/fingerprint_suffix_transform.rb
|
76
81
|
- lib/kustomize/transform/image_transform.rb
|
77
82
|
- lib/kustomize/transform/json_6902_patch_transform.rb
|
78
|
-
- lib/kustomize/transform/name_digest_autosuffix_transform.rb
|
79
83
|
- lib/kustomize/transform/namespace_transform.rb
|
84
|
+
- lib/kustomize/transform/purge_internal_annotations_transform.rb
|
85
|
+
- lib/kustomize/transform/ref_fixup_transform.rb
|
86
|
+
- lib/kustomize/transform/transformer_plugins_transform.rb
|
87
|
+
- lib/kustomize/transformer_plugin.rb
|
80
88
|
- lib/kustomize/version.rb
|
81
89
|
homepage: https://github.com/tsutsu/kustomize
|
82
90
|
licenses:
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'kustomize/emitter'
|
2
|
-
|
3
|
-
class Kustomize::Emitter::PluginEmitter < Kustomize::Emitter
|
4
|
-
def initialize(input_emitter, session:)
|
5
|
-
@session = session
|
6
|
-
@input_emitter = input_emitter
|
7
|
-
end
|
8
|
-
|
9
|
-
def source_directory
|
10
|
-
@source_path.parent
|
11
|
-
end
|
12
|
-
|
13
|
-
def input_emitters
|
14
|
-
[@input_emitter]
|
15
|
-
end
|
16
|
-
|
17
|
-
def plugin_instances
|
18
|
-
return @plugin_instances if @plugin_instances
|
19
|
-
|
20
|
-
@plugin_instances =
|
21
|
-
self.input_resources.map do |rc|
|
22
|
-
plugin_klass = @session.plugin_manager.get(rc['apiVersion'], rc['kind'])
|
23
|
-
plugin_klass.new(rc)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def emit
|
28
|
-
self.plugin_instances.flat_map(&:emit)
|
29
|
-
end
|
30
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'digest'
|
3
|
-
require 'set'
|
4
|
-
|
5
|
-
require 'accessory'
|
6
|
-
require 'digest/base32'
|
7
|
-
|
8
|
-
require 'kustomize/transform'
|
9
|
-
require 'kustomize/emitter/document_emitter/kustomization_document_emitter'
|
10
|
-
|
11
|
-
class Kustomize::Transform::NameDigestAutosuffixTransform < Kustomize::Transform
|
12
|
-
include Accessory
|
13
|
-
|
14
|
-
SUFFIX_JOINER = "-"
|
15
|
-
|
16
|
-
def self.create(kustomize_doc)
|
17
|
-
raise ArgumentError unless kustomize_doc.kind_of?(Kustomize::Emitter::DocumentEmitter::KustomizationDocumentEmitter)
|
18
|
-
self.new(kustomize_doc)
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(kustomize_doc)
|
22
|
-
@kustomize_doc = kustomize_doc
|
23
|
-
end
|
24
|
-
|
25
|
-
SECRET_KINDS = Set[
|
26
|
-
'Secret',
|
27
|
-
'SealedSecret'
|
28
|
-
]
|
29
|
-
|
30
|
-
def suffixes
|
31
|
-
return @suffixes if @suffixes
|
32
|
-
|
33
|
-
secret_docs =
|
34
|
-
@kustomize_doc.input_resources
|
35
|
-
.filter{ |rc| SECRET_KINDS.member?(rc['kind']) }
|
36
|
-
|
37
|
-
@suffixes =
|
38
|
-
secret_docs.map do |rc|
|
39
|
-
rc_kind = rc['kind']
|
40
|
-
|
41
|
-
secret_name = NAME_LENSES_BY_KIND[rc_kind].first.get_in(rc)
|
42
|
-
secret_content = CONTENT_LENSES_BY_KIND[rc_kind].get_in(rc)
|
43
|
-
content_hash_suffix = Digest::SHA256.base32digest(secret_content.to_json, :zbase32)[0, 8]
|
44
|
-
|
45
|
-
[secret_name, content_hash_suffix]
|
46
|
-
end.to_h
|
47
|
-
end
|
48
|
-
|
49
|
-
CONTENT_LENSES_BY_KIND = {
|
50
|
-
"Secret" => Lens["data"],
|
51
|
-
"SealedSecret" => Lens["spec", "encryptedData"]
|
52
|
-
}
|
53
|
-
|
54
|
-
NAME_LENSES_BY_KIND = {
|
55
|
-
"Deployment" => [
|
56
|
-
Lens["spec", "template", "spec", "containers", Access.all, "env", Access.all, "valueFrom", "secretKeyRef", "name"]
|
57
|
-
],
|
58
|
-
|
59
|
-
"Secret" => [
|
60
|
-
Lens["metadata", "name"]
|
61
|
-
],
|
62
|
-
|
63
|
-
"SealedSecret" => [
|
64
|
-
Lens["spec", "template", "metadata", "name"]
|
65
|
-
]
|
66
|
-
}
|
67
|
-
|
68
|
-
def apply(rc_doc)
|
69
|
-
name_lenses = NAME_LENSES_BY_KIND[rc_doc['kind']]
|
70
|
-
return rc_doc unless name_lenses
|
71
|
-
|
72
|
-
name_lenses.inject(rc_doc) do |doc, lens|
|
73
|
-
lens.update_in(doc) do |orig_name|
|
74
|
-
if self.suffixes.has_key?(orig_name)
|
75
|
-
new_name = [orig_name, self.suffixes[orig_name]].join('-')
|
76
|
-
[:set, new_name]
|
77
|
-
else
|
78
|
-
:keep
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|